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

标签 python numpy warnings deprecated deprecation-warning

我最近在我的一台机器上更新了 Python 的 Numpy 包,显然我一直依赖 a deprecated feature of 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''

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

Probably means you didn't see the deprecation warnings since forever ;)

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

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

the documentation一致,同样的代码在我以前的 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

最佳答案

弃用警告是 ignored by default .您需要通过使用 -Wd flag 运行 Python 来启用它们:

python -Wd my_source_file.py

或者通过安装一个新的警告过滤器规范来覆盖忽略 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")

关于python - 为什么我没有看到 Numpy 的 DeprecationWarning?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37356814/

相关文章:

Python:os.isfile() 和 os.listdir() 之间的分歧

arrays - for 循环的简洁数学符号

c++ - 如何将 "warnings as error"规则添加到 Qt .pro 文件?

android - XML 中的“图像上缺少 contentDescription 属性”

android - android 4.0下的奇怪异常与eclipse

python - 如何测试 Python http.server.HTTPServer 是否永远服务?

python - 验证证书的指纹

python - 从较大的 JSON 子集在 Python 中创建新的 JSON

numpy - 我可以避免使用 numpy 进行动态编程时的 Python 循环开销吗?

python - Opencv:错误:(-210)在函数阈值中