]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36018: Add special value tests and make minor tweaks to the docs (GH-12096)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Thu, 28 Feb 2019 17:16:25 +0000 (09:16 -0800)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 28 Feb 2019 17:16:25 +0000 (09:16 -0800)
https://bugs.python.org/issue36018

Doc/library/statistics.rst
Lib/statistics.py
Lib/test/test_statistics.py

index a0d4d3910220088052a80eac16b0b25599cb4268..8d961b7ca5b18a23887c158e680113ef7485e70d 100644 (file)
@@ -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`.
 
@@ -579,7 +579,7 @@ of applications in statistics, including simulations and hypothesis testing.
 :class:`NormalDist` Examples and Recipes
 ----------------------------------------
 
-: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
index bab585750d9124ce91785183c9d5feb20e542e7f..e917a5dddd8be9ded944d390868467f348bca1fb 100644 (file)
@@ -735,7 +735,7 @@ class NormalDist:
         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))))
index d35cdd8420a37638ee40f949c35c40e77a75170c..4adc5e4cbf4ae198b46fb235c9ffdff9293eea3c 100644 (file)
@@ -2113,6 +2113,10 @@ class TestNormalDist(unittest.TestCase):
         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
@@ -2127,6 +2131,10 @@ class TestNormalDist(unittest.TestCase):
         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)