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

吃可爱长大的小学妹 提交于 2019-12-25 07:42:37

问题


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.])
>>> 

回答1:


"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:.



来源:https://stackoverflow.com/questions/41310108/why-did-python-give-me-this-strange-visible-deprecation-warning-something-to-le

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!