]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Statistics inv_cdf sync with corresponding random module normal distributions (#95265)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Tue, 26 Jul 2022 07:23:33 +0000 (02:23 -0500)
committerGitHub <noreply@github.com>
Tue, 26 Jul 2022 07:23:33 +0000 (02:23 -0500)
Lib/statistics.py
Lib/test/test_statistics.py
Modules/_statisticsmodule.c

index 9d775e74f81c64da3c3e411bccf0d9b43eccb924..c78d64518853e77003e2d6c0ff5bc30c99f38303 100644 (file)
@@ -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):
index 6de98241c294d79d3070115b4ec8a9b749f7be6e..bf85525dd129a55a407f9b8404254b33f2f67fc1 100644 (file)
@@ -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'))))
index 78c0676a01f027b95be93463bb71938f84b4bc85..b9d1e4f1616036095873f98cffef2de10e33a577 100644 (file)
@@ -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;
     }