From 3ddd0badb694a0633c3997912e402f84b2392f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Wed, 17 May 2023 18:07:02 +0200 Subject: [PATCH 1/2] Added Examples --- ci/code_checks.sh | 5 ----- pandas/_libs/tslibs/period.pyx | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 6436556e0a696..8e30c4c6b8d52 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -170,11 +170,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.Timedelta.total_seconds \ pandas.arrays.TimedeltaArray \ pandas.Period.end_time \ - pandas.Period.freqstr \ - pandas.Period.is_leap_year \ - pandas.Period.month \ - pandas.Period.quarter \ - pandas.Period.year \ pandas.Period.asfreq \ pandas.Period.now \ pandas.arrays.PeriodArray \ diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 1626d1490b440..71f86b43cf6f1 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1967,6 +1967,12 @@ cdef class _Period(PeriodMixin): def year(self) -> int: """ Return the year this Period falls on. + + Examples + -------- + >>> period = pd.Period('2022-01', 'M') + >>> period.year + 2022 """ base = self._dtype._dtype_code return pyear(self.ordinal, base) @@ -1975,6 +1981,12 @@ cdef class _Period(PeriodMixin): def month(self) -> int: """ Return the month this Period falls on. + + Examples + -------- + >>> period = pd.Period('2022-01', 'M') + >>> period.month + 1 """ base = self._dtype._dtype_code return pmonth(self.ordinal, base) @@ -2284,6 +2296,12 @@ cdef class _Period(PeriodMixin): def quarter(self) -> int: """ Return the quarter this Period falls on. + + Examples + -------- + >>> period = pd.Period('2022-04', 'M') + >>> period.quarter + 2 """ base = self._dtype._dtype_code return pquarter(self.ordinal, base) @@ -2392,6 +2410,16 @@ cdef class _Period(PeriodMixin): def is_leap_year(self) -> bool: """ Return True if the period's year is in a leap year. + + Examples + -------- + >>> period = pd.Period('2022-01', 'M') + >>> period.is_leap_year + False + + >>> period = pd.Period('2020-01', 'M') + >>> period.is_leap_year + True """ return bool(is_leapyear(self.year)) @@ -2411,6 +2439,11 @@ cdef class _Period(PeriodMixin): def freqstr(self) -> str: """ Return a string representation of the frequency. + + Examples + -------- + >>> pd.Period('2020-01', 'D').freqstr + 'D' """ return self._dtype._freqstr From 11b47e7f370de95339b90a4db8ffc50fd0d77ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Wed, 17 May 2023 18:13:46 +0200 Subject: [PATCH 2/2] corrected code_checks --- ci/code_checks.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 8e30c4c6b8d52..433118e648827 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -169,7 +169,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.Timedelta.to_numpy \ pandas.Timedelta.total_seconds \ pandas.arrays.TimedeltaArray \ - pandas.Period.end_time \ pandas.Period.asfreq \ pandas.Period.now \ pandas.arrays.PeriodArray \