Skip to content

Commit

Permalink
Statistics inv_cdf sync with corresponding random module normal distr…
Browse files Browse the repository at this point in the history
…ibutions (python#95265)
  • Loading branch information
rhettinger authored Jul 26, 2022
1 parent b7ce462 commit 4395ff1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 0 additions & 2 deletions Lib/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,8 +1221,6 @@ def inv_cdf(self, p):
"""
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):
Expand Down
7 changes: 4 additions & 3 deletions Lib/test/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2801,9 +2801,10 @@ def test_inv_cdf(self):
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'))))
Expand Down
2 changes: 1 addition & 1 deletion Modules/_statisticsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 4395ff1

Please sign in to comment.