Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FutureWarnings with NumPy 1.9: "comparison to None will result in an elementwise comparison in the future" #251

Closed
mdickinson opened this issue Dec 18, 2014 · 1 comment

Comments

@mdickinson
Copy link
Member

When using NumPy >= 1.9, we're seeing a good number of FutureWarning messages arising from the test suite of a large-ish Chaco-using application.

The warnings appear to be mostly (perhaps entirely) caused by traits that accept either an array or None: assigning the array to such a trait that previously had the value None results in one of these warnings. For example:

Python 2.7.3 |Master 2.0.0.dev1463-a1bb912 (64-bit)| (default, Nov  8 2014, 06:08:11) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> from traits.api import *
>>> from chaco.base import ImageTrait
>>> class MyImagePlot(HasTraits):
...     image = ImageTrait
... 
>>> plot = MyImagePlot()
>>> plot.image = np.zeros((3, 5))
__main__:1: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.

The ImageTrait and related traits (PointTrait, CubeTrait, etc.) are one source of these warnings. Another source is use of Any traits where the trait might store either None or an array, for example in PlotAxis._tick_positions.

There's a new ArrayOrNone trait type in Traits master that might help with fixing this issue. (enthought/traits#219)

One fun aspect: trying to detect the warnings with e.g. python -Werror::FutureWarning -m unittest discover ... doesn't entirely work, because many of those warnings are coming from the ctraits comparison machinery, and that machinery swallows exceptions. On the other hand, because the comparison machinery swallows exceptions, these warnings are mostly harmless: in the future, a comparison with None will return a broadcast array result, then an attempt to interpret that array in a boolean context will raise a ValueError, which will be swallowed harmlessly by the machinery (and result in Traits always issuing related events).

@rkern
Copy link
Member

rkern commented Dec 18, 2017

Fixed by #350

@rkern rkern closed this as completed Dec 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants