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

Workspace.prune only accepts lists #1684

Closed
1 task done
alexander-held opened this issue Nov 5, 2021 · 0 comments · Fixed by #1692
Closed
1 task done

Workspace.prune only accepts lists #1684

alexander-held opened this issue Nov 5, 2021 · 0 comments · Fixed by #1692
Labels
bug Something isn't working needs-triage Needs a maintainer to categorize and assign user request Request coming form a pyhf user

Comments

@alexander-held
Copy link
Member

Summary

The docstring for Workspace.prune signals support for str arguments, but currently only lists are supported (tested for modifier types / samples / channels). This happens since _prune_and_rename iterates over its arguments without enforcing conversion to lists first. Happy to provide a MR to fix this behavior if desired, or update the docstrings to require list arguments.

OS / Environment

n/a

Steps to Reproduce

import pyhf

spec = {
    "channels": [
        {
            "name": "SR",
            "samples": [
                {"data": [10.0], "name": "Signal", "modifiers": []},
                {
                    "data": [112.0],
                    "modifiers": [
                        {
                            "data": {"hi_data": [67.0], "lo_data": [158.0]},
                            "name": "Modeling",
                            "type": "histosys"
                        }
                    ],
                    "name": "Background"
                }
            ]
        }
    ],
    "measurements": [
        {"config": {"parameters": [], "poi": ""}, "name": "minimal_example"}
    ],
    "observations": [
        {"data": [120.0], "name": "SR"}
    ],
    "version": "1.0.0"
}

ws = pyhf.Workspace(spec)
ws.prune(modifier_types=["histosys"])  # works fine
ws.prune(modifier_types="histosys")  # pyhf.exceptions.InvalidWorkspaceOperation
ws.prune(samples="Background")  # pyhf.exceptions.InvalidWorkspaceOperation
ws.prune(channels="SR")  # pyhf.exceptions.InvalidWorkspaceOperation

File Upload (optional)

No response

Expected Results

No exceptions raised.

Actual Results

Traceback (most recent call last):
  File "test.py", line 34, in <module>
    ws.prune(modifier_types="histosys")  # pyhf.exceptions.InvalidWorkspaceOperation
  File "[...]/pyhf/src/pyhf/workspace.py", line 638, in prune
    return self._prune_and_rename(
  File "[...]/pyhf/src/pyhf/workspace.py", line 513, in _prune_and_rename
    raise exceptions.InvalidWorkspaceOperation(
pyhf.exceptions.InvalidWorkspaceOperation: h is not one of the modifier types in this workspace.

pyhf Version

0.6.4.dev38

Code of Conduct

  • I agree to follow the Code of Conduct
@alexander-held alexander-held added bug Something isn't working needs-triage Needs a maintainer to categorize and assign labels Nov 5, 2021
@matthewfeickert matthewfeickert added the user request Request coming form a pyhf user label Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Needs a maintainer to categorize and assign user request Request coming form a pyhf user
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants