hist icon indicating copy to clipboard operation
hist copied to clipboard

[FEATURE] merge / map / map_reduce / combine / some other name

Open henryiii opened this issue 3 years ago • 0 comments

A useful tool could be grouping or merging, such as mentioned in https://github.com/CoffeaTeam/coffea/issues/580 . Currently, this can be done like this, as long as you are okay to remove the axis and get a single result histogram out:

h_only = h1[{"dataset": ["Egamma", "SingleMuon", "DoubleMuon"]}]
h = h_only[{"dataset":sum}]

We could have a method that provides a mapping to merge (and it could be supported on both Stacks and categorical axes):

h1_p = h1.merge("dataset", {"valid": {"Egamma", "SingleMuon", "DoubleMuon"}, "invalid": []}, action=sum)

This would make a new histogram where the "dataset" axis has been reduced from three entries to two (first one is the same of the three existing entries, and one blank in this example).

PS: need to check pick_set + reduce in boost_histogram to see if it works in the correct order.

henryiii avatar Sep 17 '21 20:09 henryiii