uhoh
uhoh

Reputation: 3745

Why did Python give me this strange Visible Deprecation Warning? Something to learn here?

I couldn't remember if np.zeros(x) will automatically covert a float x to int or not, so I tried it in IDLE. What I got the first time was a Warning message that refers to the script I had run earlier in the same session, and then warns me "using a non-integer number instead of an integer will result in an error in the future".

I tried it again, and the warning did not repeat, and the array was instantiated as expected with dtype=float.

Why does the warning say there will be an error (as opposed to could be), and what will it be? And why did it refer to the first non-blank line in the script I'd run much earlier today get embedded into the warning?

This may be a window into how IDLE is working - so I'm hoping to learn something from this. I've read here that I can suppress the warning, but I would like to understand it's behavior first.

>>> 
>>> equator = np.zeros(3.14)

Warning (from warnings module):
  File "/Users/xxxxxx/Documents/xxxxxx/CYGNSS/CYGNSS TLE interpolator v00.py", line 2
    CYGNSS_BLOB = """1 41884U 16078A   16350.61686218 -.00000033  00000-0  00000+0 0  9996
VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
>>> 
>>> equator = np.zeros(3.14)
>>> equator
array([ 0.,  0.,  0.])
>>> 

Upvotes: 0

Views: 778

Answers (1)

user6655984
user6655984

Reputation:

"In the future" means "in a future version of NumPy". So far you get a warning, not an error. The assignment was made (you didn't need to run the command the second time, equator was already assigned as you wanted) and execution proceeded normally.

But some future version of NumPy will throw an error, halting the execution.

The warning is not repeated again within the same session; there's some logic there intended to avoid nagging the user too much.

I can't explain the line reference; for me it refers to __main__:1:.

Upvotes: 2

Related Questions