33"""
44from __future__ import annotations
55
6+ from abc import (
7+ ABC ,
8+ abstractmethod ,
9+ )
610from datetime import datetime
711from typing import (
812 TYPE_CHECKING ,
6165 Index ,
6266 _index_shared_docs ,
6367)
64- from pandas .core .indexes .extension import (
65- NDArrayBackedExtensionIndex ,
66- inherit_names ,
67- )
68+ from pandas .core .indexes .extension import NDArrayBackedExtensionIndex
6869from pandas .core .indexes .range import RangeIndex
6970from pandas .core .tools .timedeltas import to_timedelta
7071
7778_TDT = TypeVar ("_TDT" , bound = "DatetimeTimedeltaMixin" )
7879
7980
80- @inherit_names (
81- ["inferred_freq" , "_resolution_obj" , "resolution" ],
82- DatetimeLikeArrayMixin ,
83- cache = True ,
84- )
85- @inherit_names (["mean" , "freqstr" ], DatetimeLikeArrayMixin )
86- class DatetimeIndexOpsMixin (NDArrayBackedExtensionIndex ):
81+ class DatetimeIndexOpsMixin (NDArrayBackedExtensionIndex , ABC ):
8782 """
8883 Common ops mixin to support a unified interface datetimelike Index.
8984 """
9085
9186 _can_hold_strings = False
9287 _data : DatetimeArray | TimedeltaArray | PeriodArray
93- freqstr : str | None
94- _resolution_obj : Resolution
88+
89+ @doc (DatetimeLikeArrayMixin .mean )
90+ def mean (self , * , skipna : bool = True , axis : int | None = 0 ):
91+ return self ._data .mean (skipna = skipna , axis = axis )
9592
9693 @property
9794 def freq (self ) -> BaseOffset | None :
@@ -106,6 +103,21 @@ def freq(self, value) -> None:
106103 def asi8 (self ) -> npt .NDArray [np .int64 ]:
107104 return self ._data .asi8
108105
106+ @property
107+ @doc (DatetimeLikeArrayMixin .freqstr )
108+ def freqstr (self ) -> str | None :
109+ return self ._data .freqstr
110+
111+ @cache_readonly
112+ @abstractmethod
113+ def _resolution_obj (self ) -> Resolution :
114+ ...
115+
116+ @cache_readonly
117+ @doc (DatetimeLikeArrayMixin .resolution )
118+ def resolution (self ) -> str :
119+ return self ._data .resolution
120+
109121 # ------------------------------------------------------------------------
110122
111123 @cache_readonly
@@ -390,7 +402,7 @@ def _maybe_cast_listlike_indexer(self, keyarr):
390402 return Index (res , dtype = res .dtype )
391403
392404
393- class DatetimeTimedeltaMixin (DatetimeIndexOpsMixin ):
405+ class DatetimeTimedeltaMixin (DatetimeIndexOpsMixin , ABC ):
394406 """
395407 Mixin class for methods shared by DatetimeIndex and TimedeltaIndex,
396408 but not PeriodIndex
@@ -461,6 +473,11 @@ def shift(self: _TDT, periods: int = 1, freq=None) -> _TDT:
461473 )
462474 return type (self )._simple_new (result , name = self .name )
463475
476+ @cache_readonly
477+ @doc (DatetimeLikeArrayMixin .inferred_freq )
478+ def inferred_freq (self ) -> str | None :
479+ return self ._data .inferred_freq
480+
464481 # --------------------------------------------------------------------
465482 # Set Operation Methods
466483
0 commit comments