-
-
Notifications
You must be signed in to change notification settings - Fork 11k
numpy.maximum since 1.15 raises RuntimeWarning when encountering a NaN even though the docs say it should propagate NaNs #12038
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
Note that we may still want to raise a warning. |
Might open for discussion on the mailing list. |
If we do decide the raising a warning is the right thing, we should document that. I'm tending in that direction as the appearance of NaNs could indicate an error or that nanmax should be used. |
I added a "thumbs up" emoji to the bug report, but it occurs to me that the meaning of doing that is a bit vague, so here's the explicit comment: I agree that
I don't think there is |
Raising a warning is also inconsistent. Functions such as
|
nanmax does something different, it ignores nans, whereas maximum propagates nans. In [1]: import numpy as np
In [2]: x = np.arange(3, dtype=float)
In [3]: x[2] = np.nan
In [4]: x
Out[4]: array([ 0., 1., nan])
In [5]: np.nanmax(np.vstack([x, x[::-1]]), axis=0)
Out[5]: array([0., 1., 0.])
In [6]: np.maximum(x, x[::-1])
/home/tudor/anaconda3/bin/ipython:1: RuntimeWarning: invalid value encountered in maximum
#!/home/tudor/anaconda3/bin/python
Out[6]: array([nan, 1., nan]) |
|
Some discussion about whether |
In that discussion, @juliantaylor said
The |
What needs to happen for this to be classified as either a) feature that works as expected or b) regression? What's the process? I'm asking because I am using code that's throwing a lot of warnings because of this behaviour change. If it's a feature, than I need to work around it, if it's a regression then I just need to temporarily silence that one warning. |
My own feeling on this as that we should do what is most useful to the users, but I don't know what that is :) I find the arguments for not warning a bit stronger than those in favor, although I'd like to know more about the use case in which the warning is a problem. It would be good to have more opinions, maybe a posting on the mailing list would help. Also @pv, @rgommers Thoughts? |
The warning is a problem for me because I try to keep my stuff tidy with no warnings. The function has NaN handling very well documented: it explicitly says what happens when NaNs are found and the behaviour is well defined: NaNs are propagated using a well defined rule. But I'm not sure at what point and who decides on that. |
Is anyone currently arguing for keeping the warnings? |
NumPy 1.15.3 is coming up, it would be good to settle this... |
Also maybe related to #8945 where warnings are possibly emitted when comparing (sign, abs, gt, lt ...) |
I will chime in as a strong proponent of not emitting these warnings. The reasoning is carefully explained by @WarrenWeckesser and @tudorprodan. I arrived here because the pvlib python library uses |
I think this is trending strongly in the direction of no warnings. |
Taking a step back here - as far as I'm aware all of the floating point ufuncs have well-defined behavior on nans, as specified by ieee754. So should we just change the default to ignore this class of fperr, rather than choosing not to emit it? Edit: nevermind, I wasn't aware we raised this explicitly |
numpy.maximum
now raises a RuntimeWarning when encountering a NaN, but the documentation says it propagates NaNs and even goes to the trouble of saying exactly how they are propagated, which makes it seem like it shouldn't give a warning.Reproducing code example:
Numpy/Python version information:
The text was updated successfully, but these errors were encountered: