Skip to content

statistics.median overflows for large finite middle values #158753

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: The median() docstring states: "When the number of data points is even, the median is interpolated by taking the average of the two middle values".

Expected: statistics.median([1e308, 1e308]) returns 1e308.

Actual: Returns inf.

import math, statistics

data = [1e308, 1e308]
if not all(math.isfinite(x) and x > 0 for x in data):
    print("REFUTATION REJECTED: input is not finite positive numeric data")
else:
    actual = statistics.median(data)
    expected = data[0] / 2 + data[1] / 2
    if actual != expected:
        print("REFUTATION CONFIRMED:", data, "actual:", actual, "expected:", expected)
    else:
        print("REFUTATION REJECTED: actual equals the documented average")

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

REFUTATION CONFIRMED: [1e+308, 1e+308] actual: inf expected: 1e+308

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-045701-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