pub struct Period {
pub ordinal: i64,
pub freq: PeriodFreq,
}Expand description
A single pandas-style Period value.
Stored as an integer ordinal on a frequency-specific axis plus the
frequency code. Two Periods with different freq are incompatible —
arithmetic and comparison require same-freq operands.
Fields§
§ordinal: i64§freq: PeriodFreqImplementations§
Source§impl Period
impl Period
pub const fn new(ordinal: i64, freq: PeriodFreq) -> Self
Sourcepub const fn ordinal(&self) -> i64
pub const fn ordinal(&self) -> i64
Integer position on this period’s frequency axis, matching
pd.Period.ordinal.
Sourcepub const fn freq(&self) -> PeriodFreq
pub const fn freq(&self) -> PeriodFreq
Frequency code for this period, matching pd.Period.freq.
Sourcepub const fn freqstr(&self) -> &'static str
pub const fn freqstr(&self) -> &'static str
Canonical pandas frequency alias, matching pd.Period.freqstr.
Sourcepub fn cmp_same_freq(&self, other: &Self) -> Option<Ordering>
pub fn cmp_same_freq(&self, other: &Self) -> Option<Ordering>
Same-freq ordinal comparison. Returns None if freq differs —
caller decides whether that’s an error or a panic site.
Sourcepub fn shift(&self, n: i64) -> Self
pub fn shift(&self, n: i64) -> Self
Shift by n periods of the current frequency.
Matches pd.Period + n and pd.Period - n.
Sourcepub fn diff(&self, other: &Self) -> Option<i64>
pub fn diff(&self, other: &Self) -> Option<i64>
Period-difference in units of the shared frequency.
Returns None if freq differs (pandas raises IncompatibleFrequency).
Sourcepub fn parse(s: &str) -> Result<Self, TypeError>
pub fn parse(s: &str) -> Result<Self, TypeError>
Parse common pandas Period(...) strings and infer the frequency.
Supported forms mirror pandas’ unambiguous scalar constructor cases:
annual ("2024"), quarterly ("2024Q1"), monthly ("2024-01"),
and daily ("2024-01-15"). The ordinal axes match pandas:
1970, 1970Q1, 1970-01, and 1970-01-01 all have ordinal 0.
Sourcepub fn calendar_string(&self) -> String
pub fn calendar_string(&self) -> String
Pandas calendar string for this period, matching str(pd.Period).
Inverts the frequency-specific ordinal axes anchored at 1970:
1970/1970Q1/1970-01/1970-01-01/1970-01-01 00:00 all have
ordinal 0. Returns "NaT" for the missing sentinel (i64::MIN).
Annual/Quarterly/Monthly/Daily and the sub-daily clocks
(Hourly/Minutely/Secondly) are exact. Weekly and Business use a
best-effort YYYY-MM-DD rendering (their pandas axes — a Sunday-ended
week range and a business-day count — are not yet wired; neither is
reachable through the current parse/cast paths).