File tree Expand file tree Collapse file tree 1 file changed +31
-3
lines changed Expand file tree Collapse file tree 1 file changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -242,12 +242,40 @@ int PANDAS_INLINE pyobject_cmp(PyObject* a, PyObject* b) {
242
242
}
243
243
244
244
245
+ Py_hash_t PANDAS_INLINE _Pandas_HashDouble (double val ){
246
+ //Since Python3.10, nan is no longer has hash 0
247
+ if (Py_IS_NAN (val )) {
248
+ return 0 ;
249
+ }
250
+ #if PY_VERSION_HEX < 0x030A0000
251
+ return _Py_HashDouble (val );
252
+ #else
253
+ return _Py_HashDouble (NULL , val );
254
+ #endif
255
+ }
256
+
257
+
258
+ Py_hash_t PANDAS_INLINE hash_float (PyFloatObject * key ){
259
+ return _Pandas_HashDouble (PyFloat_AS_DOUBLE (key ));
260
+ }
261
+
262
+
245
263
khint32_t PANDAS_INLINE kh_python_hash_func (PyObject * key ){
264
+ Py_hash_t hash ;
246
265
// For PyObject_Hash holds:
247
266
// hash(0.0) == 0 == hash(-0.0)
248
- // hash(X) == 0 if X is a NaN-value
249
- // so it is OK to use it directly for doubles
250
- Py_hash_t hash = PyObject_Hash (key );
267
+ // yet for different nan-object different hash-values
268
+ // are possible
269
+ if (PyFloat_CheckExact (key )) {
270
+ // we cannot use kh_float64_hash_func
271
+ // becase float(k) == k holds for any int-object k
272
+ // and kh_float64_hash_func doesn't respect it
273
+ hash = hash_float ((PyFloatObject * )key );
274
+ }
275
+ else {
276
+ hash = PyObject_Hash (key );
277
+ }
278
+
251
279
if (hash == -1 ) {
252
280
PyErr_Clear ();
253
281
return 0 ;
You can’t perform that action at this time.
0 commit comments