BUG: histogram small range robust #24161
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes BUG: IndexError when using np.histogram with small values #23110
the histogram
norm
variable is used to determine the bin index of input values, andnorm
is calculated in some cases by dividingn_equal_bins
by the range of the data; when the range of the data is extraordinarily small, thenorm
can become floating point infinityin this patch, we delay calculating
norm
to increase resistance to the generation of infinite values--for example, a really small input value divided by a really small range is more resistant to generating infinity, so we effectively just change the order of operations a bithowever, I haven't considered whether this is broadly superior for resisting floating point non-finite values for other
histogram
input/extreme value permutations--one might speculate that this is just patching one extreme case that happened to show up in the wild, but may increase likelihood of some other extreme case that isn't in our testsuite yetthe main logic for this patch is that it fixes an issue that occurred in the wild and adds a test for
it--if another extreme value case eventually pops up, at least this case will have a regression guard to keep guiding us in the right direction