Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I not seeing Numpy's DeprecationWarning?

I recently updated Python's Numpy package on one of my machines, and apparently I've been relying on a deprecated feature of numpy for a while now:

>>> 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''

One of the commenters in the above link pointed out:

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

...which is correct, I didn't.

But why? How did I manage to miss the deprecation warning?

Consistent with the documentation, this same code worked differently in my previous numpy version:

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

...but shouldn't this trigger a warning? Do I misunderstand how numpy handles deprecation warnings? How can I be sure I'm not missing other deprecation warnings?

My python environment:

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
like image 529
Andrew Avatar asked May 20 '16 22:05

Andrew


1 Answers

DeprecationWarnings are ignored by default. You need to enable them, either by running Python with the -Wd flag:

python -Wd my_source_file.py

or by installing a new warning filter specification that overrides the one for ignoring 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")
like image 99
user2357112 supports Monica Avatar answered Nov 07 '22 19:11

user2357112 supports Monica