-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: mixed object arrays and nan functions #8974
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
Comments
On python 3, I get Python 2 lets you compare anything to anything else, and get a totally random result, which is why you don't get an error |
Apologies, I forgot the slicing. I can replicate this behaviour on 3.5 |
>>> arr = np.array([np.nan, 1], dtype=np.float64)
>>> np.nanmin(arr)
nan
Edit: not on master |
For the record, here is a somewhat hacky fix that is obviously unsavory for several reasons (fairly arbitrary cast, introduction of def safe_nanfunc(data, nanfunc):
if data.dtype == 'object':
# cast to float
data = np.ndarray.astype(data, dtype='f')
return nanfunc(data)
|
In [1]: import numpy as np
In [2]: np.array([np.nan, 1], dtype=np.float64)
Out[2]: array([ nan, 1.])
In [3]: np.nanmin(np.array([np.nan, 1], dtype=np.float64))
Out[3]: 1.0
In [4]: np.nanmax(np.array([np.nan, 1], dtype=np.float64))
Out[4]: 1.0 wasn't a problem for me. I'm on
|
It seems like unit tests should have caught this error, but regardless we have one above now! @eric-wieser if you agree this is a bug how long would it take to get this pushed into a minor version number if a fix can be found quickly? |
I've filed a more specific issue at #8975 I doubt that there'll be a new release of |
@eric-wieser, I should note the speed to fix isn't a real problem but more of a curiosity for me. This is the type of thing I could likely fix but the unfortunate things is I'm under some severe time pressure right now and have a work around via |
Thanks @eric-wieser for the hints on how to fix the issue. It sounds like this might be fast to fix but my numpy dev environment is quite stale now. What is typically the timeline here, e.g., the process to typically get this type of thing fixed? I can't work on this now but may be able to make some time over the next 60 days or so. |
I've split off the There's a quick fix to the nanfunctions which would be to change |
A related bug: #6209 |
The following code produces non-intuitive behavior that I believe may be a bug:
I would expected output from
[4]
and[5]
to be364.0
, notnan
. Other nan functions, e.g.,nanmean
also appear to be corrupted. Furthermore, theRuntimeWarning
is fairly cryptic and doesn't appear to be correct.Is there something I'm missing here? This is not at all what I would expect based on what boils down to a reducing function to a dimension that is effectively a numpy array that is not all
nan
s as apparently interpreted by theRuntimeWarning
.The text was updated successfully, but these errors were encountered: