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. The derived order
(ordinal, then freq) is a total one for index labels (45fzr): within one
freq it is the periods’ own.
Fields§
§ordinal: i64§freq: PeriodFreqImplementations§
Source§impl Period
impl Period
pub const fn new(ordinal: i64, freq: PeriodFreq) -> Self
Sourcepub const fn is_nat(&self) -> bool
pub const fn is_nat(&self) -> bool
Whether this is NaT: the missing period, ordinal i64::MIN (what a
missing element of a PeriodIndex holds and what renders NaT).
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).
EVERY frequency is exact, Weekly and Business included.
⚠️ THOSE TWO ARE NOT INDEXED IN DAYS, which is what made them wrong until
08363d42f: a weekly ordinal counts WEEKS from the Monday 1969-12-22 and
renders as the RANGE it spans (2024-03-11/2024-03-17), and a business
ordinal counts BUSINESS DAYS at five per week. Both used to be handed to
civil_from_days, which reads its argument as days since the epoch, so
ordinal 2829 rendered 1977-09-30 instead of the week of 2024-03-15.
The note that used to sit here called them “best-effort” and said neither
was “reachable through the current parse/cast paths”. The first half was
a real limitation; the second was too narrow a survey. Self::parse
indeed cannot produce them and neither can cast_scalar — but
DatetimeIndex::to_period("W") builds them directly, and fp-index then
renders those values through Display in PeriodIndex::format,
to_index, to_flat_index, the .str accessor and the get_loc error
message. The frequencies were unreachable only from the two paths the
note happened to check.