PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 17, 2022

[FIXED] Why am I not seeing Numpy's DeprecationWarning?

 July 17, 2022     deprecated, deprecation-warning, numpy, python, warnings     No comments   

Issue

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

Solution

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


Answered By - user2357112
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing