[Python-ideas] statistics module in Python3.4

Oscar Benjamin oscar.j.benjamin at gmail.com
Sat Feb 1 21:54:40 CET 2014


On 1 February 2014 20:10, Wolfgang Maier
<wolfgang.maier at biologie.uni-freiburg.de> wrote:
> Greg Ewing <greg.ewing at ...> writes:
>
>>
>> Wolfgang Maier wrote:
>> > Mappings may be an excellent way of specifying frequencies and weights in an
>> > elegant way.
>>
>> That may be, but I think I'd rather have a separate
>> function, or a mode argument, explicitly indicating
>> that this is what you want. Detecting whether something
>> is a mapping in a duck-typed way is dodgy in general.
>>
>
> There should be nothing dodgy about this with the abstract base class Mapping.

I agree with Greg about this. I dislike APIs that try to be too clever
about accepting different types of input. The mode() function is
clearly intended to accept an iterable not a Counter and I consider it
a bug that it does. It can be fixed to treat a Counter as an iterable
by changing the _counts function to do

    collections.Counter(data)

to

    collections.Counter(iter(data))

If you want the option for doing statistics with Counter style data
formats then they should be invoked explicitly as Greg says.


Oscar


More information about the Python-ideas mailing list