Skip to content
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: Allow skipping of validation when combining workspaces #2385

Merged
merged 6 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/contributors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ Contributors include:
- Beojan Stanislaus
- Daniel Werner
- Jonas Rembser
- Lorenz Gaertner
7 changes: 5 additions & 2 deletions src/pyhf/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,9 @@ def rename(self, modifiers=None, samples=None, channels=None, measurements=None)
)

@classmethod
def combine(cls, left, right, join='none', merge_channels=False):
def combine(
cls, left, right, join='none', merge_channels=False, validate: bool = True
):
"""
Return a new workspace specification that is the combination of the two workspaces.

Expand All @@ -733,6 +735,7 @@ def combine(cls, left, right, join='none', merge_channels=False):
right (~pyhf.workspace.Workspace): Another workspace
join (:obj:`str`): How to join the two workspaces. Pick from "none", "outer", "left outer", or "right outer".
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.
validate (:obj:`bool`): Whether to validate against a JSON schema

Returns:
~pyhf.workspace.Workspace: A new combined workspace object
Expand Down Expand Up @@ -770,7 +773,7 @@ def combine(cls, left, right, join='none', merge_channels=False):
'observations': new_observations,
'version': new_version,
}
return cls(newspec)
return cls(newspec, validate=validate)
matthewfeickert marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def sorted(cls, workspace):
Expand Down
22 changes: 22 additions & 0 deletions tests/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,28 @@ def test_combine_workspace(workspace_factory, join):
)


@pytest.mark.parametrize("join", pyhf.Workspace.valid_joins)
def test_combine_workspace_without_validation(mocker, workspace_factory, join):
ws = workspace_factory()
new_ws = ws.rename(
channels={channel: f'renamed_{channel}' for channel in ws.channels},
samples={sample: f'renamed_{sample}' for sample in ws.samples},
modifiers={
modifier: f'renamed_{modifier}'
for modifier, _ in ws.modifiers
if not modifier == 'lumi'
},
measurements={
measurement: f'renamed_{measurement}'
for measurement in ws.measurement_names
},
)

mocker.patch('pyhf.schema.validate')
pyhf.Workspace.combine(ws, new_ws, join=join, validate=False)
assert pyhf.schema.validate.called is False


def test_workspace_equality(workspace_factory):
ws = workspace_factory()
ws_other = workspace_factory()
Expand Down