-
Notifications
You must be signed in to change notification settings - Fork 92
Closed
Labels
feat/enhancementNew feature or requestNew feature or requestneeds-triageNeeds a maintainer to categorize and assignNeeds a maintainer to categorize and assignuser requestRequest coming form a pyhf userRequest coming form a pyhf user
Description
Summary
#1639 very slightly changed the return type of model.config.suggested_fixed(). It used to be List[bool], but now some elements can be numpy.bool_, which behaves differently (see numpy/numpy#9646):
>>> import numpy as np
>>> isinstance(np.bool_(True), bool)
FalseThis makes typing / type checking in libraries using pyhf more complicated (spotted via scikit-hep/cabinetry#301). Would it be possible to consistently return List[bool] again instead?
Additional Information
The example below shows how numpy.bool_ entries appear for some, but not all models.
import pyhf
spec = {
"channels": [
{
"name": "SR",
"samples": [
{
"data": [25, 5],
"modifiers": [
{
"data": [5, 2],
"name": "staterror_SR",
"type": "staterror",
},
],
"name": "Signal",
}
],
},
],
"measurements": [{"config": {"parameters": [], "poi": ""}, "name": "fit"}],
"observations": [
{"data": [35, 8], "name": "SR"},
],
"version": "1.0.0",
}
def check_types(model):
for i, par in enumerate(model.config.suggested_fixed()):
if not isinstance(par, bool):
print(f"{model.config.par_names()[i]} has type {type(par)}")
model = pyhf.simplemodels.correlated_background([5], [10], [11], [9])
print("checking correlated_background model")
check_types(model)
model = pyhf.Workspace(spec).model()
print("checking custom model")
check_types(model)Output for 9fbbbf9 and later (including current master):
checking correlated_background model
checking custom model
staterror_SR[0] has type <class 'numpy.bool_'>
staterror_SR[1] has type <class 'numpy.bool_'>
Output for 5ea4e0a:
checking correlated_background model
checking custom model
Code of Conduct
- I agree to follow the Code of Conduct
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feat/enhancementNew feature or requestNew feature or requestneeds-triageNeeds a maintainer to categorize and assignNeeds a maintainer to categorize and assignuser requestRequest coming form a pyhf userRequest coming form a pyhf user