Skip to content

Commit 7d6d609

Browse files
authored
CLN: remove is_null_datetimelike (#44540)
1 parent 9ea3b12 commit 7d6d609

File tree

8 files changed

+16
-81
lines changed

8 files changed

+16
-81
lines changed

pandas/_libs/lib.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
14621462
for i in range(n):
14631463
val = values[i]
14641464

1465-
# do not use is_null_datetimelike to keep
1465+
# do not use checknull to keep
14661466
# np.datetime64('nat') and np.timedelta64('nat')
14671467
if val is None or util.is_nan(val):
14681468
pass

pandas/_libs/missing.pyx

+14-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ from pandas._libs.tslibs.nattype cimport (
2121
c_NaT as NaT,
2222
checknull_with_nat,
2323
is_dt64nat,
24-
is_null_datetimelike,
2524
is_td64nat,
2625
)
2726
from pandas._libs.tslibs.np_datetime cimport (
@@ -121,11 +120,20 @@ cpdef bint checknull(object val, bint inf_as_na=False):
121120
-------
122121
bool
123122
"""
124-
return (
125-
val is C_NA
126-
or is_null_datetimelike(val, inat_is_null=False, inf_as_na=inf_as_na)
127-
or is_decimal_na(val)
128-
)
123+
if val is None or val is NaT or val is C_NA:
124+
return True
125+
elif util.is_float_object(val) or util.is_complex_object(val):
126+
if val != val:
127+
return True
128+
elif inf_as_na:
129+
return val == INF or val == NEGINF
130+
return False
131+
elif util.is_timedelta64_object(val):
132+
return get_timedelta64_value(val) == NPY_NAT
133+
elif util.is_datetime64_object(val):
134+
return get_datetime64_value(val) == NPY_NAT
135+
else:
136+
return is_decimal_na(val)
129137

130138

131139
cdef inline bint is_decimal_na(object val):

pandas/_libs/tslibs/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"NaTType",
66
"iNaT",
77
"nat_strings",
8-
"is_null_datetimelike",
98
"OutOfBoundsDatetime",
109
"OutOfBoundsTimedelta",
1110
"IncompatibleFrequency",
@@ -37,7 +36,6 @@
3736
NaT,
3837
NaTType,
3938
iNaT,
40-
is_null_datetimelike,
4139
nat_strings,
4240
)
4341
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime

pandas/_libs/tslibs/nattype.pxd

-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ cdef _NaT c_NaT
1818
cdef bint checknull_with_nat(object val)
1919
cdef bint is_dt64nat(object val)
2020
cdef bint is_td64nat(object val)
21-
cpdef bint is_null_datetimelike(object val, bint inat_is_null=*, bint inf_as_na=*)

pandas/_libs/tslibs/nattype.pyi

-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ NaT: NaTType
1212
iNaT: int
1313
nat_strings: set[str]
1414

15-
def is_null_datetimelike(
16-
val: object, inat_is_null: bool = ..., inf_as_na: bool = ...
17-
) -> bool: ...
18-
1915
class NaTType(datetime):
2016
value: np.int64
2117
def asm8(self) -> np.datetime64: ...

pandas/_libs/tslibs/nattype.pyx

-42
Original file line numberDiff line numberDiff line change
@@ -1218,45 +1218,3 @@ cdef inline bint is_td64nat(object val):
12181218
if util.is_timedelta64_object(val):
12191219
return get_timedelta64_value(val) == NPY_NAT
12201220
return False
1221-
1222-
1223-
cdef:
1224-
cnp.float64_t INF = <cnp.float64_t>np.inf
1225-
cnp.float64_t NEGINF = -INF
1226-
1227-
1228-
cpdef bint is_null_datetimelike(
1229-
object val, bint inat_is_null=True, bint inf_as_na=False
1230-
):
1231-
"""
1232-
Determine if we have a null for a timedelta/datetime (or integer versions).
1233-
1234-
Parameters
1235-
----------
1236-
val : object
1237-
inat_is_null : bool, default True
1238-
Whether to treat integer iNaT value as null
1239-
inf_as_na : bool, default False
1240-
Whether to treat INF or -INF value as null.
1241-
1242-
Returns
1243-
-------
1244-
bool
1245-
"""
1246-
if val is None:
1247-
return True
1248-
elif val is c_NaT:
1249-
return True
1250-
elif util.is_float_object(val) or util.is_complex_object(val):
1251-
if val != val:
1252-
return True
1253-
if inf_as_na:
1254-
return val == INF or val == NEGINF
1255-
return False
1256-
elif util.is_timedelta64_object(val):
1257-
return get_timedelta64_value(val) == NPY_NAT
1258-
elif util.is_datetime64_object(val):
1259-
return get_datetime64_value(val) == NPY_NAT
1260-
elif inat_is_null and util.is_integer_object(val):
1261-
return val == NPY_NAT
1262-
return False

pandas/tests/dtypes/test_missing.py

+1-24
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
from pandas._config import config as cf
99

1010
from pandas._libs import missing as libmissing
11-
from pandas._libs.tslibs import (
12-
iNaT,
13-
is_null_datetimelike,
14-
)
11+
from pandas._libs.tslibs import iNaT
1512

1613
from pandas.core.dtypes.common import (
1714
is_float,
@@ -687,26 +684,6 @@ def test_checknull_old(self):
687684
for value in never_na_vals:
688685
assert not libmissing.checknull_old(value)
689686

690-
def test_is_null_datetimelike(self):
691-
for value in na_vals:
692-
assert is_null_datetimelike(value)
693-
assert is_null_datetimelike(value, False)
694-
695-
for value in inf_vals:
696-
assert not is_null_datetimelike(value)
697-
assert not is_null_datetimelike(value, False)
698-
699-
for value in int_na_vals:
700-
assert is_null_datetimelike(value)
701-
assert not is_null_datetimelike(value, False)
702-
703-
for value in sometimes_na_vals:
704-
assert not is_null_datetimelike(value)
705-
assert not is_null_datetimelike(value, False)
706-
707-
for value in never_na_vals:
708-
assert not is_null_datetimelike(value)
709-
710687
def test_is_matching_na(self, nulls_fixture, nulls_fixture2):
711688
left = nulls_fixture
712689
right = nulls_fixture2

pandas/tests/tslibs/test_api.py

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def test_namespace():
2929
"NaT",
3030
"NaTType",
3131
"iNaT",
32-
"is_null_datetimelike",
3332
"nat_strings",
3433
"OutOfBoundsDatetime",
3534
"OutOfBoundsTimedelta",

0 commit comments

Comments
 (0)