我最近在我的一台机器上更新了 Python 的 Numpy 包,显然我已经依赖 numpy 的已弃用功能有一段时间了:
>>> np.__version__
'1.10.4'
>>> a = np.ones(10, dtype=np.uint16)
>>> a /= 0.5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ufunc 'true_divide' output (typecode 'd') could not be coerced to provided output parameter (typecode 'H') according to the casting rule ''same_kind''
上述链接中的一位评论者指出:
可能意味着您永远没有看到弃用警告 ;)
...这是正确的,我没有。
但是为什么?我怎么错过了弃用警告?
与文档一致,相同的代码在我之前的numpy版本中的工作方式有所不同:
>>> np.__version__
'1.9.2'
>>> a = np.ones(10, dtype=np.uint16)
>>> a /= 0.5
>>> a
array([2, 2, 2, 2, 2, 2, 2, 2, 2, 2], dtype=uint16)
...但是这不应该触发警告吗?我是否误解了 numpy 如何处理弃用警告? 我如何确定我没有错过其他弃用警告?
我的python环境:
Python 3.5.1 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit (AMD64)] on win32
我正在运行 python3 --version
Python 3.8.16
Ansible --版本
ansible [核心 2.13.13]
我无法在屏幕上显示弃用警告。我有
deprecation_warnings=True 。这不会生效 true/false