gh-140938: Raise ValueError for infinite inputs to stdev/pstdev (GH-141531)

Raise ValueError for infinite inputs to stdev/pstdev

---

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
Raymond Hettinger 2025-11-14 17:25:45 -06:00 committed by GitHub
parent 1281be1caf
commit f0a8bc737a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 5 deletions

View file

@ -2005,7 +2005,6 @@ def test_iter_list_same(self):
expected = self.func(data)
self.assertEqual(self.func(iter(data)), expected)
class TestPVariance(VarianceStdevMixin, NumericTestCase, UnivariateTypeMixin):
# Tests for population variance.
def setUp(self):
@ -2113,6 +2112,14 @@ def test_center_not_at_mean(self):
self.assertEqual(self.func(data), 2.5)
self.assertEqual(self.func(data, mu=0.5), 6.5)
def test_gh_140938(self):
# Inputs with inf/nan should raise a ValueError
with self.assertRaises(ValueError):
self.func([1.0, math.inf])
with self.assertRaises(ValueError):
self.func([1.0, math.nan])
class TestSqrtHelpers(unittest.TestCase):
def test_integer_sqrt_of_frac_rto(self):