Skip to content

Commit 167ae36

Browse files
authored
revoke the changes in @doc
Added doc decorators to methods for better documentation integration.
1 parent 31942cf commit 167ae36

File tree

1 file changed

+12
-139
lines changed

1 file changed

+12
-139
lines changed

pandas/core/indexes/datetimelike.py

Lines changed: 12 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
NullFrequencyError,
3737
)
3838
from pandas.util._decorators import (
39+
Appender,
3940
cache_readonly,
41+
doc,
4042
)
4143

4244
from pandas.core.dtypes.common import (
@@ -55,10 +57,12 @@
5557
PeriodArray,
5658
TimedeltaArray,
5759
)
60+
from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin
5861
import pandas.core.common as com
5962
import pandas.core.indexes.base as ibase
6063
from pandas.core.indexes.base import (
6164
Index,
65+
_index_shared_docs,
6266
)
6367
from pandas.core.indexes.extension import NDArrayBackedExtensionIndex
6468
from pandas.core.indexes.range import RangeIndex
@@ -88,37 +92,8 @@ class DatetimeIndexOpsMixin(NDArrayBackedExtensionIndex, ABC):
8892
_can_hold_strings = False
8993
_data: DatetimeArray | TimedeltaArray | PeriodArray
9094

95+
@doc(DatetimeLikeArrayMixin.mean)
9196
def mean(self, *, skipna: bool = True, axis: int | None = 0):
92-
"""
93-
Return the mean value of the Array.
94-
95-
Parameters
96-
----------
97-
skipna : bool, default True
98-
Whether to ignore any NaT elements.
99-
axis : int, optional, default 0
100-
Axis along which to compute the mean.
101-
102-
Returns
103-
-------
104-
scalar
105-
Timestamp or Timedelta.
106-
107-
See Also
108-
--------
109-
numpy.ndarray.mean : Returns the average of the array elements.
110-
Series.mean : Return the mean value in a Series.
111-
112-
Examples
113-
--------
114-
>>> idx = pd.date_range("2023-01-01", periods=3)
115-
>>> idx.mean()
116-
Timestamp('2023-01-02 00:00:00')
117-
118-
>>> idx = pd.to_timedelta([1, 2, 3], unit="D")
119-
>>> idx.mean()
120-
Timedelta('2 days 00:00:00')
121-
"""
12297
return self._data.mean(skipna=skipna, axis=axis)
12398

12499
@property
@@ -161,22 +136,8 @@ def asi8(self) -> npt.NDArray[np.int64]:
161136
return self._data.asi8
162137

163138
@property
139+
@doc(DatetimeLikeArrayMixin.freqstr)
164140
def freqstr(self) -> str:
165-
"""
166-
Return the frequency string if it is set, otherwise None.
167-
168-
See Also
169-
--------
170-
DatetimeIndex.freq : Return the frequency object if it is set, otherwise None.
171-
DatetimeIndex.inferred_freq : Tries to return a string representing a frequency
172-
guess generated by infer_freq.
173-
174-
Examples
175-
--------
176-
>>> idx = pd.date_range("2023-01-01", periods=3, freq="D")
177-
>>> idx.freqstr
178-
'D'
179-
"""
180141
from pandas import PeriodIndex
181142

