为什么我没有看到Numpy的DeprecationWarning?

And*_*rew 5 python warnings numpy deprecated deprecation-warning

我最近在我的一台机器上更新了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''
Run Code Online (Sandbox Code Playgroud)

上述链接中的一位评论者指出:

可能意味着你永远不会看到弃用警告;)

......这是正确的,我没有.

为什么呢?我是如何设法错过弃用警告的?

文档一致,这个相同的代码在我以前的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)
Run Code Online (Sandbox Code Playgroud)

......但是这不应该引发警告吗?我是否误解了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
Run Code Online (Sandbox Code Playgroud)

use*_*ica 6

默认情况下忽略 DeprecationWarnings .您需要通过运行带有-Wd标志的 Python来启用它们:

python -Wd my_source_file.py
Run Code Online (Sandbox Code Playgroud)

或者通过安装新的警告过滤器规范来覆盖忽略DeprecationWarning的规范:

import warnings

# Print any warning the first time a given source line issues them,
# overriding built-in filters that ignore some warning types.
warnings.filterwarnings("default")
Run Code Online (Sandbox Code Playgroud)