The future warning happens when you do something like this:
>>> numpy.asarray([1,2,3,None]) == None
Which currently returns False
, but I understand will return an array containing [False,False,False,True]
in a future version of Numpy.
As discussed on the numpy discussion list the way around this is to testa is None
.
What confuses me is this behaviour of the in
keyword with a 1D array compared to a list:
>>> None in [1,2,3,None]
True
>>> None in numpy.asarray([1,2,3,None])
__main__:1: FutureWarning: comparison to 'None' will result in an elementwise
object comparison in the future
False
>>> 1 in numpy.asarray([1,2,3,None])
True
EDIT (see comments) - There are really two different questions:
- Why does this cause a
FutureWarning
- what will the future behaviour ofNone in numpy.asarray(...)
be compared to what it is now? - Why the difference in behaviour of
in
from alist
; can I test if my array containsNone
without converting it to a list or using afor
loop?
Numpy version is 1.9.1, Python 3.4.1