Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docstrings for pandas.Period.month #59517

Merged
merged 9 commits into from
Aug 15, 2024
1 change: 0 additions & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Period.asfreq SA01" \
-i "pandas.Period.freq GL08" \
-i "pandas.Period.freqstr SA01" \
-i "pandas.Period.month SA01" \
-i "pandas.Period.ordinal GL08" \
-i "pandas.Period.strftime PR01,SA01" \
-i "pandas.Period.to_timestamp SA01" \
Expand Down
46 changes: 46 additions & 0 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2014,12 +2014,58 @@ cdef class _Period(PeriodMixin):
"""
Return the month this Period falls on.

Parameters
----------
None

Returns
-------
int : The month number of the Period.

See Also
--------
period.week : Get the week of the year on the given Period.
Period.year : Return the year this Period falls on.
Period.day : Return the day of the month this Period falls on.


Examples
--------
Create a Period object for January 2022 and get the month:

>>> period = pd.Period('2022-01', 'M')
>>> period.month
1

Create a Period object with no specified frequency, resulting in a default frequency:

>>> period = pd.Period('2022', 'Y')
>>> period.month
12

Create a Period object with a specified frequency but an incomplete date string:

>>> period = pd.Period('2022', 'M')
>>> period.month
1

Handle a case where the Period object is invalid or empty, which results in `NaN`:

>>> period = pd.Period('nan', 'M')
>>> period.month
nan

Handle a case where the Period object is invalid or empty, which results in `NaN`:

>>> period = pd.Period('nan', 'M')
>>> period.month
nan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repeated?


Notes
-----
The month is determined based on the `ordinal` and `base` attributes of the Period.
"""

base = self._dtype._dtype_code
return pmonth(self.ordinal, base)

Expand Down
Loading