Skip to content

Preserve finite means when summing large samples overflows - #803

Open
Gambit-Checkmate wants to merge 1 commit into
mahmoud:masterfrom
Gambit-Checkmate:fix/finite-mean-overflow
Open

Gambit-Checkmate wants to merge 1 commit into
mahmoud:masterfrom
Gambit-Checkmate:fix/finite-mean-overflow

Conversation

@Gambit-Checkmate

Copy link
Copy Markdown

The change

Fixes #802. Large finite samples such as [1e308, 1e308] return an infinite mean because the sum overflows before division. Keep the usual calculation and fall back to statistics.mean for a nonfinite result on built-in numeric inputs. The example now returns 1e308, and its variance and standard deviation return zero.

Windows CPython 3.13.13 passed 783 tests and doctests, with one platform skip. The original six failure cases cover overflowing positive/negative sums, cancellation and dependent variance. Additional mixed-integer, boolean, nonfinite and complex-number controls pass. Focused checks passed on Linux Python 3.10 and Windows 3.11, 3.12 and 3.14. Ruff E9/F, Python 3.7 syntax and package builds pass.

The backstory

Previous contribution #799. I reproduced this during source inspection by comparing the same large finite samples with the standard library's arithmetic mean. This is separate from the iterable-input work in #780 and integer-variance work in #703/#704.

AI assistance

  • Harness/tooling — OpenAI Codex
  • Model — GPT-6-based Codex agent
  • Original prompt excerpt — “没有合适公开 issue 时可以检查代码、复现真实缺陷,确认无重复后报告问题并提交独立修复。”

Codex investigated, implemented, tested and drafted this submission.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stats.mean overflows for finite samples with representable averages

1 participant