Skip to content

Fix base case handling in quantiles() #110150

Closed
@rhettinger

Description

@rhettinger

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions