Skip to content

Commit 4d215a7

Browse files
authored
feat: Allow skipping of validation when combining workspaces (#2385)
* Add validate arg to workspace.combine to allow for optionally skipping workspace validation during. Default is to validate. * Add test for validate arg being used. * Add Lorenz Gaertner to contributors list.
1 parent b4fec1c commit 4d215a7

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

docs/contributors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ Contributors include:
3333
- Beojan Stanislaus
3434
- Daniel Werner
3535
- Jonas Rembser
36+
- Lorenz Gaertner

src/pyhf/workspace.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,9 @@ def rename(self, modifiers=None, samples=None, channels=None, measurements=None)
706706
)
707707

708708
@classmethod
709-
def combine(cls, left, right, join='none', merge_channels=False):
709+
def combine(
710+
cls, left, right, join='none', merge_channels=False, validate: bool = True
711+
):
710712
"""
711713
Return a new workspace specification that is the combination of the two workspaces.
712714
@@ -733,6 +735,7 @@ def combine(cls, left, right, join='none', merge_channels=False):
733735
right (~pyhf.workspace.Workspace): Another workspace
734736
join (:obj:`str`): How to join the two workspaces. Pick from "none", "outer", "left outer", or "right outer".
735737
merge_channels (:obj:`bool`): Whether or not to merge channels when performing the combine. This is only done with "outer", "left outer", and "right outer" options.
738+
validate (:obj:`bool`): Whether to validate against a JSON schema.
736739
737740
Returns:
738741
~pyhf.workspace.Workspace: A new combined workspace object
@@ -770,7 +773,7 @@ def combine(cls, left, right, join='none', merge_channels=False):
770773
'observations': new_observations,
771774
'version': new_version,
772775
}
773-
return cls(newspec)
776+
return cls(newspec, validate=validate)
774777

775778
@classmethod
776779
def sorted(cls, workspace):

tests/test_workspace.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,28 @@ def test_combine_workspace(workspace_factory, join):
791791
)
792792

793793

794+
@pytest.mark.parametrize("join", pyhf.Workspace.valid_joins)
795+
def test_combine_workspace_without_validation(mocker, workspace_factory, join):
796+
ws = workspace_factory()
797+
new_ws = ws.rename(
798+
channels={channel: f"renamed_{channel}" for channel in ws.channels},
799+
samples={sample: f"renamed_{sample}" for sample in ws.samples},
800+
modifiers={
801+
modifier: f"renamed_{modifier}"
802+
for modifier, _ in ws.modifiers
803+
if modifier != "lumi"
804+
},
805+
measurements={
806+
measurement: f"renamed_{measurement}"
807+
for measurement in ws.measurement_names
808+
},
809+
)
810+
811+
mocker.patch("pyhf.schema.validate")
812+
pyhf.Workspace.combine(ws, new_ws, join=join, validate=False)
813+
assert pyhf.schema.validate.called is False
814+
815+
794816
def test_workspace_equality(workspace_factory):
795817
ws = workspace_factory()
796818
ws_other = workspace_factory()

0 commit comments

Comments
 (0)