Repository navigation
fix: give unweighted histogram bins of negative content a variance - #1826
Merged
Merged
Conversation
This was referenced Nov 6, 2026
ariostas
marked this pull request as ready for review
November 6, 2026 14:47
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
|
Like ROOT's TH1::GetBinError, the variance of a bin without fSumw2 is the absolute value of its content, rather than 0 when the content is negative. TProfile gets _values_variances, which the histogram conversions use. Found by the tests of scikit-hep#1814. Assisted-by: Claude Code:claude-opus-5-5
ariostas
force-pushed
the
fix/histograms
branch
from
November 6, 2026 15:09
c44abf1 to
eb62798
Compare
numpy.abs keeps the dtype, and the absolute value of the lowest integer of a dtype doesn't fit in it, so a TH1C bin of -128 had a variance of -128 (and TH1S, TH1I, TH2 and TH3 likewise). Assisted-by: Claude Code:claude-opus-5-5
ianna
approved these changes
Nov 10, 2026
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.
🤖 AI text below 🤖
Part of the split of #1814 (the list is in #1834).
fSumw2, the variance of a TH1/TH2/TH3 bin is now the absolute value of its content, like ROOT'sTH1::GetBinError(sqrt(|content|)). Before, it was 0 for bins of negative content. Integer contents are converted to floats first, so the lowest integer of a TH1C/S/I doesn't overflow.==on two TProfiles raisedAttributeError, becauseHistogram.__eq__calls_values_variances, which profiles didn't have. Profiles now have it.tests/test_1826_fix_histograms.pyholds the regression tests: every test in it fails on main (for parametrized tests, at least one of their cases).This changes what
variances()anderrors()return for unweighted histograms with negative bins, and what==compares, which is why it's a separate PR.to_boost()andto_hist()are unaffected, since they only take variances from weighted histograms.