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.year SA01 #59525

Merged
merged 4 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.ordinal GL08" \
-i "pandas.Period.strftime PR01,SA01" \
-i "pandas.Period.to_timestamp SA01" \
-i "pandas.Period.year SA01" \
-i "pandas.PeriodDtype SA01" \
-i "pandas.PeriodDtype.freq SA01" \
-i "pandas.PeriodIndex.day SA01" \
Expand Down
37 changes: 35 additions & 2 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2038,11 +2038,44 @@ cdef class _Period(PeriodMixin):
"""
Return the year this Period falls on.

Returns
-------
int

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

Notes
-----
The year is based on the `ordinal` and `base` attributes of the Period.

Examples
--------
>>> period = pd.Period('2022-01', 'M')
Create a Period object for January 2023 and get the year:

>>> period = pd.Period('2023-01', 'M')
>>> period.year
2022
2023

Create a Period object for 01 January 2023 and get the year:

>>> period = pd.Period('2023', 'D')
>>> period.year
2023

Get the year for a period representing a quarter:

>>> period = pd.Period('2023Q2', 'Q')
>>> period.year
2023

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

>>> period = pd.Period('nan', 'M')
>>> period.year
nan
"""
base = self._dtype._dtype_code
return pyear(self.ordinal, base)
Expand Down
Loading