Mark Dickinson added the comment:
> Presumably this relates to the fact that nan != nan.
Yep. What you're seeing is pretty much expected behaviour, and it matches how
NaNs behave with respect to containment in other Python contexts:
>>> x = float('nan')
>>> y = float('nan')
>>> s = {x}
>>> x in s
True
>>> y in s
False
There's a much-discussed compromise between object model sanity and respect for
IEEE 754 here. You can find the discussions on the mailing lists, but the
summary is that this isn't going to change in a hurry.
One way you can work around this is to make sure you only have single NaN
object (possibly referenced multiple times) in your list. Then you get the
behaviour that you're looking for:
>>> nan = float('nan')
>>> a = [1, 1, 2, nan, nan, nan]
>>> collections.Counter(a)
Counter({nan: 3, 1: 2, 2: 1})
By the way, when you say 'array of floats', do you mean a NumPy ndarray, a
standard library array.array object, or a plain Python list? The example you
show is a list containing a mixture of ints and strings.
I suggest closing this as 'wont fix'. Raymond?
----------
nosy: +mark.dickinson, rhettinger
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue19161>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com