Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
4a7668ad
Kaydet (Commit)
4a7668ad
authored
Şub 08, 2014
tarafından
Nick Coghlan
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Close #20536: correctly handle Decimal exponents in statistics
üst
f45e3e34
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
1 deletion
+46
-1
statistics.py
Lib/statistics.py
+5
-1
test_statistics.py
Lib/test/test_statistics.py
+38
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/statistics.py
Dosyayı görüntüle @
4a7668ad
...
...
@@ -243,9 +243,13 @@ def _decimal_to_ratio(d):
num
=
0
for
digit
in
digits
:
num
=
num
*
10
+
digit
if
exp
<
0
:
den
=
10
**-
exp
else
:
num
*=
10
**
exp
den
=
1
if
sign
:
num
=
-
num
den
=
10
**-
exp
return
(
num
,
den
)
...
...
Lib/test/test_statistics.py
Dosyayı görüntüle @
4a7668ad
...
...
@@ -686,6 +686,38 @@ class DecimalToRatioTest(unittest.TestCase):
for
d
in
(
Decimal
(
'NAN'
),
Decimal
(
'sNAN'
),
Decimal
(
'INF'
)):
self
.
assertRaises
(
ValueError
,
statistics
.
_decimal_to_ratio
,
d
)
def
test_sign
(
self
):
# Test sign is calculated correctly.
numbers
=
[
Decimal
(
"9.8765e12"
),
Decimal
(
"9.8765e-12"
)]
for
d
in
numbers
:
# First test positive decimals.
assert
d
>
0
num
,
den
=
statistics
.
_decimal_to_ratio
(
d
)
self
.
assertGreaterEqual
(
num
,
0
)
self
.
assertGreater
(
den
,
0
)
# Then test negative decimals.
num
,
den
=
statistics
.
_decimal_to_ratio
(
-
d
)
self
.
assertLessEqual
(
num
,
0
)
self
.
assertGreater
(
den
,
0
)
def
test_negative_exponent
(
self
):
# Test result when the exponent is negative.
t
=
statistics
.
_decimal_to_ratio
(
Decimal
(
"0.1234"
))
self
.
assertEqual
(
t
,
(
1234
,
10000
))
def
test_positive_exponent
(
self
):
# Test results when the exponent is positive.
t
=
statistics
.
_decimal_to_ratio
(
Decimal
(
"1.234e7"
))
self
.
assertEqual
(
t
,
(
12340000
,
1
))
def
test_regression_20536
(
self
):
# Regression test for issue 20536.
# See http://bugs.python.org/issue20536
t
=
statistics
.
_decimal_to_ratio
(
Decimal
(
"1e2"
))
self
.
assertEqual
(
t
,
(
100
,
1
))
t
=
statistics
.
_decimal_to_ratio
(
Decimal
(
"1.47e5"
))
self
.
assertEqual
(
t
,
(
147000
,
1
))
class
CheckTypeTest
(
unittest
.
TestCase
):
# Test _check_type private function.
...
...
@@ -1074,6 +1106,12 @@ class TestMean(NumericTestCase, AverageMixin, UnivariateTypeMixin):
actual
=
self
.
func
(
data
*
2
)
self
.
assertApproxEqual
(
actual
,
expected
)
def
test_regression_20561
(
self
):
# Regression test for issue 20561.
# See http://bugs.python.org/issue20561
d
=
Decimal
(
'1e4'
)
self
.
assertEqual
(
statistics
.
mean
([
d
]),
d
)
class
TestMedian
(
NumericTestCase
,
AverageMixin
):
# Common tests for median and all median.* functions.
...
...
Misc/NEWS
Dosyayı görüntüle @
4a7668ad
...
...
@@ -27,6 +27,9 @@ Core and Builtins
Library
-------
- Issue #20536: the statistics module now correctly handle Decimal instances
with positive exponents
- Issue #18805: the netmask/hostmask parsing in ipaddress now more reliably
filters out illegal values and correctly allows any valid prefix length.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment