[issue40764] Conflation of Counter with Multiset

2020-05-25 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

For the most part, Counter() works fine with negative counts.  The update() and 
subtract() methods were specifically designed to work with negative values.  
Nothing prevents use cases with negative counts.

In addition, there are some methods like elements() that only make sense with 
positive counts.  So if your use case has negative counts, then these methods 
methods wouldn't be applicable.

Should the Counter() have been two different classes?  Maybe yes, maybe no.  
But that ship sailed a long time ago.  For now, it is what it is and wouldn't 
be easy to change without breaking a lot of code.

>From the outset, the central concept of Counter() is that it is a dictionary 
>that returns zero when a value is missing.  Pretty much everything else is a 
>set of convenience methods supporting all the different ways people aspire to 
>use it (multisets, bags, counters, sparse arrays, etc).  People needing 
>multiset methods use the multiset methods.  People want negative counts use 
>the other methods.

Am marking this a closed.  There isn't much that can be changed here.  Also, 
theoretical objections aside, what we have now seems to be working well enough 
for most people most of the time.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40764] Conflation of Counter with Multiset

2020-05-25 Thread Dong-hee Na


Change by Dong-hee Na :


--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40764] Conflation of Counter with Multiset

2020-05-25 Thread Paul


New submission from Paul :

The collections docs state: "Several mathematical operations are provided for 
combining Counter objects to produce multisets (counters that have counts 
greater than zero)."

I am surprised at the clear level of decision into conflating counters with 
multisets. Why break all functionality for negative counts in favour of 
multisets? Why not create a Multiset object for multisets?

One example use of negative counts is in factorisation 
(https://bugs.python.org/msg368298 will be surprised counters don't count)
18   = 2**1 * 3**2  --> x18 = Counter({2: 1, 3: 2})
 4   = 2**2 --> x4 = Counter({2: 2})

To compute 18/4 in this representation (which I believe is exactly precisely a 
count), one would expect

18/4 = 2**-1 * 3**2 --> x4_5 = x18 - x4 = Counter({2: -1, 3: 2})

But instead,

x18 - x4 = Counter({3: 2}) = 9 ???

This is just an example. The use case for negative counts is plain and obvious. 
The question is: why does collections break counter behaviour in favour of 
conflation with multisets? Why not have two objects: Counter for counters and 
Multiset for multisets?

--
components: Library (Lib)
messages: 369867
nosy: wpk-
priority: normal
severity: normal
status: open
title: Conflation of Counter with Multiset
type: behavior
versions: Python 3.10, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com