Skip to content

CLN: remove is_null_datetimelike #44540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
for i in range(n):
val = values[i]

# do not use is_null_datetimelike to keep
# do not use checknull to keep
# np.datetime64('nat') and np.timedelta64('nat')
if val is None or util.is_nan(val):
pass
Expand Down
20 changes: 14 additions & 6 deletions pandas/_libs/missing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ from pandas._libs.tslibs.nattype cimport (
c_NaT as NaT,
checknull_with_nat,
is_dt64nat,
is_null_datetimelike,
is_td64nat,
)
from pandas._libs.tslibs.np_datetime cimport (
Expand Down Expand Up @@ -121,11 +120,20 @@ cpdef bint checknull(object val, bint inf_as_na=False):
-------
bool
"""
return (
val is C_NA
or is_null_datetimelike(val, inat_is_null=False, inf_as_na=inf_as_na)
or is_decimal_na(val)
)
if val is None or val is NaT or val is C_NA:
return True
elif util.is_float_object(val) or util.is_complex_object(val):
if val != val:
return True
elif inf_as_na:
return val == INF or val == NEGINF
return False
elif util.is_timedelta64_object(val):
return get_timedelta64_value(val) == NPY_NAT
elif util.is_datetime64_object(val):
return get_datetime64_value(val) == NPY_NAT
else:
return is_decimal_na(val)


cdef inline bint is_decimal_na(object val):
Expand Down
2 changes: 0 additions & 2 deletions pandas/_libs/tslibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"NaTType",
"iNaT",
"nat_strings",
"is_null_datetimelike",
"OutOfBoundsDatetime",
"OutOfBoundsTimedelta",
"IncompatibleFrequency",
Expand Down Expand Up @@ -37,7 +36,6 @@
NaT,
NaTType,
iNaT,
is_null_datetimelike,
nat_strings,
)
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/tslibs/nattype.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ cdef _NaT c_NaT
cdef bint checknull_with_nat(object val)
cdef bint is_dt64nat(object val)
cdef bint is_td64nat(object val)
cpdef bint is_null_datetimelike(object val, bint inat_is_null=*, bint inf_as_na=*)
4 changes: 0 additions & 4 deletions pandas/_libs/tslibs/nattype.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ NaT: NaTType
iNaT: int
nat_strings: set[str]

def is_null_datetimelike(
val: object, inat_is_null: bool = ..., inf_as_na: bool = ...
) -> bool: ...

class NaTType(datetime):
value: np.int64
def asm8(self) -> np.datetime64: ...
Expand Down
42 changes: 0 additions & 42 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1218,45 +1218,3 @@ cdef inline bint is_td64nat(object val):
if util.is_timedelta64_object(val):
return get_timedelta64_value(val) == NPY_NAT
return False


cdef:
cnp.float64_t INF = <cnp.float64_t>np.inf
cnp.float64_t NEGINF = -INF


cpdef bint is_null_datetimelike(
object val, bint inat_is_null=True, bint inf_as_na=False
):
"""
Determine if we have a null for a timedelta/datetime (or integer versions).

Parameters
----------
val : object
inat_is_null : bool, default True
Whether to treat integer iNaT value as null
inf_as_na : bool, default False
Whether to treat INF or -INF value as null.

Returns
-------
bool
"""
if val is None:
return True
elif val is c_NaT:
return True
elif util.is_float_object(val) or util.is_complex_object(val):
if val != val:
return True
if inf_as_na:
return val == INF or val == NEGINF
return False
elif util.is_timedelta64_object(val):
return get_timedelta64_value(val) == NPY_NAT
elif util.is_datetime64_object(val):
return get_datetime64_value(val) == NPY_NAT
elif inat_is_null and util.is_integer_object(val):
return val == NPY_NAT
return False
25 changes: 1 addition & 24 deletions pandas/tests/dtypes/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
from pandas._config import config as cf

from pandas._libs import missing as libmissing
from pandas._libs.tslibs import (
iNaT,
is_null_datetimelike,
)
from pandas._libs.tslibs import iNaT

from pandas.core.dtypes.common import (
is_float,
Expand Down Expand Up @@ -687,26 +684,6 @@ def test_checknull_old(self):
for value in never_na_vals:
assert not libmissing.checknull_old(value)

def test_is_null_datetimelike(self):
for value in na_vals:
assert is_null_datetimelike(value)
assert is_null_datetimelike(value, False)

for value in inf_vals:
assert not is_null_datetimelike(value)
assert not is_null_datetimelike(value, False)

for value in int_na_vals:
assert is_null_datetimelike(value)
assert not is_null_datetimelike(value, False)

for value in sometimes_na_vals:
assert not is_null_datetimelike(value)
assert not is_null_datetimelike(value, False)

for value in never_na_vals:
assert not is_null_datetimelike(value)

def test_is_matching_na(self, nulls_fixture, nulls_fixture2):
left = nulls_fixture
right = nulls_fixture2
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/tslibs/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def test_namespace():
"NaT",
"NaTType",
"iNaT",
"is_null_datetimelike",
"nat_strings",
"OutOfBoundsDatetime",
"OutOfBoundsTimedelta",
Expand Down