Skip to content

Commit

Permalink
feat: Sort _ChannelSummaryMixin.channel_nbins by keys to match `cha…
Browse files Browse the repository at this point in the history
…nnels` order (#1546)

* Sort _ChannelSummaryMixin.channel_nbins dict by keys to match the order of _ChannelSummaryMixin.channels
* Add a test for the order of channel_nbins keys matching the order of channels entries
  • Loading branch information
matthewfeickert authored Aug 5, 2021
1 parent 5eab9ee commit 4b66cd2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/pyhf/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def __init__(self, *args, **kwargs):
self.samples = sorted(list(set(self.samples)))
self.parameters = sorted(list(set(self.parameters)))
self.modifiers = sorted(list(set(self.modifiers)))
self.channel_nbins = {
channel: self.channel_nbins[channel] for channel in self.channels
}

self.channel_slices = {}
begin = 0
Expand Down
9 changes: 9 additions & 0 deletions tests/test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ def test_channel_summary_mixin_empty():
assert mixin.modifiers == []
assert mixin.parameters == []
assert mixin.samples == []


def test_channel_nbins_sorted_as_channels(spec):
assert "channels" in spec
spec["channels"].append(spec["channels"][0].copy())
spec["channels"][-1]["name"] = "a_make_first_in_sort_channel2"
mixin = pyhf.mixins._ChannelSummaryMixin(channels=spec["channels"])
assert mixin.channels == ["a_make_first_in_sort_channel2", "channel1"]
assert list(mixin.channel_nbins.keys()) == mixin.channels

0 comments on commit 4b66cd2

Please sign in to comment.