diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 7f4911037cff9..fcbd0a855dcc8 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -155,7 +155,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.Period.ordinal\ pandas.PeriodIndex.freq\ pandas.PeriodIndex.qyear\ - pandas.Series.dt\ pandas.Series.dt.as_unit\ pandas.Series.dt.freq\ pandas.Series.dt.qyear\ @@ -437,6 +436,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.Series.cat.rename_categories\ pandas.Series.cat.reorder_categories\ pandas.Series.cat.set_categories\ + pandas.Series.dt `# Accessors are implemented as classes, but we do not document the Parameters section` \ pandas.Series.dt.as_unit\ pandas.Series.dt.ceil\ pandas.Series.dt.day_name\ diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 59d6e313a2d93..2bb234e174563 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -572,6 +572,44 @@ class PeriodProperties(Properties): class CombinedDatetimelikeProperties( DatetimeProperties, TimedeltaProperties, PeriodProperties ): + """ + Accessor object for Series values' datetime-like, timedelta and period properties. + + See Also + -------- + DatetimeIndex : Index of datetime64 data. + + Examples + -------- + >>> dates = pd.Series( + ... ["2024-01-01", "2024-01-15", "2024-02-5"], dtype="datetime64[ns]" + ... ) + >>> dates.dt.day + 0 1 + 1 15 + 2 5 + dtype: int32 + >>> dates.dt.month + 0 1 + 1 1 + 2 2 + dtype: int32 + + >>> dates = pd.Series( + ... ["2024-01-01", "2024-01-15", "2024-02-5"], dtype="datetime64[ns, UTC]" + ... ) + >>> dates.dt.day + 0 1 + 1 15 + 2 5 + dtype: int32 + >>> dates.dt.month + 0 1 + 1 1 + 2 2 + dtype: int32 + """ + def __new__(cls, data: Series): # pyright: ignore[reportInconsistentConstructor] # CombinedDatetimelikeProperties isn't really instantiated. Instead # we need to choose which parent (datetime or timedelta) is