Skip to content

Commit 41554ef

Browse files
authored
Stronger tests for the statistics kernel formulas (gh-120506)
1 parent 42351c3 commit 41554ef

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Lib/test/test_statistics.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,18 +2434,22 @@ def integrate(func, low, high, steps=10_000):
24342434
data.append(100)
24352435
self.assertGreater(f_hat(100), 0.0)
24362436

2437-
def test_kde_kernel_invcdfs(self):
2437+
def test_kde_kernel_specs(self):
2438+
# White-box test for the kernel formulas in isolation from
2439+
# their downstream use in kde() and kde_random()
24382440
kernel_specs = statistics._kernel_specs
2439-
kde = statistics.kde
24402441

24412442
# Verify that cdf / invcdf will round trip
24422443
xarr = [i/100 for i in range(-100, 101)]
2444+
parr = [i/1000 + 5/10000 for i in range(1000)]
24432445
for kernel, spec in kernel_specs.items():
2446+
cdf = spec['cdf']
24442447
invcdf = spec['invcdf']
24452448
with self.subTest(kernel=kernel):
2446-
cdf = kde([0.0], h=1.0, kernel=kernel, cumulative=True)
24472449
for x in xarr:
24482450
self.assertAlmostEqual(invcdf(cdf(x)), x, places=6)
2451+
for p in parr:
2452+
self.assertAlmostEqual(cdf(invcdf(p)), p, places=11)
24492453

24502454
@support.requires_resource('cpu')
24512455
def test_kde_random(self):

0 commit comments

Comments
 (0)