@@ -12,33 +12,16 @@ cimport pandas._libs.util as util
1212
1313from pandas._libs.tslibs.np_datetime cimport (
1414 get_timedelta64_value, get_datetime64_value)
15- from pandas._libs.tslibs.nattype cimport checknull_with_nat, c_NaT
15+ from pandas._libs.tslibs.nattype cimport (
16+ checknull_with_nat, c_NaT as NaT, is_null_datetimelike)
17+
1618
1719cdef float64_t INF = < float64_t> np.inf
1820cdef float64_t NEGINF = - INF
1921
2022cdef int64_t NPY_NAT = util.get_nat()
2123
2224
23- cdef inline bint _check_all_nulls(object val):
24- """ utility to check if a value is any type of null """
25- res: bint
26-
27- if isinstance (val, (float , complex )):
28- res = val != val
29- elif val is c_NaT:
30- res = 1
31- elif val is None :
32- res = 1
33- elif util.is_datetime64_object(val):
34- res = get_datetime64_value(val) == NPY_NAT
35- elif util.is_timedelta64_object(val):
36- res = get_timedelta64_value(val) == NPY_NAT
37- else :
38- res = 0
39- return res
40-
41-
4225cpdef bint checknull(object val):
4326 """
4427 Return boolean describing of the input is NA-like, defined here as any
@@ -62,18 +45,7 @@ cpdef bint checknull(object val):
6245 The difference between `checknull` and `checknull_old` is that `checknull`
6346 does *not* consider INF or NEGINF to be NA.
6447 """
65- if util.is_float_object(val) or util.is_complex_object(val):
66- return val != val # and val != INF and val != NEGINF
67- elif util.is_datetime64_object(val):
68- return get_datetime64_value(val) == NPY_NAT
69- elif val is c_NaT:
70- return True
71- elif util.is_timedelta64_object(val):
72- return get_timedelta64_value(val) == NPY_NAT
73- elif util.is_array(val):
74- return False
75- else :
76- return val is None or util.is_nan(val)
48+ return is_null_datetimelike(val, inat_is_null = False )
7749
7850
7951cpdef bint checknull_old(object val):
@@ -101,18 +73,11 @@ cpdef bint checknull_old(object val):
10173 The difference between `checknull` and `checknull_old` is that `checknull`
10274 does *not* consider INF or NEGINF to be NA.
10375 """
104- if util.is_float_object(val) or util.is_complex_object(val):
105- return val != val or val == INF or val == NEGINF
106- elif util.is_datetime64_object(val):
107- return get_datetime64_value(val) == NPY_NAT
108- elif val is c_NaT:
76+ if checknull(val):
10977 return True
110- elif util.is_timedelta64_object(val):
111- return get_timedelta64_value(val) == NPY_NAT
112- elif util.is_array(val):
113- return False
114- else :
115- return val is None or util.is_nan(val)
78+ elif util.is_float_object(val) or util.is_complex_object(val):
79+ return val == INF or val == NEGINF
80+ return False
11681
11782
11883cdef inline bint _check_none_nan_inf_neginf(object val):
@@ -128,7 +93,7 @@ cdef inline bint _check_none_nan_inf_neginf(object val):
12893cpdef ndarray[uint8_t] isnaobj(ndarray arr):
12994 """
13095 Return boolean mask denoting which elements of a 1-D array are na-like,
131- according to the criteria defined in `_check_all_nulls `:
96+ according to the criteria defined in `checknull `:
13297 - None
13398 - nan
13499 - NaT
@@ -154,7 +119,7 @@ cpdef ndarray[uint8_t] isnaobj(ndarray arr):
154119 result = np.empty(n, dtype = np.uint8)
155120 for i in range (n):
156121 val = arr[i]
157- result[i] = _check_all_nulls (val)
122+ result[i] = checknull (val)
158123 return result.view(np.bool_)
159124
160125
@@ -189,7 +154,7 @@ def isnaobj_old(ndarray arr):
189154 result = np.zeros(n, dtype = np.uint8)
190155 for i in range (n):
191156 val = arr[i]
192- result[i] = val is c_NaT or _check_none_nan_inf_neginf(val)
157+ result[i] = val is NaT or _check_none_nan_inf_neginf(val)
193158 return result.view(np.bool_)
194159
195160
@@ -299,7 +264,7 @@ cdef inline bint is_null_datetime64(v):
299264 if checknull_with_nat(v):
300265 return True
301266 elif util.is_datetime64_object(v):
302- return v.view( ' int64 ' ) == NPY_NAT
267+ return get_datetime64_value(v ) == NPY_NAT
303268 return False
304269
305270
@@ -309,7 +274,7 @@ cdef inline bint is_null_timedelta64(v):
309274 if checknull_with_nat(v):
310275 return True
311276 elif util.is_timedelta64_object(v):
312- return v.view( ' int64 ' ) == NPY_NAT
277+ return get_timedelta64_value(v ) == NPY_NAT
313278 return False
314279
315280
0 commit comments