From 2d6d5c41b2462da3da19638e3b5f85f0406a9c15 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 25 Feb 2019 23:32:39 -0800 Subject: [PATCH 1/3] Small clean-ups. --- Doc/library/statistics.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/statistics.rst b/Doc/library/statistics.rst index a0d4d391022008..8d961b7ca5b18a 100644 --- a/Doc/library/statistics.rst +++ b/Doc/library/statistics.rst @@ -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 `_ of data and *sigma* + mean `_ and *sigma* represents the `standard deviation - `_ of the data. + `_. 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 ---------------------------------------- -A :class:`NormalDist` readily solves classic probability problems. +:class:`NormalDist` readily solves classic probability problems. For example, given `historical data for SAT exams `_ showing that scores From 56e0ddbcdc7c48f501d46ff24d351e5308851240 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 28 Feb 2019 08:42:59 -0800 Subject: [PATCH 2/3] Add tests for special values --- Lib/test/test_statistics.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py index d35cdd8420a376..4adc5e4cbf4ae1 100644 --- a/Lib/test/test_statistics.py +++ b/Lib/test/test_statistics.py @@ -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 @@ -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) From 9d9860a9a8d61c19e6b9d062dfbb114c0d125c19 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 28 Feb 2019 08:52:13 -0800 Subject: [PATCH 3/3] Fix typo in docstring --- Lib/statistics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/statistics.py b/Lib/statistics.py index bab585750d9124..e917a5dddd8be9 100644 --- a/Lib/statistics.py +++ b/Lib/statistics.py @@ -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))))