Skip to content

Commit 99d92d9

Browse files
committed
DOC: Fix pandas.Period.freq docstring validation (GL08)
- Convert freq from cdef readonly to @Property with proper docstring - Add comprehensive NumPy-style docstring following pandas standards - Include Returns, See Also, and Examples sections - Remove pandas.Period.freq GL08 from ci/code_checks.sh ignore list Part of #58063
1 parent 4386a46 commit 99d92d9

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7070
--format=actions \
7171
-i ES01 `# For now it is ok if docstrings are missing the extended summary` \
7272
-i "pandas.Series.dt PR01" `# Accessors are implemented as classes, but we do not document the Parameters section` \
73-
-i "pandas.Period.freq GL08" \
7473
-i "pandas.Period.ordinal GL08" \
7574
-i "pandas.errors.IncompatibleFrequency SA01,SS06,EX01" \
7675
-i "pandas.api.extensions.ExtensionArray.value_counts EX01,RT03,SA01" \

pandas/_libs/tslibs/period.pyx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,9 @@ cdef class _Period(PeriodMixin):
17461746
cdef readonly:
17471747
int64_t ordinal
17481748
PeriodDtypeBase _dtype
1749-
BaseOffset freq
1749+
1750+
cdef:
1751+
BaseOffset _freq
17501752

17511753
# higher than np.ndarray, np.matrix, np.timedelta64
17521754
__array_priority__ = 100
@@ -1756,9 +1758,40 @@ cdef class _Period(PeriodMixin):
17561758

17571759
def __cinit__(self, int64_t ordinal, BaseOffset freq):
17581760
self.ordinal = ordinal
1759-
self.freq = freq
1761+
self._freq = freq
17601762
self._dtype = PeriodDtypeBase(freq._period_dtype_code, freq.n)
17611763

1764+
@property
1765+
def freq(self) -> BaseOffset:
1766+
"""
1767+
Get the frequency object of the Period.
1768+
1769+
The frequency represents the span of the period. This can be any valid
1770+
pandas frequency string (e.g., 'D' for daily, 'M' for monthly) or a
1771+
DateOffset object.
1772+
1773+
Returns
1774+
-------
1775+
BaseOffset
1776+
The frequency object of the Period.
1777+
1778+
See Also
1779+
--------
1780+
Period.freqstr : Return a string representation of the frequency.
1781+
Period.asfreq : Convert Period to desired frequency.
1782+
1783+
Examples
1784+
--------
1785+
>>> period = pd.Period('2020-01', freq='M')
1786+
>>> period.freq
1787+
<MonthEnd>
1788+
1789+
>>> period = pd.Period('2020-01-01', freq='D')
1790+
>>> period.freq
1791+
<Day>
1792+
"""
1793+
return self._freq
1794+
17621795
@classmethod
17631796
def _maybe_convert_freq(cls, object freq) -> BaseOffset:
17641797
"""
@@ -2660,11 +2693,11 @@ cdef class _Period(PeriodMixin):
26602693
return value
26612694

26622695
def __setstate__(self, state):
2663-
self.freq = state[1]
2696+
self._freq = state[1]
26642697
self.ordinal = state[2]
26652698

26662699
def __reduce__(self):
2667-
object_state = None, self.freq, self.ordinal
2700+
object_state = None, self._freq, self.ordinal
26682701
return (Period, object_state)
26692702

26702703
def strftime(self, fmt: str | None) -> str:

0 commit comments

Comments
 (0)