Skip to content

Commit 4395ff1

Browse files
authored
Statistics inv_cdf sync with corresponding random module normal distributions (#95265)
1 parent b7ce462 commit 4395ff1

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

Lib/statistics.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,8 +1221,6 @@ def inv_cdf(self, p):
12211221
"""
12221222
if p <= 0.0 or p >= 1.0:
12231223
raise StatisticsError('p must be in the range 0.0 < p < 1.0')
1224-
if self._sigma <= 0.0:
1225-
raise StatisticsError('cdf() not defined when sigma at or below zero')
12261224
return _normal_dist_inv_cdf(p, self._mu, self._sigma)
12271225

12281226
def quantiles(self, n=4):

Lib/test/test_statistics.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,9 +2801,10 @@ def test_inv_cdf(self):
28012801
iq.inv_cdf(1.0) # p is one
28022802
with self.assertRaises(self.module.StatisticsError):
28032803
iq.inv_cdf(1.1) # p over one
2804-
with self.assertRaises(self.module.StatisticsError):
2805-
iq = NormalDist(100, 0) # sigma is zero
2806-
iq.inv_cdf(0.5)
2804+
2805+
# Supported case:
2806+
iq = NormalDist(100, 0) # sigma is zero
2807+
self.assertEqual(iq.inv_cdf(0.5), 100)
28072808

28082809
# Special values
28092810
self.assertTrue(math.isnan(Z.inv_cdf(float('NaN'))))

Modules/_statisticsmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ _statistics__normal_dist_inv_cdf_impl(PyObject *module, double p, double mu,
3131
/*[clinic end generated code: output=02fd19ddaab36602 input=24715a74be15296a]*/
3232
{
3333
double q, num, den, r, x;
34-
if (p <= 0.0 || p >= 1.0 || sigma <= 0.0) {
34+
if (p <= 0.0 || p >= 1.0) {
3535
goto error;
3636
}
3737

0 commit comments

Comments
 (0)