You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The scenario I'm dealing with is an array of dtype object where this array has some np.nan entries (where original data were missing) and strings where data are valid. I got stuck when trying to get a mask from such array.
Consider the example:
>>> a = np.array([np.nan,'ok'],dtype=np.object)
>>> a
array([nan, 'ok'], dtype=object)
Using np.isnan doesn't work because:
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
Then I went to basic (IEEE754) rules and compared a with itself (element-wise) expecting I would get False for the "NaN" entry and True for the other one... but nop:
When I run your example with NumPy 1.11.1 I see:
FutureWarning: numpy equal will not check object identity in the future. The comparison did not return the same result as suggested by the identity (is)) and will change.
I'm not entirely sure when "the future" is, because I couldn't find the relevant issue on GitHub with a quick search. But we do definitely indeed want to fix this, because it's broken :).
Don't remember, I may have fixed this without any explicit issue open, might need to check the pull requests or just the code for when it was introduced.
The test np.equal(a,a) now returns array([False, True], dtype=bool), so I guess the future has arrived. Closing, please reopen if I am mistaken (not about the future, but about the issue at hand).
The scenario I'm dealing with is an array of dtype
object
where this array has somenp.nan
entries (where original data were missing) andstrings
where data are valid. I got stuck when trying to get a mask from such array.Consider the example:
Using
np.isnan
doesn't work because:Then I went to basic (IEEE754) rules and compared
a
with itself (element-wise) expecting I would getFalse
for the "NaN" entry andTrue
for the other one... but nop:And that is my issue; this behaviour is completely unexpected to me.
If I do the elements comparison by my self, it works:
The behaviour I was expecting does happen when one has a
float
array -- which is not my case, but I tried to test things:For the time being, my solution is:
Thanks.
The text was updated successfully, but these errors were encountered: