This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Nikita Smetanin
Recipients Nikita Smetanin, remi.lapeyre, rhettinger, xtreak
Date 2019-03-20.13:28:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1553088482.81.0.356276738978.issue36380@roundup.psfhosted.org>
In-reply-to
Content
@xtreak I agree, also, this behavior is stated in documentation, but it's quite inconsistent in many ways, like in the following examples:
Counter(a=-1) + Counter(a=-2) produces empty Counter() instead of Counter(a=-2) which is unexpected, but 
Counter(a=-1) + Counter(a=2) produces correct result Counter(a=1). The same is with in-place operators.

That makes no sense.

It's clear that in-place addition, for example, isn't a good place to remove negative elements which wasn't involved in this operation at all. The only possible optimization here (if we don't want to change the behavior) is to keep track of positive / non-positive elements in a separate set.

The better solution could be in providing two classes — Counter for any (signed) values with consistent operations and MultisetCounter (e.g.) or specific methods (like .multiset_add) for positive-only values and positive-checks.
History
Date User Action Args
2019-03-20 13:28:02Nikita Smetaninsetrecipients: + Nikita Smetanin, rhettinger, remi.lapeyre, xtreak
2019-03-20 13:28:02Nikita Smetaninsetmessageid: <1553088482.81.0.356276738978.issue36380@roundup.psfhosted.org>
2019-03-20 13:28:02Nikita Smetaninlinkissue36380 messages
2019-03-20 13:28:02Nikita Smetanincreate