aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_statistics.py
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2024-03-24 11:35:58 +0200
committerGitHub <noreply@github.com>2024-03-24 04:35:58 -0500
commita1e948edba9ec6ba61365429857f7a087c5edf51 (patch)
tree1cf07e589f0624d4fececa0da52c074fdb6ccc3b /Lib/test/test_statistics.py
parentd610d821fd210dce63a1132c274ffdf8acc510bc (diff)
downloadcpython-a1e948edba9ec6ba61365429857f7a087c5edf51.tar.gz
cpython-a1e948edba9ec6ba61365429857f7a087c5edf51.zip
Add cumulative option for the new statistics.kde() function. (#117033)
Diffstat (limited to 'Lib/test/test_statistics.py')
-rw-r--r--Lib/test/test_statistics.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py
index 1cf41638a7f..204787a88a9 100644
--- a/Lib/test/test_statistics.py
+++ b/Lib/test/test_statistics.py
@@ -2379,6 +2379,18 @@ class TestKDE(unittest.TestCase):
area = integrate(f_hat, -20, 20)
self.assertAlmostEqual(area, 1.0, places=4)
+ # Check CDF against an integral of the PDF
+
+ data = [3, 5, 10, 12]
+ h = 2.3
+ x = 10.5
+ for kernel in kernels:
+ with self.subTest(kernel=kernel):
+ cdf = kde(data, h, kernel, cumulative=True)
+ f_hat = kde(data, h, kernel)
+ area = integrate(f_hat, -20, x, 100_000)
+ self.assertAlmostEqual(cdf(x), area, places=4)
+
# Check error cases
with self.assertRaises(StatisticsError):
@@ -2395,6 +2407,8 @@ class TestKDE(unittest.TestCase):
kde(sample, h='str') # Wrong bandwidth type
with self.assertRaises(StatisticsError):
kde(sample, h=1.0, kernel='bogus') # Invalid kernel
+ with self.assertRaises(TypeError):
+ kde(sample, 1.0, 'gauss', True) # Positional cumulative argument
# Test name and docstring of the generated function
@@ -2403,7 +2417,7 @@ class TestKDE(unittest.TestCase):
f_hat = kde(sample, h, kernel)
self.assertEqual(f_hat.__name__, 'pdf')
self.assertIn(kernel, f_hat.__doc__)
- self.assertIn(str(h), f_hat.__doc__)
+ self.assertIn(repr(h), f_hat.__doc__)
# Test closed interval for the support boundaries.
# In particular, 'uniform' should non-zero at the boundaries.