Skip to content

Commit f2e2db9

Browse files
committed
fix: Make pyhf.Workspace.combine return cls instead of Workspace (#1041)
* Workspace.combine returns cls() instead of Workspace() allowing for others to inherit pyhf.Workspace
1 parent cd3ea9f commit f2e2db9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/pyhf/workspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,4 +675,4 @@ def combine(cls, left, right, join='none'):
675675
'observations': new_observations,
676676
'version': new_version,
677677
}
678-
return Workspace(newspec)
678+
return cls(newspec)

tests/test_workspace.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,3 +717,32 @@ def test_workspace_equality(workspace_factory):
717717
assert ws == ws
718718
assert ws == ws_other
719719
assert ws != 'not a workspace'
720+
721+
722+
def test_workspace_inheritance(workspace_factory):
723+
ws = workspace_factory()
724+
new_ws = ws.rename(
725+
channels={'channel1': 'channel3', 'channel2': 'channel4'},
726+
samples={
727+
'background1': 'background3',
728+
'background2': 'background4',
729+
'signal': 'signal2',
730+
},
731+
modifiers={
732+
'syst1': 'syst4',
733+
'bkg1Shape': 'bkg3Shape',
734+
'bkg2Shape': 'bkg4Shape',
735+
},
736+
measurements={
737+
'GaussExample': 'OtherGaussExample',
738+
'GammaExample': 'OtherGammaExample',
739+
'ConstExample': 'OtherConstExample',
740+
'LogNormExample': 'OtherLogNormExample',
741+
},
742+
)
743+
744+
class FooWorkspace(pyhf.Workspace):
745+
pass
746+
747+
combined = FooWorkspace.combine(ws, new_ws)
748+
assert isinstance(combined, FooWorkspace)

0 commit comments

Comments
 (0)