While writing some program involving numpy, I found that membership test doesn't work as expected for numpy dtype objects. Specifically, the result is unexpected for set
, but not list
or tuple
.
import numpy as np
x = np.arange(5).dtype
y = np.int64
print(x in {y}, x in (y,), x in [y])
the result is False True True
.
found this in both Python 2.7 and 3.6, with numpy 1.12.x installed.
Any idea why?
UPDATE
looks that dtype objects don't respect some assumptions about hashing in Python.
http://www.asmeurer.com/blog/posts/what-happens-when-you-mess-with-hashing-in-python/
and https://github.com/numpy/numpy/issues/5345
Thanks @ser2357112 and @Fabien