-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cast int inputs to double in binning evaluations
Fixes #217
- Loading branch information
Showing
2 changed files
with
72 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pytest | ||
|
||
import correctionlib.schemav2 as cs | ||
|
||
|
||
def test_issue217(): | ||
content = [1.1, 1.08, 1.06, 1.04, 1.02, 1.0] | ||
corr = cs.Correction( | ||
name="NJetweight", | ||
version=1, | ||
inputs=[cs.Variable(name="nJets", type="int", description="Number of jets")], | ||
output=cs.Variable( | ||
name="weight", type="real", description="Multiplicative event weight" | ||
), | ||
data=cs.Binning( | ||
nodetype="binning", | ||
input="nJets", | ||
edges=[0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5], | ||
content=content, | ||
flow="clamp", | ||
), | ||
) | ||
ceval = corr.to_evaluator() | ||
assert [ceval.evaluate(i) for i in range(1, 7)] == content | ||
|
||
|
||
def test_binning_invalidinput(): | ||
corr = cs.Correction( | ||
name="NJetweight", | ||
version=1, | ||
inputs=[cs.Variable(name="bogus", type="string")], | ||
output=cs.Variable( | ||
name="weight", type="real", description="Multiplicative event weight" | ||
), | ||
data=cs.Binning( | ||
nodetype="binning", | ||
input="bogus", | ||
edges=[0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5], | ||
content=[1.1, 1.08, 1.06, 1.04, 1.02, 1.0], | ||
flow="clamp", | ||
), | ||
) | ||
with pytest.raises(RuntimeError): | ||
corr.to_evaluator() |