[Python-checkins] bpo-45876: Have stdev() also use decimal specific square root. (GH-29869)
rhettinger
webhook-mailer at python.org
Tue Nov 30 20:26:07 EST 2021
https://github.com/python/cpython/commit/0aa0bd056349f73de9577ccc38560c1d01864d51
commit: 0aa0bd056349f73de9577ccc38560c1d01864d51
branch: main
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2021-11-30T19:25:57-06:00
summary:
bpo-45876: Have stdev() also use decimal specific square root. (GH-29869)
files:
M Lib/statistics.py
diff --git a/Lib/statistics.py b/Lib/statistics.py
index 9f1efa21b15e3..ff19ce9672d33 100644
--- a/Lib/statistics.py
+++ b/Lib/statistics.py
@@ -920,9 +920,8 @@ def stdev(data, xbar=None):
raise StatisticsError('stdev requires at least two data points')
T, ss = _ss(data, xbar)
mss = ss / (n - 1)
- if hasattr(T, 'sqrt'):
- var = _convert(mss, T)
- return var.sqrt()
+ if issubclass(T, Decimal):
+ return _decimal_sqrt_of_frac(mss.numerator, mss.denominator)
return _float_sqrt_of_frac(mss.numerator, mss.denominator)
More information about the Python-checkins
mailing list