Repository navigation
gh-162743: Fix correlation mean rounding for large timestamps - #162799
Open
Sudhakar7J wants to merge 1 commit into
Open
Sudhakar7J wants to merge 1 commit into
Sudhakar7J wants to merge 1 commit into
Conversation
Compensate the mean in statistics.correlation() so floating-point rounding in fsum/n does not corrupt centered data when inputs are large with small differences.
Sudhakar7J
force-pushed
the
fix/gh-162743-correlation-mean
branch
from
November 28, 2026 09:41
f7d110b to
5479f58
Compare
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.
Summary
statistics.correlation()computed means asfsum(x) / nand centered data with that rounded mean. For large timestamp-like inputs where the mean is not exactly representable as a float, this can shift the centered sums enough to produce a wrong correlation (the issue reports-0.2instead of+1.0).This adds a one-step mean compensation (
xbar += fsum(xi - xbar for xi in x) / n) before centering, which corrects the floating-point rounding error in the mean.Test Plan
test_correlation_large_timestamp_precisionregression test.statistics.py: reported case returns1.0, existing sanity cases still pass.AI assistance: this change was drafted with an AI coding agent; I reviewed the issue, fix, and test before opening the PR.