Skip to content

Fix base case handling in quantiles() #110150

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

Closed
rhettinger opened this issue Sep 30, 2023 · 0 comments
Closed

Fix base case handling in quantiles() #110150

rhettinger opened this issue Sep 30, 2023 · 0 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@rhettinger
Copy link
Contributor

rhettinger commented Sep 30, 2023

Fix an inconvenience in quantiles() by supporting input lists of length one, much like min(), max(), mean() and median() also support datasets of size one.

The principal use case is making statistical summaries of data streams. It is really inconvenient to require a special case for the first data point. Instead, it is much nicer to make updates as new data arrives, starting with the very first datum.

This is what we want:

"Running five number summary for a data stream"
# https://en.wikipedia.org/wiki/Five-number_summary

from statistics import quantiles
import random

stream = (random.expovariate() for i in range(20))
data = []
for x in stream:
    data.append(x)
    print(min(data), quantiles(data), max(data))

Linked PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant