-
Notifications
You must be signed in to change notification settings - Fork 25
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: HistStack for #169 #244
Conversation
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.05%.
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! |
Maybe with more plotting options here. Any suggestions? |
1613223
to
5851c1e
Compare
h = Hist.new.Reg(..., name="x").StrCat(["one", "two"] name="y").Double()
s = h.stack("y")
s = Stack({"one": h[:, "one"], "two":h[:, "two"]})
# Another way?
h1 = h[:, "one"]
h1.name = "one"
h2 = h[:, "two"]
h2.name = "two"
s = Stack(h1, h2)
h.plot() # -> shortcut for h.stack("y").plot() Thought: Could we above a initial memory copy for stacking an existing histogram? May not be better, due to making copy every access? self._data = h
self[x] # -> pull x from histogram _OR_ list/dict? |
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.
We also need some tests for Stack(axes) and Hist.stack(name/idx)
Done.
src/hist/basehist.py
Outdated
|
||
if isinstance(args[0], int): | ||
stack_args = [self.axes[i] for i in args] | ||
return Stack(*stack_args) |
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.
I think we should only support one arg, which is the axis to stack over. Multiple args would make a ND stack, which we don't want to support, at least for now.
The argument should be the axis to stack over, which should be expanded. For example:
stack_histograms = self[{ax:i}] for i in range(len(self.axis[ax]))]
return Stack(*stack_histograms)
Though I think we also need to keep track of the bin this came from too.
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.
What's the ax
in this example?
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.
In my case, it was the integer axis number to expand. Though if it was a string axis name, since that is supported natively in both h[{...}]
and h.axis[...]
, that should work too. I didn't expand the dict correctly above, though.
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.
Updated the example above - it now no longer "remembers" the cell name, though. Ideally, each histogram would also have at least "h.name" set to the original cell "name". Maybe:
for name, h in zip(self.axes[ax], stack_histograms)
h.name = name
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.
If self.axes[i]
is a StrCategory
, which is most common, then h.name
will be the category that this histogram came from. If it's an integer, then name is an integer - slightly weird, but not too bad. If it's a Regular/Variable, then "name" is a tuple with two floats, which is quite weird for something called "name". But I think it's a reasonable tradeoff - having the value is still useful.
d5c4c60
to
337648e
Compare
Quick summary of changes: axes are not stackable, only histograms. Added a little bit of container-like support so |
Thanks everyone! |
How to use |
I thought there were some. This is what it looks like: h = hist.Hist.new.Reg(10,0,1, name="x").StrCategory(["good", "bad"], name="quality").Double()
# Fill with data tagged with quality="good" or "bad"
stack = h.stack("quality")
assert stack[0].name == "good"
assert stack[1].name == "bad" Ideally, calling Could you add a test like the one above, actually? I'm working on three other features. |
Oops, forgot, |
This is why we write tests! 😳 |
To solve #169.