fix: TProfile2D/3D weighted and counts() were broken for N-D profiles#1651
Open
henryiii wants to merge 2 commits into
Open
fix: TProfile2D/3D weighted and counts() were broken for N-D profiles#1651henryiii wants to merge 2 commits into
henryiii wants to merge 2 commits into
Conversation
- Fix `weighted` property in TProfile2D/3D: `fNcells` is an int so
`len(self.member("fNcells"))` raised TypeError; also the logic was
inverted vs the correct 1-D version in TProfile.py
- Fix `counts()` in TProfile2D/3D: flat `fBinEntries` was never reshaped
and transposed before slicing, causing IndexError on flow=False; now
matches the reshape+transpose pattern used by `values()`
- Change `TProfile.counts()` default from `flow=True` to `flow=False` to
match every other `counts()` in the codebase (behavior change)
- Remove Python-2-era `__ne__` methods from TH1 and TAxis (Python 3
auto-derives `__ne__` from `__eq__`)
Fixes #1646
Assisted-by: ClaudeCode:claude-sonnet-4-6
Add 16 tests covering: - weighted property not raising TypeError for TProfile2D and TProfile3D - counts(flow=True/False) shape matching values(flow=True/False) shape - counts() inner region consistent with counts(flow=True) slice Assisted-by: ClaudeCode:claude-sonnet-4-6
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
|
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 #1646
Summary
TProfile2D/3D
weightedproperty (TProfile2D.py:36-39,TProfile3D.py:40-43):fNcellsis anint, solen(self.member("fNcells"))raisedTypeErrorwheneverfBinSumw2existed. Additionally the logic was inverted relative to the correct 1-D version inTProfile.py:237-240. Both files now match the 1-D version:fBinSumw2 is not None and len(fBinSumw2) == self.member("fNcells").TProfile2D/3D
counts()shape (TProfile2D.py:41-52,TProfile3D.py:45-56):out.reshape(fBinEntries.shape)was a no-op becausefBinEntriesis stored flat (shape(fNcells,)). The subsequentout[1:-1, 1:-1]/out[1:-1, 1:-1, 1:-1]slices then raisedIndexError. The fix applies the samereshape+numpy.transposepattern already used byvalues()in both classes, ensuringcounts(flow=…).shape == values(flow=…).shape.TProfile.counts()defaultflow(TProfile.py:242): Changed default fromflow=Truetoflow=False. Every othercounts()in the codebase defaults toflow=False(the abstractProfile.countsatTProfile.py:142,TProfile2D.counts,TProfile3D.counts,TH1.Histogram.counts). Theflow=Truedefault was an inconsistency. Maintainer: please confirm this behavior change is acceptable — any downstream code callingh.counts()on a 1-DTProfilewithout an explicitflow=argument will now receive the no-flow array (lengthfNbins) instead of the with-flow array (lengthfNbins + 2).Python-2
__ne__cleanup (TH1.py:85-89,TAxis.py:122-126): Removed explicit__ne__methods with the comment "Some versions of Python don't automatically negate__eq__". Python 3 auto-derives__ne__from__eq__, so these are dead code.Test plan
weightedproperty no longer raisesTypeErroronuproot-issue-227a.root(TProfile2D) anduproot-issue-227b.root(TProfile3D)counts(flow=True).shape == values(flow=True).shapefor both TProfile2D and TProfile3Dcounts(flow=False).shape == values(flow=False).shapefor both TProfile2D and TProfile3Dtests/test_0228_read_TProfiles.py,tests/test_1609_tprofiles.py)🤖 Generated with Claude Code