fix: Ensure floating-point accuracy in hist#22245
Merged
ritchie46 merged 1 commit intopola-rs:mainfrom Apr 14, 2025
Merged
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #22245 +/- ##
==========================================
- Coverage 80.78% 80.77% -0.01%
==========================================
Files 1639 1639
Lines 235548 235538 -10
Branches 2714 2714
==========================================
- Hits 190278 190261 -17
- Misses 44630 44637 +7
Partials 640 640 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
hist accuracy in the face of floating-point imprecisionhist
dongchao-1
pushed a commit
to dongchao-1/polars
that referenced
this pull request
Apr 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #22234
Two minor adjustments:
When user-supplied bins are provided, the slow path is always taken. This guarantees that the user's bins are always respected. The prior implementation attempted to detect if the bins were uniformly distributed using a heuristic, but that heuristic can be foiled, and we were bound to encounter an issue on this sometime in the future.
In the fast path (now only when
bin_countis supplied), the index calculation might generate results > 1 ULP of the bin edges in some cases, resulting in an invalid index, as see in the linked issue. There, we have1.0 - 1e-17 == 1.0:There is now a check to see whether the value should be moved to an adjacent bucket. This check encompasses a prior check, so performance should not be affected.