https://github.com/python/cpython/commit/41554ef0e0925695544d96a7bc49af1428d6bb6b
commit: 41554ef0e0925695544d96a7bc49af1428d6bb6b
branch: main
author: Raymond Hettinger <[email protected]>
committer: rhettinger <[email protected]>
date: 2024-06-14T10:21:35-05:00
summary:

Stronger tests for the statistics kernel formulas (gh-120506)

files:
M Lib/test/test_statistics.py

diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py
index 0b28459f03d86a..c374c947e02a6b 100644
--- a/Lib/test/test_statistics.py
+++ b/Lib/test/test_statistics.py
@@ -2434,18 +2434,22 @@ def integrate(func, low, high, steps=10_000):
         data.append(100)
         self.assertGreater(f_hat(100), 0.0)
 
-    def test_kde_kernel_invcdfs(self):
+    def test_kde_kernel_specs(self):
+        # White-box test for the kernel formulas in isolation from
+        # their downstream use in kde() and kde_random()
         kernel_specs = statistics._kernel_specs
-        kde = statistics.kde
 
         # Verify that cdf / invcdf will round trip
         xarr = [i/100 for i in range(-100, 101)]
+        parr = [i/1000 + 5/10000 for i in range(1000)]
         for kernel, spec in kernel_specs.items():
+            cdf = spec['cdf']
             invcdf = spec['invcdf']
             with self.subTest(kernel=kernel):
-                cdf = kde([0.0], h=1.0, kernel=kernel, cumulative=True)
                 for x in xarr:
                     self.assertAlmostEqual(invcdf(cdf(x)), x, places=6)
+                for p in parr:
+                    self.assertAlmostEqual(cdf(invcdf(p)), p, places=11)
 
     @support.requires_resource('cpu')
     def test_kde_random(self):

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to