Skip to content

Commit f41dd55

Browse files
vnlitvinovanmyachev
authored andcommitted
Speed up util.is_nan for float values (pandas-dev#25946)
1 parent 57860a8 commit f41dd55

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
@@ -235,7 +235,11 @@ cdef inline bint is_nan(object val):
235235
-------
236236
is_nan : bool
237237
"""
238-
return (is_float_object(val) or is_complex_object(val)) and val != val
238+
cdef float64_t fval
239+
if is_float_object(val):
240+
fval = val
241+
return fval != fval
242+
return is_complex_object(val) and val != val
239243

240244

241245
cdef inline const char* get_c_string_buf_and_size(object py_string,

0 commit comments

Comments
 (0)