Different behaviour for collections of nans from CPython
Created originally on Bitbucket by david_maciver_ (David MacIver)
All of the following asserts pass in cpython (I've tried on 2.7, 3.3 and 3.4) but some of them fail on pypy (I've tried on pypy-2.5.0 and pypy3-2.4.0).
#!python
n1 = float('nan')
n2 = float('nan')
x = [n1]
assert n1 in x
assert n2 not in x
assert x.index(n1) == 0
try:
x.index(n2)
assert False
except ValueError:
pass
Basically, it seems like in cpython collection methods have a shortcut that treats x and y as equal if x is y even if not x == y.
The behaviour for sets is also different. For set like collections CPython treats reference equal nans as equal but other nans as distinct in the same way as the above, but pypy seems to collapse all nans together into one value.
#!python
n1 = float('nan')
n2 = float('nan')
n3 = float('nan')
x = {n1, n2}
assert len(x) == 2
assert n1 in x
assert n2 in x
assert n3 not in x
t = {n1}
assert t == t
assert t == {n1}
assert t != {n2}