-
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.
Update to pybind11 v2.12 and migrate to string infinity (#242)
* Update to pybind11 v2.12 * Require string representation of infinity Closes #208 * MSVC doesn't like "or" * Fixup typing * Use MacOS 13 runner for python matrix, latest for 3.12 As the MacOS 14+ runners use the M1 chip and those don't support python versions older than 3.10 * Drop pypy * Add some more tests for string inf
- Loading branch information
Showing
6 changed files
with
116 additions
and
62 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
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
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,41 @@ | ||
import pytest | ||
|
||
from correctionlib import schemav2 as schema | ||
|
||
|
||
def _make_binning(edges, content): | ||
corr = schema.Correction( | ||
name="test corr", | ||
version=2, | ||
inputs=[ | ||
schema.Variable(name="x", type="real"), | ||
], | ||
output=schema.Variable(name="a scale", type="real"), | ||
data=schema.Binning.model_validate( | ||
{ | ||
"nodetype": "binning", | ||
"input": "x", | ||
"edges": edges, | ||
"flow": "error", | ||
"content": content, | ||
} | ||
), | ||
) | ||
return corr.to_evaluator() | ||
|
||
|
||
def test_string_infinity(): | ||
corr = _make_binning([0, 20, 40, "inf"], [1.0, 1.1, 1.2]) | ||
assert corr.evaluate(10.0) == 1.0 | ||
assert corr.evaluate(100.0) == 1.2 | ||
corr = _make_binning([0, 20, 40, "+inf"], [1.0, 1.1, 1.2]) | ||
assert corr.evaluate(100.0) == 1.2 | ||
corr = _make_binning(["-inf", 20, 40, "+inf"], [1.0, 1.1, 1.2]) | ||
assert corr.evaluate(-100.0) == 1.0 | ||
|
||
with pytest.raises(ValueError): | ||
_make_binning([0, 20, 40, "infinity"], [1.0, 1.1, 1.2]) | ||
with pytest.raises(ValueError): | ||
_make_binning([0, 20, 40, float("inf")], [1.0, 1.1, 1.2]) | ||
with pytest.raises(ValueError): | ||
_make_binning([0, "inf", 20, 40], [1.0, 1.1, 1.2]) |