-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: zero-width histogram bins if the data values are in a small range close to numeric precision #27142
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
Labels
Comments
I saw there is already a check for monotony: numpy/numpy/lib/_histograms_impl.py Line 434 in 69e2845
Is there a reason = is accepted or could this check be changed to |
A PR with a test for this edge case might expose where other tests could fail. |
timhoffm
added a commit
to timhoffm/numpy
that referenced
this issue
Aug 8, 2024
When many bins are requested in a small value region, it may not be possible to create enough distinct bin edges due to limited numeric precision. Up to now, `histogram` then returned identical subsequent bin edges, which would mean a bin width of 0. These bins could also have counts associated with them. Instead of returning such unlogical bin distributions, this PR raises a value error if the calculated bins do not all have a finite size. Closes numpy#27142.
timhoffm
added a commit
to timhoffm/numpy
that referenced
this issue
Aug 8, 2024
When many bins are requested in a small value region, it may not be possible to create enough distinct bin edges due to limited numeric precision. Up to now, `histogram` then returned identical subsequent bin edges, which would mean a bin width of 0. These bins could also have counts associated with them. Instead of returning such unlogical bin distributions, this PR raises a value error if the calculated bins do not all have a finite size. Closes numpy#27142.
ArvidJB
pushed a commit
to ArvidJB/numpy
that referenced
this issue
Nov 1, 2024
When many bins are requested in a small value region, it may not be possible to create enough distinct bin edges due to limited numeric precision. Up to now, `histogram` then returned identical subsequent bin edges, which would mean a bin width of 0. These bins could also have counts associated with them. Instead of returning such unlogical bin distributions, this PR raises a value error if the calculated bins do not all have a finite size. Closes numpy#27142.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Describe the issue:
np.histogram
can produce zero-width bins if the data values are in a small range close to numeric precision. Noted in matplotlib/matplotlib#28685I'm aware that there is no reasonable representation / that calculating a reasonable representation close to the numeric precision is not possible. But would it be an option to check the bin-width and error out instead of returning nonsense histogram binning?
Reproduce the code example:
Error message:
No response
Python and NumPy Versions:
numpy 1.26.4
python 3.12.2
Runtime Environment:
No response
Context for the issue:
No response
The text was updated successfully, but these errors were encountered: