Skip to content

Commit 70cdade

Browse files
committed
Rename the functions consistently
1 parent f5c091c commit 70cdade

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

Lib/statistics.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,11 @@ def _isqrt_frac_rto(n: int, m: int) -> float:
313313
return a | (a*a*m != n)
314314

315315

316-
# For 53 bit precision floats, the _sqrt_frac() shift is 109.
316+
# For 53 bit precision floats, the _float_sqrt_of_frac() shift is 109.
317317
_sqrt_shift: int = 2 * sys.float_info.mant_dig + 3
318318

319319

320-
def _sqrt_frac(n: int, m: int) -> float:
320+
def _float_sqrt_of_frac(n: int, m: int) -> float:
321321
"""Square root of n/m as a float, correctly rounded."""
322322
# See principle and proof sketch at: https://bugs.python.org/msg407078
323323
q = (n.bit_length() - m.bit_length() - _sqrt_shift) // 2
@@ -330,7 +330,7 @@ def _sqrt_frac(n: int, m: int) -> float:
330330
return numerator / denominator # Convert to float
331331

332332

333-
def _deci_sqrt(n: int, m: int) -> Decimal:
333+
def _decimal_sqrt_of_frac(n: int, m: int) -> Decimal:
334334
"""Square root of n/m as a float, correctly rounded."""
335335
# Premise: For decimal, computing sqrt(m / n) can be off by 1 ulp.
336336
# Method: Check the result, moving up or down a step if needed.
@@ -895,7 +895,7 @@ def stdev(data, xbar=None):
895895
if hasattr(T, 'sqrt'):
896896
var = _convert(mss, T)
897897
return var.sqrt()
898-
return _sqrt_frac(mss.numerator, mss.denominator)
898+
return _float_sqrt_of_frac(mss.numerator, mss.denominator)
899899

900900

901901
def pstdev(data, mu=None):
@@ -915,8 +915,8 @@ def pstdev(data, mu=None):
915915
T, ss = _ss(data, mu)
916916
mss = ss / n
917917
if issubclass(T, Decimal):
918-
return _deci_sqrt(mss.numerator, mss.denominator)
919-
return _sqrt_frac(mss.numerator, mss.denominator)
918+
return _decimal_sqrt_of_frac(mss.numerator, mss.denominator)
919+
return _float_sqrt_of_frac(mss.numerator, mss.denominator)
920920

921921

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

Lib/test/test_statistics.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,7 @@ def test_isqrt_frac_rto(self):
21772177
self.assertTrue(m * (r - 1)**2 < n < m * (r + 1)**2)
21782178

21792179
@requires_IEEE_754
2180-
def test_sqrt_frac(self):
2180+
def test_float_sqrt_of_frac(self):
21812181

21822182
def is_root_correctly_rounded(x: Fraction, root: float) -> bool:
21832183
if not x:
@@ -2204,24 +2204,24 @@ def is_root_correctly_rounded(x: Fraction, root: float) -> bool:
22042204
denonimator: int = randrange(10 ** randrange(50)) + 1
22052205
with self.subTest(numerator=numerator, denonimator=denonimator):
22062206
x: Fraction = Fraction(numerator, denonimator)
2207-
root: float = statistics._sqrt_frac(numerator, denonimator)
2207+
root: float = statistics._float_sqrt_of_frac(numerator, denonimator)
22082208
self.assertTrue(is_root_correctly_rounded(x, root))
22092209

22102210
# Verify that corner cases and error handling match math.sqrt()
2211-
self.assertEqual(statistics._sqrt_frac(0, 1), 0.0)
2211+
self.assertEqual(statistics._float_sqrt_of_frac(0, 1), 0.0)
22122212
with self.assertRaises(ValueError):
2213-
statistics._sqrt_frac(-1, 1)
2213+
statistics._float_sqrt_of_frac(-1, 1)
22142214
with self.assertRaises(ValueError):
2215-
statistics._sqrt_frac(1, -1)
2215+
statistics._float_sqrt_of_frac(1, -1)
22162216

22172217
# Error handling for zero denominator matches that for Fraction(1, 0)
22182218
with self.assertRaises(ZeroDivisionError):
2219-
statistics._sqrt_frac(1, 0)
2219+
statistics._float_sqrt_of_frac(1, 0)
22202220

22212221
# The result is well defined if both inputs are negative
2222-
self.assertEqual(statistics._sqrt_frac(-2, -1), statistics._sqrt_frac(2, 1))
2222+
self.assertEqual(statistics._float_sqrt_of_frac(-2, -1), statistics._float_sqrt_of_frac(2, 1))
22232223

2224-
def test_deci_sqrt(self):
2224+
def test_decimal_sqrt_of_frac(self):
22252225
root: Decimal
22262226
numerator: int
22272227
denominator: int
@@ -2232,7 +2232,7 @@ def test_deci_sqrt(self):
22322232
(Decimal('0.8500554152289934068192208727'), 722594208960136395984391238251, 1000000000000000000000000000000), # Adj down
22332233
]:
22342234
with decimal.localcontext(decimal.DefaultContext):
2235-
self.assertEqual(statistics._deci_sqrt(numerator, denominator), root)
2235+
self.assertEqual(statistics._decimal_sqrt_of_frac(numerator, denominator), root)
22362236

22372237
# Confirm expected root with a quad precision decimal computation
22382238
with decimal.localcontext(decimal.DefaultContext) as ctx:
@@ -2243,18 +2243,18 @@ def test_deci_sqrt(self):
22432243
self.assertEqual(root, target_root)
22442244

22452245
# Verify that corner cases and error handling match Decimal.sqrt()
2246-
self.assertEqual(statistics._deci_sqrt(0, 1), 0.0)
2246+
self.assertEqual(statistics._decimal_sqrt_of_frac(0, 1), 0.0)
22472247
with self.assertRaises(decimal.InvalidOperation):
2248-
statistics._deci_sqrt(-1, 1)
2248+
statistics._decimal_sqrt_of_frac(-1, 1)
22492249
with self.assertRaises(decimal.InvalidOperation):
2250-
statistics._deci_sqrt(1, -1)
2250+
statistics._decimal_sqrt_of_frac(1, -1)
22512251

22522252
# Error handling for zero denominator matches that for Fraction(1, 0)
22532253
with self.assertRaises(ZeroDivisionError):
2254-
statistics._deci_sqrt(1, 0)
2254+
statistics._decimal_sqrt_of_frac(1, 0)
22552255

22562256
# The result is well defined if both inputs are negative
2257-
self.assertEqual(statistics._deci_sqrt(-2, -1), statistics._deci_sqrt(2, 1))
2257+
self.assertEqual(statistics._decimal_sqrt_of_frac(-2, -1), statistics._decimal_sqrt_of_frac(2, 1))
22582258

22592259

22602260
class TestStdev(VarianceStdevMixin, NumericTestCase):

0 commit comments

Comments
 (0)