182143
if self._data.freqstr is not None and isinstance(
@@ -192,15 +153,8 @@ def freqstr(self) -> str:
192153
def _resolution_obj(self) -> Resolution: ...
193154

194155
@cache_readonly
156+
@doc(DatetimeLikeArrayMixin.resolution)
195157
def resolution(self) -> str:
196-
"""
197-
Return the resolution of the array.
198-
199-
Returns
200-
-------
201-
str
202-
The resolution of the array.
203-
"""
204158
return self._data.resolution
205159

206160
# ------------------------------------------------------------------------
@@ -455,20 +409,8 @@ def shift(self, periods: int = 1, freq=None) -> Self:
455409

456410
# --------------------------------------------------------------------
457411

412+
@doc(Index._maybe_cast_listlike_indexer)
458413
def _maybe_cast_listlike_indexer(self, keyarr):
459-
"""
460-
Ensure that the list-like indexer is of the correct type.
461-
462-
Parameters
463-
----------
464-
keyarr : list-like
465-
The list-like indexer to check.
466-
467-
Returns
468-
-------
469-
list-like
470-
The list-like indexer of the correct type.
471-
"""
472414
try:
473415
res = self._data._validate_listlike(keyarr, allow_object=True)
474416
except (ValueError, TypeError):
@@ -559,33 +501,8 @@ def values(self) -> np.ndarray:
559501
data.flags.writeable = False
560502
return data
561503

504+
@doc(DatetimeIndexOpsMixin.shift)
562505
def shift(self, periods: int = 1, freq=None) -> Self:
563-
"""
564-
Shift index by desired number of time frequency increments.
565-
566-
This method is for shifting the values of datetime-like indexes
567-
by a specified time increment a given number of times.
568-
569-
Parameters
570-
----------
571-
periods : int, default 1
572-
Number of periods (or increments) to shift by,
573-
can be positive or negative.
574-
freq : pandas.DateOffset, pandas.Timedelta or string, optional
575-
Frequency increment to shift by.
576-
If None, the index is shifted by its own `freq` attribute.
577-
Offset aliases are valid strings, e.g., 'D', 'W', 'M' etc.
578-
579-
Returns
580-
-------
581-
pandas.DatetimeIndex
582-
Shifted index.
583-
584-
See Also
585-
--------
586-
Index.shift : Shift values of Index.
587-
PeriodIndex.shift : Shift values of PeriodIndex.
588-
"""
589506
if freq is not None and freq != self.freq:
590507
if isinstance(freq, str):
591508
freq = to_offset(freq)
@@ -611,25 +528,8 @@ def shift(self, periods: int = 1, freq=None) -> Self:
611528
return type(self)._simple_new(result, name=self.name)
612529

613530
@cache_readonly
531+
@doc(DatetimeLikeArrayMixin.inferred_freq)
614532
def inferred_freq(self) -> str | None:
615-
"""
616-
Tries to return a string representing a frequency guess generated by infer_freq.
617-
618-
Returns
619-
-------
620-
str or None
621-
622-
See Also
623-
--------
624-
DatetimeIndex.freq : Return the frequency object if it is set, otherwise None.
625-
DatetimeIndex.freqstr : Return the frequency string if it is set.
626-
627-
Examples
628-
--------
629-
>>> idx = pd.DatetimeIndex(["2018-01-01", "2018-01-03", "2018-01-05"])
630-
>>> idx.inferred_freq
631-
'2D'
632-
"""
633533
return self._data.inferred_freq
634534

635535
# --------------------------------------------------------------------
@@ -920,41 +820,14 @@ def _get_insert_freq(self, loc: int, item):
920820
freq = self.freq
921821
return freq
922822

823+
@doc(NDArrayBackedExtensionIndex.delete)
923824
def delete(self, loc) -> Self:
924-
"""
925-
Make new Index with passed location(-s) deleted.
926-
927-
Parameters
928-
----------
929-
loc : int or list of int
930-
Location of item(-s) to delete. Use a list of locations to delete
931-
multiple items. If a slice is provided, the step must be 1.
932-
933-
Returns
934-
-------
935-
Index
936-
Will be same type as self, except for RangeIndex.
937-
"""
938825
result = super().delete(loc)
939826
result._data._freq = self._get_delete_freq(loc)
940827
return result
941828

829+
@doc(NDArrayBackedExtensionIndex.insert)
942830
def insert(self, loc: int, item):
943-
"""
944-
Make new Index inserting new item at location.
945-
946-
Follows Python list.insert semantics for negative values. Only at
947-
least one of the index/item pairs must be specified.
948-
949-
Parameters
950-
----------
951-
loc : int
952-
item : object
953-
954-
Returns
955-
-------
956-
Index
957-
"""
958831
result = super().insert(loc, item)
959832
if isinstance(result, type(self)):
960833
# i.e. parent class method did not cast

0 commit comments

Comments
 (0)