diff --git a/pandas/_libs/index.pyx b/pandas/_libs/index.pyx index 2c28a7bbb02d0..35c4b73b47695 100644 --- a/pandas/_libs/index.pyx +++ b/pandas/_libs/index.pyx @@ -22,9 +22,9 @@ cnp.import_array() from pandas._libs cimport util from pandas._libs.tslibs.nattype cimport c_NaT as NaT -from pandas._libs.tslibs.base cimport ABCTimedelta from pandas._libs.tslibs.period cimport is_period_object from pandas._libs.tslibs.timestamps cimport _Timestamp +from pandas._libs.tslibs.timedeltas cimport _Timedelta from pandas._libs.hashtable cimport HashTable @@ -471,7 +471,7 @@ cdef class TimedeltaEngine(DatetimeEngine): return 'm8[ns]' cdef int64_t _unbox_scalar(self, scalar) except? -1: - if not (isinstance(scalar, ABCTimedelta) or scalar is NaT): + if not (isinstance(scalar, _Timedelta) or scalar is NaT): raise TypeError(scalar) return scalar.value diff --git a/pandas/_libs/interval.pyx b/pandas/_libs/interval.pyx index c0244b6e18a12..b5f5ef0a3f593 100644 --- a/pandas/_libs/interval.pyx +++ b/pandas/_libs/interval.pyx @@ -42,9 +42,9 @@ from pandas._libs.tslibs.util cimport ( is_timedelta64_object, ) -from pandas._libs.tslibs.base cimport ABCTimedelta from pandas._libs.tslibs.timezones cimport tz_compare from pandas._libs.tslibs.timestamps cimport _Timestamp +from pandas._libs.tslibs.timedeltas cimport _Timedelta _VALID_CLOSED = frozenset(['left', 'right', 'both', 'neither']) @@ -340,7 +340,7 @@ cdef class Interval(IntervalMixin): def _validate_endpoint(self, endpoint): # GH 23013 if not (is_integer_object(endpoint) or is_float_object(endpoint) or - isinstance(endpoint, (_Timestamp, ABCTimedelta))): + isinstance(endpoint, (_Timestamp, _Timedelta))): raise ValueError("Only numeric, Timestamp and Timedelta endpoints " "are allowed when constructing an Interval.") diff --git a/pandas/_libs/tslibs/base.pxd b/pandas/_libs/tslibs/base.pxd index d8c76542f3457..3bffff7aca43e 100644 --- a/pandas/_libs/tslibs/base.pxd +++ b/pandas/_libs/tslibs/base.pxd @@ -1,7 +1,4 @@ -from cpython.datetime cimport datetime, timedelta - -cdef class ABCTimedelta(timedelta): - pass +from cpython.datetime cimport datetime cdef class ABCTimestamp(datetime): diff --git a/pandas/_libs/tslibs/base.pyx b/pandas/_libs/tslibs/base.pyx index 6a5ee3f784334..1677a8b0be1ec 100644 --- a/pandas/_libs/tslibs/base.pyx +++ b/pandas/_libs/tslibs/base.pyx @@ -5,11 +5,7 @@ in order to allow for fast isinstance checks without circular dependency issues. This is analogous to core.dtypes.generic. """ -from cpython.datetime cimport datetime, timedelta - - -cdef class ABCTimedelta(timedelta): - pass +from cpython.datetime cimport datetime cdef class ABCTimestamp(datetime): diff --git a/pandas/_libs/tslibs/timedeltas.pxd b/pandas/_libs/tslibs/timedeltas.pxd index 95ddf8840e65d..70a418d7803d1 100644 --- a/pandas/_libs/tslibs/timedeltas.pxd +++ b/pandas/_libs/tslibs/timedeltas.pxd @@ -1,6 +1,18 @@ +from cpython.datetime cimport timedelta from numpy cimport int64_t # Exposed for tslib, not intended for outside use. cpdef int64_t delta_to_nanoseconds(delta) except? -1 cdef convert_to_timedelta64(object ts, object unit) cdef bint is_any_td_scalar(object obj) + + +cdef class _Timedelta(timedelta): + cdef readonly: + int64_t value # nanoseconds + object freq # frequency reference + bint is_populated # are my components populated + int64_t _d, _h, _m, _s, _ms, _us, _ns + + cpdef timedelta to_pytimedelta(_Timedelta self) + cpdef bint _has_ns(self) diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 10c1a56a2eb4e..f7bbf2c9e1c8b 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -21,7 +21,7 @@ from pandas._libs.tslibs.util cimport ( is_float_object, is_array ) -from pandas._libs.tslibs.base cimport ABCTimedelta, ABCTimestamp +from pandas._libs.tslibs.base cimport ABCTimestamp from pandas._libs.tslibs.conversion cimport cast_from_unit @@ -675,12 +675,12 @@ cdef _to_py_int_float(v): # timedeltas that we need to do object instantiation in python. This will # serve as a C extension type that shadows the Python class, where we do any # heavy lifting. -cdef class _Timedelta(ABCTimedelta): - cdef readonly: - int64_t value # nanoseconds - object freq # frequency reference - bint is_populated # are my components populated - int64_t _d, _h, _m, _s, _ms, _us, _ns +cdef class _Timedelta(timedelta): + # cdef readonly: + # int64_t value # nanoseconds + # object freq # frequency reference + # bint is_populated # are my components populated + # int64_t _d, _h, _m, _s, _ms, _us, _ns # higher than np.ndarray and np.matrix __array_priority__ = 100