summaryrefslogtreecommitdiffstats
path: root/Lib/statistics.py
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2024-05-05 17:29:23 (GMT)
committerGitHub <noreply@github.com>2024-05-05 17:29:23 (GMT)
commit5092ea238e28c7d099c662d416b2a96fdbea4790 (patch)
tree0266e5db030fd8f5544c5689949e1cb896ef88bb /Lib/statistics.py
parent9c13d9e37a194f574b8591da634bf98419786448 (diff)
downloadcpython-5092ea238e28c7d099c662d416b2a96fdbea4790.zip
cpython-5092ea238e28c7d099c662d416b2a96fdbea4790.tar.gz
cpython-5092ea238e28c7d099c662d416b2a96fdbea4790.tar.bz2
Fix negative bandwidth test and add online code path test. (gh-118600)
Diffstat (limited to 'Lib/statistics.py')
-rw-r--r--Lib/statistics.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/statistics.py b/Lib/statistics.py
index f3ce2d8..c2f4fe8 100644
--- a/Lib/statistics.py
+++ b/Lib/statistics.py
@@ -1791,9 +1791,8 @@ def kde_random(data, h, kernel='normal', *, seed=None):
if h <= 0.0:
raise StatisticsError(f'Bandwidth h must be positive, not {h=!r}')
- try:
- kernel_invcdf = _kernel_invcdfs[kernel]
- except KeyError:
+ kernel_invcdf = _kernel_invcdfs.get(kernel)
+ if kernel_invcdf is None:
raise StatisticsError(f'Unknown kernel name: {kernel!r}')
prng = _random.Random(seed)