#[non_exhaustive]pub enum PeriodFreq {
Annual(u8),
Quarterly(u8),
Monthly,
Weekly(u8),
Daily,
Business,
Hourly,
Minutely,
Secondly,
Milliseconds,
Microseconds,
Nanoseconds,
}Expand description
Period frequency code. Matches pandas offset alias core set.
The ordinal axis is frequency-specific: for Monthly, ordinal 0 is a
fixed anchor (pandas uses months since 1970-01). Phase 1 doesn’t
commit to a specific epoch yet — the ordinal scheme is opaque until
Phase 2 wires calendar arithmetic. What Phase 1 DOES nail down is:
same-freq Periods compare + subtract; Period + i64 shifts by n
periods of the declared frequency.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Annual(u8)
Y-<MON> / A / Y — annual periods of a fiscal year ending in the
month carried (1-12; Y is Y-DEC). The ordinal counts fiscal years
from 1970: Period('2024', 'Y-JUN') spans 2023-07-01..2024-06-30.
Quarterly(u8)
Q-<MON> / Q — quarters of a fiscal year ending in the month
carried (1-12; Q is Q-DEC): Period('2025Q1', 'Q-JAN') spans
2024-02-01..2024-04-30.
Monthly
M — monthly periods.
Weekly(u8)
W-<DAY> / W — weeks ending on the weekday carried (0 = Monday ..
6 = Sunday; W is W-SUN).
Daily
D — daily periods.
Business
B — business-day periods.
Hourly
h / H — hourly periods.
Minutely
min / T — minutely periods.
Secondly
s / S — secondly periods.
Milliseconds
ms — millisecond periods. NOT MS, which pandas reads as month start.
Microseconds
us / US — microsecond periods.
Nanoseconds
ns / NS — nanosecond periods.
Implementations§
Source§impl PeriodFreq
impl PeriodFreq
Sourcepub const fn fiscal_month_shift(self) -> i64
pub const fn fiscal_month_shift(self) -> i64
Months a date’s month count moves forward to land on its fiscal
calendar: a fiscal year ending in month m starts in month m + 1,
so (months since 1970-01 + shift) divided by 12 (3) is the annual
(quarterly) ordinal. 0 for a year ending in December and for every
unanchored frequency.
Sourcepub const fn week_start_shift(self) -> i64
pub const fn week_start_shift(self) -> i64
Days a week starts after the Monday of W-SUN’s week: a week ending
on weekday d (Monday 0) starts on d + 1, so W-MON weeks start a
day later and W-SAT ones six days later (a Sunday). 0 for W-SUN
and every other frequency.
Sourcepub fn parse(alias: &str) -> Option<Self>
pub fn parse(alias: &str) -> Option<Self>
Parse a pandas-style frequency alias. Recognizes the common subset
(Y-
Case-insensitive with ONE exception: bare MS is month start in pandas,
not milliseconds, and is refused here the way pandas refuses it for
to_period. See the check at the top of the body.
Sourcepub const fn resolution(self) -> Option<&'static str>
pub const fn resolution(self) -> Option<&'static str>
Resolution word for PeriodIndex.resolution, or None where pandas has
no answer.
⚠️ THIS IS NOT THE ALIAS TABLE. pandas’ .resolution names the period’s
component, in the same vocabulary DatetimeIndex::resolution already
uses here – it is not the frequency string, which is what
PeriodFreq::alias is for. MEASURED, live pandas 2.2.3, one-element
PeriodIndex per freq:
Y -> ‘year’ Q -> ‘quarter’ M -> ‘month’
D -> ‘day’ h -> ‘hour’ min-> ‘minute’
s -> ‘second’
W -> raises AttributeError
B -> raises AttributeError
Every arm below previously returned the alias instead (“A-DEC”, “M”, “H”,
“T”, “S”, …), so all nine disagreed with the incumbent; W and B answered
where pandas refuses. The refusal is modelled as None rather than a
wrong word, because the caller already returns Option for the empty
index and pandas’ own failure there is an absence, not a value.