Skip to content

Commit 8169e4e

Browse files
committed
Fix docstrings for pandas.Period.year SA01
1 parent 66e465e commit 8169e4e

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-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

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

2041+
Returns
2042+
-------
2043+
int
2044+
The year (e.g., 2023)
2045+
2046+
See Also
2047+
--------
2048+
period.month : Get the month of the year on the given Period.
2049+
period.day : Return the day of the month the Period falls on.
2050+
2051+
Notes
2052+
-----
2053+
The year is based on the `ordinal` and `base` attributes of the Period.
2054+
20412055
Examples
20422056
--------
2043-
>>> period = pd.Period('2022-01', 'M')
2057+
Create a Period object for January 2023 and get the year:
2058+
2059+
>>> period = pd.Period('2023-01', 'M')
20442060
>>> period.year
2045-
2022
2061+
2023
2062+
2063+
Create a Period object for 01 January 2023 and get the year:
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.month
2078+
nan
2079+
2080+
Period object with an invalid format:
2081+
2082+
>>> period = pd.Period('invalid', 'M')
2083+
# Will raise an DateParseError
20462084
"""
20472085
base = self._dtype._dtype_code
20482086
return pyear(self.ordinal, base)

0 commit comments

Comments
 (0)