[Python-ideas] statistics module in Python3.4

Yury Selivanov yselivanov.ml at gmail.com
Thu Jan 30 18:44:50 CET 2014


On 1/27/2014, 12:41 PM, Wolfgang wrote:
[snip]
> As for the first subject:
> Specifically, I am not happy with the way the function handles different
> types. Currently _coerce_types gets called for every element in the
> function's input sequence and type conversion follows quite complicated
> rules, and - what is worst - make the outcome of _sum() and thereby mean()
> dependent on the order of items in the input sequence, e.g.:
>
>>>> mean((1,Fraction(2,3),1.0,Decimal(2.3),2.0, Decimal(5)))
> 1.9944444444444445
>
>>>> mean((1,Fraction(2,3),Decimal(2.3),1.0,2.0, Decimal(5)))
> Traceback (most recent call last):
>    File "<pyshell#7>", line 1, in <module>
>      mean((1,Fraction(2,3),Decimal(2.3),1.0,2.0, Decimal(5)))
>    File "C:\Python33\statistics.py", line 369, in mean
>      return _sum(data)/n
>    File "C:\Python33\statistics.py", line 157, in _sum
>      T = _coerce_types(T, type(x))
>    File "C:\Python33\statistics.py", line 327, in _coerce_types
>      raise TypeError('cannot coerce types %r and %r' % (T1, T2))
> TypeError: cannot coerce types <class 'fractions.Fraction'> and <class
> 'decimal.Decimal'>
FWIW, I find some of the concerns Wolfgang raised quite valid.

Steven, what do you think?

Yury


More information about the Python-ideas mailing list