Skip to content

statistics.fmean raises OverflowError for finite inputs with a representable mean #158756

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: "Convert data to floats and compute the arithmetic mean." — statistics.fmean docstring.

Expected: Return approximately 1e308 without raising.

Actual: OverflowError: intermediate overflow in fsum

import statistics, math
from fractions import Fraction

data = [1e308, 1e308]
if not data or not all(isinstance(x, float) and math.isfinite(x) for x in data):
    print("REFUTATION REJECTED: input is not nonempty finite float data")
else:
    expected = float(sum(map(Fraction, data), Fraction()) / len(data))
    try:
        actual = statistics.fmean(data)
        broken = not math.isclose(actual, expected, rel_tol=1e-15)
    except Exception as e:
        actual = f"{type(e).__name__}: {e}"
        broken = True
    if broken:
        print(f"REFUTATION CONFIRMED: input={data!r}, actual={actual!r}, expected={expected!r}")
    else:
        print("REFUTATION REJECTED: result matches the independently computed arithmetic mean")

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

REFUTATION CONFIRMED: input=[1e+308, 1e+308], actual='OverflowError: intermediate overflow in fsum', 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-124541-c1

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