-
Notifications
You must be signed in to change notification settings - Fork 28
feat: axis sort #243
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
feat: axis sort #243
Conversation
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 1.10%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
|
||
data = (data_dict[i] for i in range(len(args), self.ndim)) | ||
|
||
total_data = tuple(args) + tuple(data) # Python 2 can't unpack twice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally unrelated, but we should unpack twice, hist has never supported Python 2... :)
Would scikit-hep/boost-histogram#577 make this easier? |
I think, post refactor (bh 0.13 or so?), this is now just copying the >>> h = Hist.new.Reg(10, 0, 1, name="hi", label="ho").Double()
>>> h.axes[0].this = "that"
>>> h.axes[0].__dict__
{'name': 'hi', 'label': 'ho', 'this': 'that'} |
Ok yeah, arguably scikit-hep/boost-histogram#577 could make this entire API redundant, though it might still be worth having as a shorthand for the 2 most obvious use cases I see - sort by label, sort by integral. Btw the bh draft doesn't work for StrCat, I guess you are aware with the Any ETA on that draft? This sorting histograms question comes up quite often for me and it's fairly experience breaking to reply with "export to 1Ds and pass as a list to mplhep". |
Before PyHEP; but hopefully this week. Probably will be right after the PR above it (scaling). |
This is going in as an "experimental" feature in boost-histogram 1.1 - scikit-hep/boost-histogram#577 . It does not add removed bins to the flow bin when a selection is not complete, but that should not matter for this PR, so the warning could be silenced. |
Only have a sort by label currently, but I think this is good enough for a first pass? |
Great, thanks a lot! It's amazing how much easier this is with the axis picking implemented. |
@henryiii FYI, do you mean from hist import Hist
h = Hist.new.StrCat(["AB", "BCC", "BC"], name="Y", label="Y-axis").IntCat([1, 4, 2], name="X", label="X-axis").Double()
# sort StrCat
h.sort(0, reverse=True).axes[0]
# sort axes by name
h.project(*[i[0] for i in sorted(enumerate(h.axes.name), key=lambda x:x[1])]) # we may want h.sort_by_names or sorted_by_names(h)
# sort axes by label
h.project(*[i[0] for i in sorted(enumerate(h.axes.label), key=lambda x:x[1], reverse=False)]) # we may want h.sort_by_labels or sorted_by_labels(h) |
No, I mean you only have access to the StrCategory label (like |
When completed, closes #222
To implement:
@henryiii could you take a look? I had to abuse some design decisions of hist to get this work, so maybe you can recommend better workarounds.
Here is a couple of examples




2D - yax
2D - xax
1D
3D - sort on not-projected axis