diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2022-05-04 04:22:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-04 04:22:04 (GMT) |
commit | d20bb33f782f5677256d7e1f2462b78113692969 (patch) | |
tree | d8590cc4889b6bc3245f81c48aa308e64f33fb36 /Lib/statistics.py | |
parent | 7d7a378c1a351a2074e9e46838718a2dcbef2948 (diff) | |
download | cpython-d20bb33f782f5677256d7e1f2462b78113692969.zip cpython-d20bb33f782f5677256d7e1f2462b78113692969.tar.gz cpython-d20bb33f782f5677256d7e1f2462b78113692969.tar.bz2 |
Fix renamed "total" variable (#92287)
* Fix renamed "total" variable
* Keep nan/inf handling consistent between versions
Diffstat (limited to 'Lib/statistics.py')
-rw-r--r-- | Lib/statistics.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/statistics.py b/Lib/statistics.py index 5a3de81..c022088 100644 --- a/Lib/statistics.py +++ b/Lib/statistics.py @@ -234,7 +234,7 @@ def _ss(data, c=None): # The sum will be a NAN or INF. We can ignore all the finite # partials, and just look at this special one. ssd = c = sx_partials[None] - assert not _isfinite(total) + assert not _isfinite(ssd) else: sx = sum(Fraction(n, d) for d, n in sx_partials.items()) sxx = sum(Fraction(n, d*d) for d, n in sxx_partials.items()) @@ -945,7 +945,11 @@ def _mean_stdev(data): if n < 2: raise StatisticsError('stdev requires at least two data points') mss = ss / (n - 1) - return float(xbar), _float_sqrt_of_frac(mss.numerator, mss.denominator) + try: + return float(xbar), _float_sqrt_of_frac(mss.numerator, mss.denominator) + except AttributeError: + # Handle Nans and Infs gracefully + return float(xbar), float(xbar) / float(ss) # === Statistics for relations between two inputs === |