Skip to content

Commit 6cb9f52

Browse files
committed
Fix docstrings for pandas.Period.month
1 parent e2ed477 commit 6cb9f52

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7979
-i "pandas.Period.asfreq SA01" \
8080
-i "pandas.Period.freq GL08" \
8181
-i "pandas.Period.freqstr SA01" \
82-
-i "pandas.Period.month SA01" \
8382
-i "pandas.Period.ordinal GL08" \
8483
-i "pandas.Period.strftime PR01,SA01" \
8584
-i "pandas.Period.to_timestamp SA01" \

pandas/_libs/tslibs/period.pyx

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,15 +2011,61 @@ cdef class _Period(PeriodMixin):
20112011

20122012
@property
20132013
def month(self) -> int:
2014-
"""
2015-
Return the month this Period falls on.
2014+
"""
2015+
Return the month this Period falls on.
2016+
2017+
Parameters
2018+
----------
2019+
None
2020+
2021+
Returns
2022+
-------
2023+
int : The month number of the Period.
2024+
2025+
See Also
2026+
--------
2027+
period.week : Get the week of the year on the given Period.
2028+
Period.year : Return the year this Period falls on.
2029+
Period.day : Return the day of the month this Period falls on.
2030+
2031+
2032+
Examples
2033+
--------
2034+
Create a Period object for January 2022 and get the month:
2035+
2036+
>>> period = pd.Period('2022-01', 'M')
2037+
>>> period.month
2038+
1
2039+
2040+
Create a Period object with no specified frequency, resulting in a default frequency:
2041+
2042+
>>> period = pd.Period('2022', 'Y')
2043+
>>> period.month
2044+
12
2045+
2046+
Create a Period object with a specified frequency but an incomplete date string:
2047+
2048+
>>> period = pd.Period('2022', 'M')
2049+
>>> period.month
2050+
1
2051+
2052+
Handle a case where the Period object is invalid or empty, which results in `NaN`:
2053+
2054+
>>> period = pd.Period('nan', 'M')
2055+
>>> period.month
2056+
nan
2057+
2058+
Handle a case where the Period object is invalid or empty, which results in `NaN`:
2059+
2060+
>>> period = pd.Period('nan', 'M')
2061+
>>> period.month
2062+
nan
2063+
2064+
Notes
2065+
-----
2066+
The month is determined based on the `ordinal` and `base` attributes of the Period.
2067+
"""
20162068

2017-
Examples
2018-
--------
2019-
>>> period = pd.Period('2022-01', 'M')
2020-
>>> period.month
2021-
1
2022-
"""
20232069
base = self._dtype._dtype_code
20242070
return pmonth(self.ordinal, base)
20252071

0 commit comments

Comments
 (0)