Skip to content

Commit b3a2456

Browse files
authored
Added checks that tolerance value is between 0 and 1 (openmc-dev#2884)
1 parent e8f68a0 commit b3a2456

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

openmc/stats/univariate.py

+3
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ def clip(self, tolerance: float = 1e-6, inplace: bool = False) -> Discrete:
280280
Discrete distribution with low-importance points removed
281281
282282
"""
283+
cv.check_less_than("tolerance", tolerance, 1.0, equality=True)
284+
cv.check_greater_than("tolerance", tolerance, 0.0, equality=True)
285+
283286
# Determine (reversed) sorted order of probabilities
284287
intensity = self.p * self.x
285288
index_sort = np.argsort(intensity)[::-1]

tests/unit_tests/test_stats.py

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ def test_clip_discrete():
8989
d_same = d.clip(1e-6, inplace=True)
9090
assert d_same is d
9191

92+
with pytest.raises(ValueError):
93+
d.clip(-1.)
94+
95+
with pytest.raises(ValueError):
96+
d.clip(5)
97+
9298

9399
def test_uniform():
94100
a, b = 10.0, 20.0

0 commit comments

Comments
 (0)