Skip to main content

Period

Struct Period 

Source
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: PeriodFreq

Implementations§

Source§

impl Period

Source

pub const fn new(ordinal: i64, freq: PeriodFreq) -> Self

Source

pub const fn ordinal(&self) -> i64

Integer position on this period’s frequency axis, matching pd.Period.ordinal.

Source

pub const fn freq(&self) -> PeriodFreq

Frequency code for this period, matching pd.Period.freq.

Source

pub const fn freqstr(&self) -> &'static str

Canonical pandas frequency alias, matching pd.Period.freqstr.

Source

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.

Source

pub fn shift(&self, n: i64) -> Self

Shift by n periods of the current frequency. Matches pd.Period + n and pd.Period - n.

Source

pub fn diff(&self, other: &Self) -> Option<i64>

Period-difference in units of the shared frequency. Returns None if freq differs (pandas raises IncompatibleFrequency).

Source

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.

Source

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).

Trait Implementations§

Source§

impl Clone for Period

Source§

fn clone(&self) -> Period

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Period

Source§

impl Debug for Period

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Period

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Period

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Pandas str(Period) form: the calendar string (2024, 2024Q1, 2024-03, 2024-01-15, …). NaT (ordinal i64::MIN) renders NaT.

Source§

impl Eq for Period

Source§

impl Hash for Period

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Period

Source§

fn eq(&self, other: &Period) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Period

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Period

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.