diff --git a/pandas/_libs/missing.pyx b/pandas/_libs/missing.pyx index 981d9cc9cbcb3..0fd1c2b21d5cd 100644 --- a/pandas/_libs/missing.pyx +++ b/pandas/_libs/missing.pyx @@ -32,8 +32,6 @@ from pandas._libs.tslibs.nattype cimport ( ) from pandas._libs.tslibs.np_datetime cimport ( get_datetime64_unit, - get_datetime64_value, - get_timedelta64_value, import_pandas_datetime, ) @@ -122,16 +120,16 @@ cpdef bint is_matching_na(object left, object right, bint nan_matches_none=False ) elif cnp.is_datetime64_object(left): return ( - get_datetime64_value(left) == NPY_NAT + cnp.get_datetime64_value(left) == NPY_NAT and cnp.is_datetime64_object(right) - and get_datetime64_value(right) == NPY_NAT + and cnp.get_datetime64_value(right) == NPY_NAT and get_datetime64_unit(left) == get_datetime64_unit(right) ) elif cnp.is_timedelta64_object(left): return ( - get_timedelta64_value(left) == NPY_NAT + cnp.get_timedelta64_value(left) == NPY_NAT and cnp.is_timedelta64_object(right) - and get_timedelta64_value(right) == NPY_NAT + and cnp.get_timedelta64_value(right) == NPY_NAT and get_datetime64_unit(left) == get_datetime64_unit(right) ) elif is_decimal_na(left): @@ -170,9 +168,9 @@ cpdef bint checknull(object val, bint inf_as_na=False): return val == INF or val == NEGINF return False elif cnp.is_timedelta64_object(val): - return get_timedelta64_value(val) == NPY_NAT + return cnp.get_timedelta64_value(val) == NPY_NAT elif cnp.is_datetime64_object(val): - return get_datetime64_value(val) == NPY_NAT + return cnp.get_datetime64_value(val) == NPY_NAT else: return is_decimal_na(val) diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index 0568576c83870..ffc17e5d23258 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -41,7 +41,6 @@ from pandas._libs.tslibs.np_datetime cimport ( convert_reso, get_conversion_factor, get_datetime64_unit, - get_datetime64_value, get_implementation_bounds, import_pandas_datetime, npy_datetime, @@ -198,7 +197,7 @@ cdef int64_t get_datetime64_nanos(object val, NPY_DATETIMEUNIT reso) except? -1: NPY_DATETIMEUNIT unit npy_datetime ival - ival = get_datetime64_value(val) + ival = cnp.get_datetime64_value(val) if ival == NPY_NAT: return NPY_NAT diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 2ed54ab71182a..3416c68a23f63 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -21,10 +21,6 @@ from numpy cimport int64_t cnp.import_array() cimport pandas._libs.tslibs.util as util -from pandas._libs.tslibs.np_datetime cimport ( - get_datetime64_value, - get_timedelta64_value, -) # ---------------------------------------------------------------------- # Constants @@ -1439,7 +1435,7 @@ cdef bint is_dt64nat(object val): Is this a np.datetime64 object np.datetime64("NaT"). """ if cnp.is_datetime64_object(val): - return get_datetime64_value(val) == NPY_NAT + return cnp.get_datetime64_value(val) == NPY_NAT return False @@ -1448,5 +1444,5 @@ cdef bint is_td64nat(object val): Is this a np.timedelta64 object np.timedelta64("NaT"). """ if cnp.is_timedelta64_object(val): - return get_timedelta64_value(val) == NPY_NAT + return cnp.get_timedelta64_value(val) == NPY_NAT return False diff --git a/pandas/_libs/tslibs/np_datetime.pxd b/pandas/_libs/tslibs/np_datetime.pxd index 60532174e8bdc..445b832e8a5bd 100644 --- a/pandas/_libs/tslibs/np_datetime.pxd +++ b/pandas/_libs/tslibs/np_datetime.pxd @@ -25,11 +25,6 @@ cdef extern from "numpy/arrayscalars.h": npy_datetime obval PyArray_DatetimeMetaData obmeta - ctypedef struct PyTimedeltaScalarObject: - # PyObject_HEAD - npy_timedelta obval - PyArray_DatetimeMetaData obmeta - cdef extern from "numpy/ndarraytypes.h": ctypedef struct npy_datetimestruct: int64_t year @@ -96,8 +91,6 @@ cdef int64_t pydate_to_dt64( ) cdef void pydate_to_dtstruct(date val, npy_datetimestruct *dts) noexcept -cdef npy_datetime get_datetime64_value(object obj) noexcept nogil -cdef npy_timedelta get_timedelta64_value(object obj) noexcept nogil cdef NPY_DATETIMEUNIT get_datetime64_unit(object obj) noexcept nogil cdef int string_to_dts( diff --git a/pandas/_libs/tslibs/np_datetime.pyx b/pandas/_libs/tslibs/np_datetime.pyx index 25249e4f6f225..3ffd70f83e88f 100644 --- a/pandas/_libs/tslibs/np_datetime.pyx +++ b/pandas/_libs/tslibs/np_datetime.pyx @@ -59,22 +59,6 @@ cdef extern from "pandas/datetime/pd_datetime.h": # ---------------------------------------------------------------------- # numpy object inspection -cdef npy_datetime get_datetime64_value(object obj) noexcept nogil: - """ - returns the int64 value underlying scalar numpy datetime64 object - - Note that to interpret this as a datetime, the corresponding unit is - also needed. That can be found using `get_datetime64_unit`. - """ - return (obj).obval - - -cdef npy_timedelta get_timedelta64_value(object obj) noexcept nogil: - """ - returns the int64 value underlying scalar numpy timedelta64 object - """ - return (obj).obval - cdef NPY_DATETIMEUNIT get_datetime64_unit(object obj) noexcept nogil: """ @@ -278,6 +262,7 @@ cdef void pydate_to_dtstruct(date val, npy_datetimestruct *dts) noexcept: dts.ps = dts.as = 0 return + cdef int64_t pydate_to_dt64( date val, npy_datetimestruct *dts, NPY_DATETIMEUNIT reso=NPY_FR_ns ): diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 518577895ec9b..700f500c1d8b8 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -53,7 +53,6 @@ from pandas._libs.tslibs.np_datetime cimport ( NPY_FR_D, astype_overflowsafe, check_dts_bounds, - get_timedelta64_value, import_pandas_datetime, npy_datetimestruct, npy_datetimestruct_to_datetime, @@ -1822,7 +1821,7 @@ cdef class _Period(PeriodMixin): if ( cnp.is_timedelta64_object(other) and - get_timedelta64_value(other) == NPY_NAT + cnp.get_timedelta64_value(other) == NPY_NAT ): # i.e. np.timedelta64("nat") return NaT diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index bfa0a9e0b1864..a423137c68123 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -63,7 +63,6 @@ from pandas._libs.tslibs.np_datetime cimport ( cmp_scalar, convert_reso, get_datetime64_unit, - get_timedelta64_value, get_unit_from_dtype, import_pandas_datetime, npy_datetimestruct, @@ -261,7 +260,7 @@ cpdef int64_t delta_to_nanoseconds( "delta_to_nanoseconds does not support Y or M units, " "as their duration in nanoseconds is ambiguous." ) - n = get_timedelta64_value(delta) + n = cnp.get_timedelta64_value(delta) elif PyDelta_Check(delta): in_reso = NPY_DATETIMEUNIT.NPY_FR_us @@ -313,7 +312,7 @@ cdef object ensure_td64ns(object ts): ): unitstr = npy_unit_to_abbrev(td64_unit) - td64_value = get_timedelta64_value(ts) + td64_value = cnp.get_timedelta64_value(ts) mult = precision_from_unit(unitstr)[0] try: @@ -484,7 +483,7 @@ cdef int64_t _item_to_timedelta64( See array_to_timedelta64. """ try: - return get_timedelta64_value(convert_to_timedelta64(item, parsed_unit)) + return cnp.get_timedelta64_value(convert_to_timedelta64(item, parsed_unit)) except ValueError as err: if errors == "coerce": return NPY_NAT @@ -1859,7 +1858,7 @@ class Timedelta(_Timedelta): elif is_timedelta64_object(value): # Retain the resolution if possible, otherwise cast to the nearest # supported resolution. - new_value = get_timedelta64_value(value) + new_value = cnp.get_timedelta64_value(value) if new_value == NPY_NAT: # i.e. np.timedelta64("NaT") return NaT @@ -2223,7 +2222,7 @@ def truediv_object_array(ndarray left, ndarray right): td64 = left[i] obj = right[i] - if get_timedelta64_value(td64) == NPY_NAT: + if cnp.get_timedelta64_value(td64) == NPY_NAT: # td here should be interpreted as a td64 NaT if _should_cast_to_timedelta(obj): res_value = np.nan @@ -2252,7 +2251,7 @@ def floordiv_object_array(ndarray left, ndarray right): td64 = left[i] obj = right[i] - if get_timedelta64_value(td64) == NPY_NAT: + if cnp.get_timedelta64_value(td64) == NPY_NAT: # td here should be interpreted as a td64 NaT if _should_cast_to_timedelta(obj): res_value = np.nan diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index bf25eaeff19a5..01aea60268574 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -88,7 +88,6 @@ from pandas._libs.tslibs.np_datetime cimport ( cmp_scalar, convert_reso, get_datetime64_unit, - get_datetime64_value, get_unit_from_dtype, import_pandas_datetime, npy_datetimestruct, @@ -307,7 +306,7 @@ cdef class _Timestamp(ABCTimestamp): NPY_DATETIMEUNIT reso reso = get_datetime64_unit(dt64) - value = get_datetime64_value(dt64) + value = cnp.get_datetime64_value(dt64) return cls._from_value_and_reso(value, reso, None) # ----------------------------------------------------------------- diff --git a/pandas/_libs/tslibs/util.pxd b/pandas/_libs/tslibs/util.pxd index 61812bafc16d2..ddd07276c7a7e 100644 --- a/pandas/_libs/tslibs/util.pxd +++ b/pandas/_libs/tslibs/util.pxd @@ -33,8 +33,6 @@ cdef extern from "numpy/arrayobject.h": PyTypeObject PyFloatingArrType_Type cdef extern from "numpy/ndarrayobject.h": - PyTypeObject PyTimedeltaArrType_Type - PyTypeObject PyDatetimeArrType_Type PyTypeObject PyComplexFloatingArrType_Type PyTypeObject PyBoolArrType_Type