Skip to content

gh-162743: Fix correlation mean rounding for large timestamps - #162799

Open
Sudhakar7J wants to merge 1 commit into
python:mainfrom
Sudhakar7J:fix/gh-162743-correlation-mean
Open

Sudhakar7J wants to merge 1 commit into
python:mainfrom
Sudhakar7J:fix/gh-162743-correlation-mean

Conversation

@Sudhakar7J

Copy link
Copy Markdown

Summary

statistics.correlation() computed means as fsum(x) / n and 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.2 instead 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

  • Added test_correlation_large_timestamp_precision regression test.
  • Verified locally on Windows/Python 3.15.2 with the patched statistics.py: reported case returns 1.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.

@python-cla-bot

python-cla-bot Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant