-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: Error when using nanmax()
and nanmin()
on an object array with an axis specified.
#9008
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
There is an answer with three downvotes that explains why this is not a bug. Happy realisation :) Nansum and Nanmax are not coded in the same fashion , a detailed explanation is available on the post. It's not an axis issue to begin with... |
So, ideally this breaks down into:
As a quick workaround, we should just not allow object arrays to take that special case branch |
Yes, explicity type cast to float. The np.isnan() fails on object type columns. |
@Satyadev592: Not the right fix. This is essentially a different manifestation of the problem at #8974, and the quick fix to numpy would be as described there. This is absolutely a bug in numpy. |
The code example at the top of this page directly contradicts that claim, does it not? The problem manifests itself only when all of the following are true: axis is specified, dtype is object, and input is 2d or higher |
Take a numpy array with only string values and try the nanmax on either axis. It still pops an error. The error this time is something to do with the fmax, dig a bit deeper , it's got something to do with numpy not having good support for the object datatype. If this is a bug , then a bug for each numpy function should be created for lack of support for object datatypes. This particular problem makes you think axis is a reason while it has nothing to do with the problem. Also shifting an explicit casting to float inside source code is probably not a good idea. Numpy does not seem to be designed for object types [Well established i think] Also , the documentation for |
Strings are an entirely different beast, and have little to do with the
Absolutely. If you can find numpy functions that fail with object arrays, where it would make sense for them not to, then either:
|
This issue would be fixed by #6320 (I just tested the example). [1]: a = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=object)
[2]: np.nanmax(a, axis=0)
array([3.0, 4.0], dtype=object)
[3]: x = np.array([1, np.nan])
[4]: np.fmin.reduce(x)
1.0
[5]: np.fmin.reduce(x.astype(object))
1.0 |
Closing, all the examples work correctly (including the last one |
The bug here is that the case you mention should not return nan |
However that's covered in gh-8975, so fine to close this |
Closed by gh-9013 |
This was the underlying cause of a problem reported on stackoverflow: http://stackoverflow.com/questions/43659827/numpy-error-when-specifying-axis-in-nanmax-while-nansum-works-an-the-same-case
The error is raised when applying
nanmax()
ornanmin()
to an array with object data type and specifying an axis.Here's the example from my answer:
There is no error when the axis is not given:
nansum()
handles the axis without an error:There are several other issues involving the nan-functions and object arrays, but I couldn't tell if this issue is a duplicate. Sorry for the noise if it is.
The text was updated successfully, but these errors were encountered: