3
3
"""
4
4
from __future__ import annotations
5
5
6
+ from abc import (
7
+ ABC ,
8
+ abstractmethod ,
9
+ )
6
10
from datetime import datetime
7
11
from typing import (
8
12
TYPE_CHECKING ,
61
65
Index ,
62
66
_index_shared_docs ,
63
67
)
64
- from pandas .core .indexes .extension import (
65
- NDArrayBackedExtensionIndex ,
66
- inherit_names ,
67
- )
68
+ from pandas .core .indexes .extension import NDArrayBackedExtensionIndex
68
69
from pandas .core .indexes .range import RangeIndex
69
70
from pandas .core .tools .timedeltas import to_timedelta
70
71
77
78
_TDT = TypeVar ("_TDT" , bound = "DatetimeTimedeltaMixin" )
78
79
79
80
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 ):
87
82
"""
88
83
Common ops mixin to support a unified interface datetimelike Index.
89
84
"""
90
85
91
86
_can_hold_strings = False
92
87
_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 )
95
92
96
93
@property
97
94
def freq (self ) -> BaseOffset | None :
@@ -106,6 +103,21 @@ def freq(self, value) -> None:
106
103
def asi8 (self ) -> npt .NDArray [np .int64 ]:
107
104
return self ._data .asi8
108
105
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
+
109
121
# ------------------------------------------------------------------------
110
122
111
123
@cache_readonly
@@ -390,7 +402,7 @@ def _maybe_cast_listlike_indexer(self, keyarr):
390
402
return Index (res , dtype = res .dtype )
391
403
392
404
393
- class DatetimeTimedeltaMixin (DatetimeIndexOpsMixin ):
405
+ class DatetimeTimedeltaMixin (DatetimeIndexOpsMixin , ABC ):
394
406
"""
395
407
Mixin class for methods shared by DatetimeIndex and TimedeltaIndex,
396
408
but not PeriodIndex
@@ -461,6 +473,11 @@ def shift(self: _TDT, periods: int = 1, freq=None) -> _TDT:
461
473
)
462
474
return type (self )._simple_new (result , name = self .name )
463
475
476
+ @cache_readonly
477
+ @doc (DatetimeLikeArrayMixin .inferred_freq )
478
+ def inferred_freq (self ) -> str | None :
479
+ return self ._data .inferred_freq
480
+
464
481
# --------------------------------------------------------------------
465
482
# Set Operation Methods
466
483
0 commit comments