Skip to content

Commit 848fcad

Browse files
committed
Speed up checknull_with_nat for double NaN
1 parent c7c4c94 commit 848fcad

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pandas/_libs/tslibs/nattype.pyx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
from cpython cimport (
4+
PyFloat_Check, PyFloat_AS_DOUBLE, PyComplex_Check,
45
PyObject_RichCompare,
56
Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE)
67

@@ -713,7 +714,14 @@ NaT = c_NaT # Python-visible
713714

714715
cdef inline bint checknull_with_nat(object val):
715716
""" utility to check if a value is a nat or not """
716-
return val is None or util.is_nan(val) or val is c_NaT
717+
cdef:
718+
double dval
719+
if val is None or val is c_NaT:
720+
return True
721+
if PyFloat_Check(val):
722+
dval = val
723+
return dval != dval
724+
return util.is_nan(val)
717725

718726

719727
cpdef bint is_null_datetimelike(object val, bint inat_is_null=True):

0 commit comments

Comments
 (0)