-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
The new range handling method will raise ValueError for arrays including NaN #7503
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
To note for everyone, this is np.histogram. @hopehhchen can you explain what you expect? It seems to me that the old behaviour returned useless results, so I am not sure I wouldn't consider the error an improvement? EDIT: Of course there may always be a case for roll back + deprecation if it is annoying. |
For anyone else who might look at this, this seems to be the old behaviour (in 1.8.2):
which seems nonsense, the numbers don't even add up. |
@seberg Thanks for the looking at this as well. Sorry I wasn't being super clear. I'm not suggesting going back to roll back, but just thinking if, instead, using np.nanmin(a) and np.nanmax(a) in the new code would make more sense. Doing this would save the users extra troubles to remove the NaNs or to manually set |
I like @hopehhchen's suggestion of using the However, this issue breaks cases when That is, these two calls should be equivalent:
|
Bug reported here: numpy/numpy#7503
I think if bins are used, range is probably not used in any case? Which seems like the right behaviour to me. |
Ah, sorry, missed that. So I guess right now range actually does matter and will filter NaNs (and probably Infs, etc.)? Seems not to matter in older versions. It might be good to double check how this behaviour has changed over the last few versions. |
I am just seconding the issue @hopehhchen raised. I am using version 1.11.0 bins = np.asarray([0,2,4,6,8,10])
values = np.asarray([1,2,4,6,4,6,7,8,5,2,2,4,6,np.nan,7,5,4,22,3,57,8,9,6,4,3,2,1,46,8,9])
# broken version. Worked in previous stable release in conda
h, bins = np.histogram(values, bins=bins)
# now this is required.
h, bins = np.histogram(values, bins=bins, range=(bins.min(),bins.max())) |
This error affects matplotlib |
I've a patch in the works for Numpy 1.15.0 that happens to fix this. Should have a PR to link to in a few weeks, once #10186 is dealt with |
Note that we could still consider using |
I just got this error even though there are no NaN values in my array:
I'm using Numpy version 1.14, matplotlib 2.0.2 |
Your backtrace doesn't match the code you're running:
vs
|
Oh yes, I added range argument after the fact, to see if it helps. Original error happened without range argument in plt.hist call. Let me edit the post. |
Did it help? It should have. |
Yes, it helped. This time there were nan values in the array, and I got the following warnings:
but the code execution continued after that. |
This issue appears after one of the latest changes to function_base.py (around Row 550 in 127eb9e on March 16, 2016). Resetting the range to array minimum and maximum by using a.min() and a.max() will raise ValueError: 'range parameter must be finite.' if the array includes NaN. Before the change, the codes assigned a pair of range parameters only when they were included in the input explicitly.
The text was updated successfully, but these errors were encountered: