Skip to content

statistics.quantiles produces infinite cut points from finite inputs with representable results #158759

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: The statistics.quantiles documentation states: "The cut points are linearly interpolated from the two nearest data points." For method='exclusive', it states: "The portion of the population falling below the i-th of m sorted data points is computed as i / (m + 1)." With two observations, these rules place them at probabilities 1/3 and 2/3 and determine the stated quartiles.

Expected: For a=6e307, approximately [-9e307, 0.0, 9e307], all finite.

Actual: [-inf, 0.0, inf]

import statistics
import math

a = 6e307
data = [-a, a]
if len(data) < 2 or not all(math.isfinite(x) for x in data):
    print("REFUTATION REJECTED: invalid input")
else:
    actual = statistics.quantiles(data, n=4, method="exclusive")
    # Interpolate/extrapolate between (-a, 1/3) and (a, 2/3).
    expected = [a * (3 * i / 2 - 3) for i in range(1, 4)]
    if len(actual) != 3 or any(
        not math.isfinite(x) or not math.isclose(x, y, rel_tol=1e-14, abs_tol=0.0)
        for x, y in zip(actual, expected)
    ):
        print("REFUTATION CONFIRMED:", data, "actual:", actual, "expected:", expected)
    else:
        print("REFUTATION REJECTED: actual matches documented expectation")

Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library statistics:

REFUTATION CONFIRMED: [-6e+307, 6e+307] actual: [-inf, 0.0, inf] expected: [-8.999999999999999e+307, 0.0, 8.999999999999999e+307]

This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/statistics-20261003-154526-c4

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions