Skip to content
Open
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 @@ -70,7 +70,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
--format=actions \
-i ES01 `# For now it is ok if docstrings are missing the extended summary` \
-i "pandas.Series.dt PR01" `# Accessors are implemented as classes, but we do not document the Parameters section` \
-i "pandas.Period.freq GL08" \
-i "pandas.Period.ordinal GL08" \
-i "pandas.errors.IncompatibleFrequency SA01,SS06,EX01" \
-i "pandas.api.extensions.ExtensionArray.value_counts EX01,RT03,SA01" \
Expand Down
41 changes: 37 additions & 4 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,9 @@ cdef class _Period(PeriodMixin):
cdef readonly:
int64_t ordinal
PeriodDtypeBase _dtype
BaseOffset freq

cdef:
BaseOffset _freq

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

def __cinit__(self, int64_t ordinal, BaseOffset freq):
self.ordinal = ordinal
self.freq = freq
self._freq = freq
self._dtype = PeriodDtypeBase(freq._period_dtype_code, freq.n)

@property
def freq(self) -> BaseOffset:
"""
Get the frequency object of the Period.

The frequency represents the span of the period. This can be any valid
pandas frequency string (e.g., 'D' for daily, 'M' for monthly) or a
DateOffset object.

Returns
-------
BaseOffset
The frequency object of the Period.

See Also
--------
Period.freqstr : Return a string representation of the frequency.
Period.asfreq : Convert Period to desired frequency.

Examples
--------
>>> period = pd.Period('2020-01', freq='M')
>>> period.freq
<MonthEnd>

>>> period = pd.Period('2020-01-01', freq='D')
>>> period.freq
<Day>
"""
return self._freq

@classmethod
def _maybe_convert_freq(cls, object freq) -> BaseOffset:
"""
Expand Down Expand Up @@ -2660,11 +2693,11 @@ cdef class _Period(PeriodMixin):
return value

def __setstate__(self, state):
self.freq = state[1]
self._freq = state[1]
self.ordinal = state[2]

def __reduce__(self):
object_state = None, self.freq, self.ordinal
object_state = None, self._freq, self.ordinal
return (Period, object_state)

def strftime(self, fmt: str | None) -> str:
Expand Down
Loading