From 4395ff1e6a18fb26c7a66b1c29b34ed60ddd001c Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 26 Jul 2022 02:23:33 -0500 Subject: [PATCH] Statistics inv_cdf sync with corresponding random module normal distributions (#95265) --- Lib/statistics.py | 2 -- Lib/test/test_statistics.py | 7 ++++--- Modules/_statisticsmodule.c | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Lib/statistics.py b/Lib/statistics.py index 9d775e74f81..c78d6451885 100644 --- a/Lib/statistics.py +++ b/Lib/statistics.py @@ -1221,8 +1221,6 @@ class NormalDist: """ if p <= 0.0 or p >= 1.0: raise StatisticsError('p must be in the range 0.0 < p < 1.0') - if self._sigma <= 0.0: - raise StatisticsError('cdf() not defined when sigma at or below zero') return _normal_dist_inv_cdf(p, self._mu, self._sigma) def quantiles(self, n=4): diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py index 6de98241c29..bf85525dd12 100644 --- a/Lib/test/test_statistics.py +++ b/Lib/test/test_statistics.py @@ -2801,9 +2801,10 @@ class TestNormalDist: iq.inv_cdf(1.0) # p is one with self.assertRaises(self.module.StatisticsError): iq.inv_cdf(1.1) # p over one - with self.assertRaises(self.module.StatisticsError): - iq = NormalDist(100, 0) # sigma is zero - iq.inv_cdf(0.5) + + # Supported case: + iq = NormalDist(100, 0) # sigma is zero + self.assertEqual(iq.inv_cdf(0.5), 100) # Special values self.assertTrue(math.isnan(Z.inv_cdf(float('NaN')))) diff --git a/Modules/_statisticsmodule.c b/Modules/_statisticsmodule.c index 78c0676a01f..b9d1e4f1616 100644 --- a/Modules/_statisticsmodule.c +++ b/Modules/_statisticsmodule.c @@ -31,7 +31,7 @@ _statistics__normal_dist_inv_cdf_impl(PyObject *module, double p, double mu, /*[clinic end generated code: output=02fd19ddaab36602 input=24715a74be15296a]*/ { double q, num, den, r, x; - if (p <= 0.0 || p >= 1.0 || sigma <= 0.0) { + if (p <= 0.0 || p >= 1.0) { goto error; }