Skip to content

Commit 6e77c81

Browse files
committed
Speed up util.is_nan for float values
1 parent c7c4c94 commit 6e77c81

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pandas/_libs/tslibs/util.pxd

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ cdef extern from "Python.h":
3333
const char* PyUnicode_AsUTF8AndSize(object obj,
3434
Py_ssize_t* length) except NULL
3535

36-
from numpy cimport int64_t
36+
from numpy cimport int64_t, float64_t
3737

3838
cdef extern from "numpy/arrayobject.h":
3939
PyTypeObject PyFloatingArrType_Type
@@ -215,7 +215,11 @@ cdef inline bint is_nan(object val):
215215
-------
216216
is_nan : bool
217217
"""
218-
return (is_float_object(val) or is_complex_object(val)) and val != val
218+
cdef float64_t fval
219+
if is_float_object(val):
220+
fval = val
221+
return fval != fval
222+
return is_complex_object(val) and val != val
219223

220224

221225
cdef inline const char* get_c_string_buf_and_size(object py_string,

0 commit comments

Comments
 (0)