Skip to content

Commit d20bb33

Browse files
authored
Fix renamed "total" variable (#92287)
* Fix renamed "total" variable * Keep nan/inf handling consistent between versions
1 parent 7d7a378 commit d20bb33

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Lib/statistics.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def _ss(data, c=None):
234234
# The sum will be a NAN or INF. We can ignore all the finite
235235
# partials, and just look at this special one.
236236
ssd = c = sx_partials[None]
237-
assert not _isfinite(total)
237+
assert not _isfinite(ssd)
238238
else:
239239
sx = sum(Fraction(n, d) for d, n in sx_partials.items())
240240
sxx = sum(Fraction(n, d*d) for d, n in sxx_partials.items())
@@ -945,7 +945,11 @@ def _mean_stdev(data):
945945
if n < 2:
946946
raise StatisticsError('stdev requires at least two data points')
947947
mss = ss / (n - 1)
948-
return float(xbar), _float_sqrt_of_frac(mss.numerator, mss.denominator)
948+
try:
949+
return float(xbar), _float_sqrt_of_frac(mss.numerator, mss.denominator)
950+
except AttributeError:
951+
# Handle Nans and Infs gracefully
952+
return float(xbar), float(xbar) / float(ss)
949953

950954

951955
# === Statistics for relations between two inputs ===

0 commit comments

Comments
 (0)