Skip to content

Commit

Permalink
CLN: use isnan() instead of the Py_IS_NAN macro (#58850)
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev authored May 30, 2024
1 parent b162331 commit a564662
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pandas/_libs/include/pandas/vendored/klib/khash_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,20 @@ KHASH_MAP_INIT_COMPLEX128(complex128, size_t)

// NaN-floats should be in the same equivalency class, see GH 22119
static inline int floatobject_cmp(PyFloatObject *a, PyFloatObject *b) {
return (Py_IS_NAN(PyFloat_AS_DOUBLE(a)) && Py_IS_NAN(PyFloat_AS_DOUBLE(b))) ||
return (isnan(PyFloat_AS_DOUBLE(a)) && isnan(PyFloat_AS_DOUBLE(b))) ||
(PyFloat_AS_DOUBLE(a) == PyFloat_AS_DOUBLE(b));
}

// NaNs should be in the same equivalency class, see GH 41836
// PyObject_RichCompareBool for complexobjects has a different behavior
// needs to be replaced
static inline int complexobject_cmp(PyComplexObject *a, PyComplexObject *b) {
return (Py_IS_NAN(a->cval.real) && Py_IS_NAN(b->cval.real) &&
Py_IS_NAN(a->cval.imag) && Py_IS_NAN(b->cval.imag)) ||
(Py_IS_NAN(a->cval.real) && Py_IS_NAN(b->cval.real) &&
return (isnan(a->cval.real) && isnan(b->cval.real) && isnan(a->cval.imag) &&
isnan(b->cval.imag)) ||
(isnan(a->cval.real) && isnan(b->cval.real) &&
a->cval.imag == b->cval.imag) ||
(a->cval.real == b->cval.real && Py_IS_NAN(a->cval.imag) &&
Py_IS_NAN(b->cval.imag)) ||
(a->cval.real == b->cval.real && isnan(a->cval.imag) &&
isnan(b->cval.imag)) ||
(a->cval.real == b->cval.real && a->cval.imag == b->cval.imag);
}

Expand Down Expand Up @@ -223,7 +223,7 @@ static inline int pyobject_cmp(PyObject *a, PyObject *b) {

static inline Py_hash_t _Pandas_HashDouble(double val) {
// Since Python3.10, nan is no longer has hash 0
if (Py_IS_NAN(val)) {
if (isnan(val)) {
return 0;
}
#if PY_VERSION_HEX < 0x030A0000
Expand Down

0 comments on commit a564662

Please sign in to comment.