[pypy-issue] Issue #2346: Hashing yields inconsistent results. (pypy/pypy)

oscardssmith issues-reply at bitbucket.org
Tue Jul 19 22:29:04 EDT 2016

New issue 2346: Hashing yields inconsistent results.


As you probably no, CPython hashes ints such that hash(i) = i for almost all ints. The only exception to this is that hash(-1) = -2 as a hash value of -1 is used to indicate problems in the hash table.

Currently hash(-1) = -1 on pypy2, (on pypy3 the expected behavior is observed). This would not be a problem, except that hash(np.int8(-1)) = -2 as CPython expects (note this is also true for np.int16, and np.int32 but **not** np.int64/np.int. This yields unexpected behavior when comparing keys of different integer types.

Either hash(-1) should return -1 for all types (likely faster) or hash(-1) returns -2 (more fully compatible with CPython, saves users who assume hash(-1) == -2 (stupid, but you never know).

More information about the pypy-issue mailing list