Skip to content

Commit 96a7462

Browse files
Fix docstrings for pandas.Period.year SA01 (#59525)
* Fix docstrings for pandas.Period.year SA01 * Fix docstrings for pandas.Period.year SA01 Validate Docstrings err * Fix docstrings for pandas.Period.year SA01 Validate Docstrings err * Removed dateparseerror example from period.year Co-authored-by: Matthew Roeschke <[email protected]> --------- Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 523afa8 commit 96a7462

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7979
-i "pandas.Period.ordinal GL08" \
8080
-i "pandas.Period.strftime PR01,SA01" \
8181
-i "pandas.Period.to_timestamp SA01" \
82-
-i "pandas.Period.year SA01" \
8382
-i "pandas.PeriodDtype SA01" \
8483
-i "pandas.PeriodDtype.freq SA01" \
8584
-i "pandas.PeriodIndex.day SA01" \

pandas/_libs/tslibs/period.pyx

+35-2
Original file line numberDiff line numberDiff line change
@@ -2038,11 +2038,44 @@ cdef class _Period(PeriodMixin):
20382038
"""
20392039
Return the year this Period falls on.
20402040

2041+
Returns
2042+
-------
2043+
int
2044+
2045+
See Also
2046+
--------
2047+
period.month : Get the month of the year for the given Period.
2048+
period.day : Return the day of the month the Period falls on.
2049+
2050+
Notes
2051+
-----
2052+
The year is based on the `ordinal` and `base` attributes of the Period.
2053+
20412054
Examples
20422055
--------
2043-
>>> period = pd.Period('2022-01', 'M')
2056+
Create a Period object for January 2023 and get the year:
2057+
2058+
>>> period = pd.Period('2023-01', 'M')
20442059
>>> period.year
2045-
2022
2060+
2023
2061+
2062+
Create a Period object for 01 January 2023 and get the year:
2063+
2064+
>>> period = pd.Period('2023', 'D')
2065+
>>> period.year
2066+
2023
2067+
2068+
Get the year for a period representing a quarter:
2069+
2070+
>>> period = pd.Period('2023Q2', 'Q')
2071+
>>> period.year
2072+
2023
2073+
2074+
Handle a case where the Period object is empty, which results in `NaN`:
2075+
2076+
>>> period = pd.Period('nan', 'M')
2077+
>>> period.year
2078+
nan
20462079
"""
20472080
base = self._dtype._dtype_code
20482081
return pyear(self.ordinal, base)

0 commit comments

Comments
 (0)