8000 gh-115532: Add kernel density estimation to the statistics module by rhettinger · Pull Request #115863 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-115532: Add kernel density estimation to the statistics module #115863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use StatisticsError for invalid kernels
  • Loading branch information
rhettinger committed Feb 23, 2024
commit e29d64f8c41a953330d757eab2dd8b8b4b814f74
2 changes: 1 addition & 1 deletion Lib/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ def kde(data, h, kernel='normal'):
support = 1.0

case _:
raise ValueError(f'Unknown kernel name: {kernel!r}')
raise StatisticsError(f'Unknown kernel name: {kernel!r}')

if support is None:

Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2391,10 +2391,11 @@ def integrate(func, low, high, steps=10_000):
kde(sample, h=0.0) # Negative bandwidth
with self.assertRaises(TypeError):
kde(sample, h='str') # Wrong bandwidth type
with self.assertRaises(ValueError):
with self.assertRaises(StatisticsError):
kde(sample, h=1.0, kernel='bogus') # Invalid kernel

# Test name and docstring
# Test name and docstring of the generated function

h = 1.5
kernel = 'cosine'
f_hat = kde(sample, h, kernel)
Expand Down
0