Skip to content

gh-160034: Raise ValueError in variance() and pvariance() for inf or nan data - #160041

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:gh-160034-variance-pvariance-inf-nan
Open

tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:gh-160034-variance-pvariance-inf-nan

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

variance() and pvariance() now raise ValueError('inf or nan encountered in data') for data containing inf or nan, matching stdev() and
pstdev() (gh-140938).

_ss() returns the sum of squared deviations as a Fraction for all finite
data, and as a non-Fraction only for inf/nan input, so the guard is a
type check on that value. A type check rather than math.isfinite(float(ss))
avoids an OverflowError on huge but finite integer data.

test_gh_140938 moves from TestPStdev into VarianceStdevMixin, so it now
covers variance, pvariance, stdev and pstdev, and gains the negative
(-inf) case.

…r nan data

variance() and pvariance() returned a non-finite (and possibly negative)
result for data containing inf or nan. Raise ValueError instead, matching
stdev() and pstdev().
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