From 6e77c81fa7eb229598a2d2ed3862392b380d9b0a Mon Sep 17 00:00:00 2001 From: Vasily Litvinov Date: Mon, 1 Apr 2019 13:46:23 -0500 Subject: [PATCH] Speed up util.is_nan for float values --- pandas/_libs/tslibs/util.pxd | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/util.pxd b/pandas/_libs/tslibs/util.pxd index 74e9db6fa7598..dc32dcd5e0b21 100644 --- a/pandas/_libs/tslibs/util.pxd +++ b/pandas/_libs/tslibs/util.pxd @@ -33,7 +33,7 @@ cdef extern from "Python.h": const char* PyUnicode_AsUTF8AndSize(object obj, Py_ssize_t* length) except NULL -from numpy cimport int64_t +from numpy cimport int64_t, float64_t cdef extern from "numpy/arrayobject.h": PyTypeObject PyFloatingArrType_Type @@ -215,7 +215,11 @@ cdef inline bint is_nan(object val): ------- is_nan : bool """ - return (is_float_object(val) or is_complex_object(val)) and val != val + cdef float64_t fval + if is_float_object(val): + fval = val + return fval != fval + return is_complex_object(val) and val != val cdef inline const char* get_c_string_buf_and_size(object py_string,