-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
return NaN in npy_ObjectMax() and npy_ObjectMin() if it's an argument #5041
Comments
@mamikony It would be best if you made a normal PR out of this. |
Yes please, though I think rather then do checks with floats, invert the logic (i.e. use <= instead of >, etc.), which should have the same effect. |
Wait, we already removed that old non-richcompare branch. Didn't that already fix this fully? |
This is a different issue. Previously, the result was dependent on the relative addresses in case of NaNs because of the builtin cmp() operator, i.e., code internal to the Python interpreter. Now, the result is always the second argument when either is NaN because of the logic of the functions in question.
|
As @charris pointed out in #4903, the current behavior is inconsistent with the Python builtins min()/max(), which will return the first argument, in this case. This is also inconsistent with NumPy documentation, which described what seems to me to be far more logical behavior: return the first NaN. |
Hmmmpf, I don't like this. I admit since people should implement Anyway, I don't know what the right solution is. There are similar issues like this all over, maybe we should do this, because it is the best we have, or maybe we should do a second comparison to find NaNs weirdness. Or maybe it is all slow/useless and the user needs to be careful. |
@seberg You make a couple of points to consider. First, what error checking do you have in mind? Second, complex numbers numbers aren't ordered like the reals, so both, Python and NumPy, correctly issue the exception |
OK, so complex may not b e a problem here. What I meant with error checking is, that checking for a python float or subtype will not find for example np.float32, so you probably really would have to try to get the float value and that might fail. |
I understand, but I don't think we can do better than Python here because we ultimately dispatch to it. In the case of Decimal, apparently it doesn't like NaNs at all: |
This is a patch I posted to #4903, but it must have fallen through the cracks. It brings the code inline with the documentation in that it always returns the NaN argument (first, if both).
The text was updated successfully, but these errors were encountered: