@@ -255,11 +255,26 @@ Py_hash_t PANDAS_INLINE _Pandas_HashDouble(double val){
255
255
}
256
256
257
257
258
- Py_hash_t PANDAS_INLINE hash_float (PyFloatObject * key ){
258
+ Py_hash_t PANDAS_INLINE floatobject_hash (PyFloatObject * key ){
259
259
return _Pandas_HashDouble (PyFloat_AS_DOUBLE (key ));
260
260
}
261
261
262
262
263
+ // replaces _Py_HashDouble with _Pandas_HashDouble
264
+ Py_hash_t PANDAS_INLINE complexobject_hash (PyComplexObject * key ){
265
+ Py_uhash_t realhash = (Py_uhash_t )_Pandas_HashDouble (key -> cval .real );
266
+ Py_uhash_t imaghash = (Py_uhash_t )_Pandas_HashDouble (key -> cval .imag );
267
+ if (realhash == (Py_uhash_t )- 1 || imaghash == (Py_uhash_t )- 1 ) {
268
+ return -1 ;
269
+ }
270
+ Py_uhash_t combined = realhash + _PyHASH_IMAG * imaghash ;
271
+ if (combined == (Py_uhash_t )- 1 ) {
272
+ return -2 ;
273
+ }
274
+ return (Py_hash_t )combined ;
275
+ }
276
+
277
+
263
278
khint32_t PANDAS_INLINE kh_python_hash_func (PyObject * key ){
264
279
Py_hash_t hash ;
265
280
// For PyObject_Hash holds:
@@ -270,7 +285,13 @@ khint32_t PANDAS_INLINE kh_python_hash_func(PyObject* key){
270
285
// we cannot use kh_float64_hash_func
271
286
// becase float(k) == k holds for any int-object k
272
287
// and kh_float64_hash_func doesn't respect it
273
- hash = hash_float ((PyFloatObject * )key );
288
+ hash = floatobject_hash ((PyFloatObject * )key );
289
+ }
290
+ else if (PyComplex_CheckExact (key )) {
291
+ // we cannot use kh_complex128_hash_func
292
+ // becase complex(k,0) == k holds for any int-object k
293
+ // and kh_complex128_hash_func doesn't respect it
294
+ hash = complexobject_hash ((PyComplexObject * )key );
274
295
}
275
296
else {
276
297
hash = PyObject_Hash (key );
0 commit comments