Skip to content

bpo-36018: Add special value tests and make minor tweaks to the docs #12096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Doc/library/statistics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,9 @@ of applications in statistics, including simulations and hypothesis testing.
.. class:: NormalDist(mu=0.0, sigma=1.0)

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

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

Expand Down Expand Up @@ -579,7 +579,7 @@ of applications in statistics, including simulations and hypothesis testing.
:class:`NormalDist` Examples and Recipes
----------------------------------------

A :class:`NormalDist` readily solves classic probability problems.
:class:`NormalDist` readily solves classic probability problems.

For example, given `historical data for SAT exams
<https://blog.prepscholar.com/sat-standard-deviation>`_ showing that scores
Expand Down
2 changes: 1 addition & 1 deletion Lib/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ def pdf(self, x):
return exp((x - self.mu)**2.0 / (-2.0*variance)) / sqrt(tau * variance)

def cdf(self, x):
'Cumulative density function: P(X <= x)'
'Cumulative distribution function: P(X <= x)'
if not self.sigma:
raise StatisticsError('cdf() not defined when sigma is zero')
return 0.5 * (1.0 + erf((x - self.mu) / (self.sigma * sqrt(2.0))))
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2113,6 +2113,10 @@ def test_pdf(self):
Y = NormalDist(100, 0)
with self.assertRaises(statistics.StatisticsError):
Y.pdf(90)
# Special values
self.assertEqual(X.pdf(float('-Inf')), 0.0)
self.assertEqual(X.pdf(float('Inf')), 0.0)
self.assertTrue(math.isnan(X.pdf(float('NaN'))))

def test_cdf(self):
NormalDist = statistics.NormalDist
Expand All @@ -2127,6 +2131,10 @@ def test_cdf(self):
Y = NormalDist(100, 0)
with self.assertRaises(statistics.StatisticsError):
Y.cdf(90)
# Special values
self.assertEqual(X.cdf(float('-Inf')), 0.0)
self.assertEqual(X.cdf(float('Inf')), 1.0)
self.assertTrue(math.isnan(X.cdf(float('NaN'))))

def test_properties(self):
X = statistics.NormalDist(100, 15)
Expand Down