[Python-ideas] statistics.sum [was Re: Pre-PEP: adding a statistics module to Python]

Alexander Belopolsky alexander.belopolsky at gmail.com
Mon Aug 5 22:34:28 CEST 2013


On Mon, Aug 5, 2013 at 4:04 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>
> * For backward compatibility, I don't think we can change the existing sum
> functions. E.g.:
>
>   - built-in sum accepts non-numeric values if they support
>     the + operator, that won't change before Python 4000;
>

I don't see this as a problem.  To the contrary, I find designs that
deliberately inhibit duck-typing to be "unpythonic."


>   - built-in sum can be inaccurate with floats;
>

This can be fixed.  The implementation already special-cases floats.


>
>   - math.fsum coerces everything to float.
>

And does not support the start argument.  Note that this was a deliberate
choice:

/*
   Note 5: The signature of math.fsum() differs from __builtin__.sum()
   because the start argument doesn't make sense in the context of
   accurate summation.  Since the partials table is collapsed before
   returning a result, sum(seq2, start=sum(seq1)) may not equal the
   accurate result returned by sum(itertools.chain(seq1, seq2)).
*/ See <
http://hg.python.org/cpython/file/c6d4564dc86f/Modules/mathmodule.c#l993>.



>
> * Even if we could change one of the existing sum functions (math.fsum is
> probably the better candidate) I personally don't know enough C to do so.
> Either somebody else steps up and volunteers, or any such change is
> deferred indefinitely.
>

I'll be happy to help with coding once the specs are agreed upon.


> Show of hands please, +1 or -1 on statistics.sum.
>

-1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130805/44ba6c89/attachment-0001.html>


More information about the Python-ideas mailing list