diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 25142cad9a30d..611bec50a7393 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -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 diff --git a/pandas/_libs/missing.pyx b/pandas/_libs/missing.pyx index 6146e8ea13f89..d5db2a8d7e0a7 100644 --- a/pandas/_libs/missing.pyx +++ b/pandas/_libs/missing.pyx @@ -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 ( @@ -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): diff --git a/pandas/_libs/tslibs/__init__.py b/pandas/_libs/tslibs/__init__.py index e38ed9a20e55b..11de4e60f202d 100644 --- a/pandas/_libs/tslibs/__init__.py +++ b/pandas/_libs/tslibs/__init__.py @@ -5,7 +5,6 @@ "NaTType", "iNaT", "nat_strings", - "is_null_datetimelike", "OutOfBoundsDatetime", "OutOfBoundsTimedelta", "IncompatibleFrequency", @@ -37,7 +36,6 @@ NaT, NaTType, iNaT, - is_null_datetimelike, nat_strings, ) from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime diff --git a/pandas/_libs/tslibs/nattype.pxd b/pandas/_libs/tslibs/nattype.pxd index 0ace3ca1fd4b1..b7c14e0a5b068 100644 --- a/pandas/_libs/tslibs/nattype.pxd +++ b/pandas/_libs/tslibs/nattype.pxd @@ -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=*) diff --git a/pandas/_libs/tslibs/nattype.pyi b/pandas/_libs/tslibs/nattype.pyi index 1a33a85a04ae0..6a5555cfff030 100644 --- a/pandas/_libs/tslibs/nattype.pyi +++ b/pandas/_libs/tslibs/nattype.pyi @@ -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: ... diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index ae553d79ae91e..a36a1e12c274d 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -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 = 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 diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index 55d0e5e73418e..7e34c7781392e 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -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, @@ -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 diff --git a/pandas/tests/tslibs/test_api.py b/pandas/tests/tslibs/test_api.py index 4ded555ed8f73..d7abb19530837 100644 --- a/pandas/tests/tslibs/test_api.py +++ b/pandas/tests/tslibs/test_api.py @@ -29,7 +29,6 @@ def test_namespace(): "NaT", "NaTType", "iNaT", - "is_null_datetimelike", "nat_strings", "OutOfBoundsDatetime", "OutOfBoundsTimedelta",