Repository navigation
Preserve finite means when summing large samples overflows - #803
Open
Gambit-Checkmate wants to merge 1 commit into
Open
Gambit-Checkmate wants to merge 1 commit into
Gambit-Checkmate wants to merge 1 commit into
Conversation
This was referenced Nov 19, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 tostatistics.meanfor a nonfinite result on built-in numeric inputs. The example now returns1e308, 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
Codex investigated, implemented, tested and drafted this submission.