Skip to content

Commit ef17fdb

Browse files
rhettingermiss-islington
authored andcommitted
bpo-36018: Add special value tests and make minor tweaks to the docs (GH-12096)
https://bugs.python.org/issue36018
1 parent ae2ea33 commit ef17fdb

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Doc/library/statistics.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,9 @@ of applications in statistics, including simulations and hypothesis testing.
482482
.. class:: NormalDist(mu=0.0, sigma=1.0)
483483

484484
Returns a new *NormalDist* object where *mu* represents the `arithmetic
485-
mean <https://en.wikipedia.org/wiki/Arithmetic_mean>`_ of data and *sigma*
485+
mean <https://en.wikipedia.org/wiki/Arithmetic_mean>`_ and *sigma*
486486
represents the `standard deviation
487-
<https://en.wikipedia.org/wiki/Standard_deviation>`_ of the data.
487+
<https://en.wikipedia.org/wiki/Standard_deviation>`_.
488488

489489
If *sigma* is negative, raises :exc:`StatisticsError`.
490490

@@ -579,7 +579,7 @@ of applications in statistics, including simulations and hypothesis testing.
579579
:class:`NormalDist` Examples and Recipes
580580
----------------------------------------
581581

582-
A :class:`NormalDist` readily solves classic probability problems.
582+
:class:`NormalDist` readily solves classic probability problems.
583583

584584
For example, given `historical data for SAT exams
585585
<https://blog.prepscholar.com/sat-standard-deviation>`_ showing that scores

Lib/statistics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ def pdf(self, x):
735735
return exp((x - self.mu)**2.0 / (-2.0*variance)) / sqrt(tau * variance)
736736

737737
def cdf(self, x):
738-
'Cumulative density function: P(X <= x)'
738+
'Cumulative distribution function: P(X <= x)'
739739
if not self.sigma:
740740
raise StatisticsError('cdf() not defined when sigma is zero')
741741
return 0.5 * (1.0 + erf((x - self.mu) / (self.sigma * sqrt(2.0))))

Lib/test/test_statistics.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,6 +2113,10 @@ def test_pdf(self):
21132113
Y = NormalDist(100, 0)
21142114
with self.assertRaises(statistics.StatisticsError):
21152115
Y.pdf(90)
2116+
# Special values
2117+
self.assertEqual(X.pdf(float('-Inf')), 0.0)
2118+
self.assertEqual(X.pdf(float('Inf')), 0.0)
2119+
self.assertTrue(math.isnan(X.pdf(float('NaN'))))
21162120

21172121
def test_cdf(self):
21182122
NormalDist = statistics.NormalDist
@@ -2127,6 +2131,10 @@ def test_cdf(self):
21272131
Y = NormalDist(100, 0)
21282132
with self.assertRaises(statistics.StatisticsError):
21292133
Y.cdf(90)
2134+
# Special values
2135+
self.assertEqual(X.cdf(float('-Inf')), 0.0)
2136+
self.assertEqual(X.cdf(float('Inf')), 1.0)
2137+
self.assertTrue(math.isnan(X.cdf(float('NaN'))))
21302138

21312139
def test_properties(self):
21322140
X = statistics.NormalDist(100, 15)

0 commit comments

Comments
 (0)