Hashing performance (was "hahsing yields inconsistent results")
Created originally on Bitbucket by oscardssmith
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).