This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author skrah
Recipients skrah, steven.daprano
Date 2014-02-06.23:42:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1391730139.77.0.406178455931.issue20536@psf.upfronthosting.co.za>
In-reply-to
Content
As I understand, _decimal_to_ratio() should always produce an
integer ratio.  But it does not for positive exponents:

>>> import statistics
>>> statistics.mean([Decimal("100"), Decimal("200")])
Decimal('150')
>>> statistics.mean([Decimal("1e2"), Decimal("2e2")])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/statistics.py", line 308, in mean
    return _sum(data)/n
  File "/usr/local/lib/python3.4/statistics.py", line 166, in _sum
    total += Fraction(n, d)
  File "/usr/local/lib/python3.4/fractions.py", line 163, in __new__
    raise TypeError("both arguments should be "
TypeError: both arguments should be Rational instances
>>> 
>>> statistics._decimal_to_ratio(Decimal("1e2"))     
(1, 0.01)
>>> 1e2.as_integer_ratio()
(100, 1)
History
Date User Action Args
2014-02-06 23:42:19skrahsetrecipients: + skrah, steven.daprano
2014-02-06 23:42:19skrahsetmessageid: <1391730139.77.0.406178455931.issue20536@psf.upfronthosting.co.za>
2014-02-06 23:42:19skrahlinkissue20536 messages
2014-02-06 23:42:19skrahcreate