[Python-ideas] Support floating-point values in collections.Counter
fiskomaten at gmail.com
Tue Dec 19 04:20:13 EST 2017
On Tue, Dec 19, 2017 at 12:51 AM, Joel Croteau <jcroteau at gmail.com> wrote:
> It would be useful in many scenarios for values in collections.Counter to be
> allowed to be floating point. I know that Counter nominally emulates a
> multiset, which would suggest only integer values, but in a more general
> sense, it could be an accumulator of either floating point or integer data.
> As near as I can tell, Collection already does support float values in both
> Python 2.7 and 3.6, and the way the code is implemented, this change should
> be a no-op. All that is required is to update the documentation to say
> floating-point values are allowed, as it currently says only integers are
How should the `elements` method work?
Currently it raises
TypeError: integer argument expected, got float
At least it should be documented that the method only works when all
counts are integers.
The error message could also state exactly what key it failed on.
More information about the Python-ideas