diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 71515e67a8276..e095d97146d03 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -274,16 +274,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.TimedeltaIndex.as_unit \ pandas.TimedeltaIndex.to_pytimedelta \ pandas.TimedeltaIndex.mean \ - pandas.PeriodIndex.day \ - pandas.PeriodIndex.dayofweek \ - pandas.PeriodIndex.day_of_week \ - pandas.PeriodIndex.dayofyear \ - pandas.PeriodIndex.day_of_year \ - pandas.PeriodIndex.days_in_month \ - pandas.PeriodIndex.daysinmonth \ - pandas.PeriodIndex.end_time \ - pandas.PeriodIndex.freqstr \ - pandas.PeriodIndex.hour \ pandas.core.window.rolling.Rolling.max \ pandas.core.window.rolling.Rolling.cov \ pandas.core.window.rolling.Rolling.skew \ diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 2047bc7970558..54bf041d59264 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1684,6 +1684,15 @@ cdef class PeriodMixin: 1 2020-02-29 23:59:59.999999999 2 2020-03-31 23:59:59.999999999 dtype: datetime64[ns] + + For PeriodIndex: + + >>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M") + >>> idx.end_time + DatetimeIndex(['2023-01-31 23:59:59.999999999', + '2023-02-28 23:59:59.999999999', + '2023-03-31 23:59:59.999999999'], + dtype='datetime64[ns]', freq=None) """ return self.to_timestamp(how="end") diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 13f314ba8381e..c3c0608a766db 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -829,6 +829,8 @@ def freqstr(self) -> str | None: Examples -------- + For DatetimeIndex: + >>> idx = pd.DatetimeIndex(["1/1/2020 10:00:00+00:00"], freq="D") >>> idx.freqstr 'D' @@ -839,6 +841,12 @@ def freqstr(self) -> str | None: ... freq="infer") >>> idx.freqstr '2D' + + For PeriodIndex: + + >>> idx = pd.PeriodIndex(["2023-1", "2023-2", "2023-3"], freq="M") + >>> idx.freqstr + 'M' """ if self.freq is None: return None diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 8afb9f4537f13..266dda52c6d0d 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -455,6 +455,12 @@ def __arrow_array__(self, type=None): "hour", """ The hour of the period. + + Examples + -------- + >>> idx = pd.PeriodIndex(["2023-01-01 10:00", "2023-01-01 11:00"], freq='H') + >>> idx.hour + Index([10, 11], dtype='int64') """, ) minute = _field_accessor( @@ -514,6 +520,18 @@ def __arrow_array__(self, type=None): "day_of_year", """ The ordinal day of the year. + + Examples + -------- + >>> idx = pd.PeriodIndex(["2023-01-10", "2023-02-01", "2023-03-01"], freq="D") + >>> idx.dayofyear + Index([10, 32, 60], dtype='int64') + + >>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y") + >>> idx + PeriodIndex(['2023', '2024', '2025'], dtype='period[A-DEC]') + >>> idx.dayofyear + Index([365, 366, 365], dtype='int64') """, ) quarter = _field_accessor( @@ -536,6 +554,8 @@ def __arrow_array__(self, type=None): Examples -------- + For Series: + >>> period = pd.period_range('2020-1-1 00:00', '2020-3-1 00:00', freq='M') >>> s = pd.Series(period) >>> s @@ -548,6 +568,12 @@ def __arrow_array__(self, type=None): 1 29 2 31 dtype: int64 + + For PeriodIndex: + + >>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M") + >>> idx.days_in_month # It can be also entered as `daysinmonth` + Index([31, 28, 31], dtype='int64') """, ) daysinmonth = days_in_month