Skip to content

Commit

Permalink
DOC: Fixing EX01 - Added examples (#53274)
Browse files Browse the repository at this point in the history
* Added Examples

* corrected code_checks
  • Loading branch information
DeaMariaLeon committed May 17, 2023
1 parent 199624d commit 80b3fee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
5 changes: 0 additions & 5 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.Timedelta.to_numpy \
pandas.Timedelta.total_seconds \
pandas.arrays.TimedeltaArray \
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 \
Expand Down
33 changes: 33 additions & 0 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,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)
Expand All @@ -1992,6 +1998,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)
Expand Down Expand Up @@ -2301,6 +2313,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)
Expand Down Expand Up @@ -2409,6 +2427,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))

Expand All @@ -2428,6 +2456,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

Expand Down

0 comments on commit 80b3fee

Please sign in to comment.