Skip to main content

Index

Struct Index 

Source
pub struct Index {
    pub name: Option<String>,
    pub kind: IndexKind,
}
Expand description

Row labels plus an optional name.

name is index-wide metadata (pandas Index.name): it is recorded by set_index (from the source column), restored by reset_index, and shown in a frame’s / series’ repr. It is None for an unnamed index (the default Range index, a freshly built datetime index, …).

kind is the label storage. A Datetime kind carries its own Tz: storage is always UTC epoch-ns, but the tz governs how those instants render and how bare-string / day-bucket matching maps to wall-clock time (see crate::tz). Both the name and a datetime kind’s tz ride with the shared Arc<Index>, so a frame and every series drawn from it agree on them for free.

Fields§

§name: Option<String>

Optional index name (pandas Index.name); None when unnamed.

§kind: IndexKind

The label storage / kind.

Implementations§

Source§

impl Index

Source

pub fn range(n: usize) -> Index

An unnamed implicit 0..n range index.

Source

pub fn int64(labels: Vec<i64>) -> Index

An unnamed explicit integer index.

Source

pub fn datetime(labels: Vec<i64>, tz: Tz) -> Index

An unnamed datetime index (UTC-ns labels, tagged with tz).

Source

pub fn str(labels: Vec<String>) -> Index

An unnamed string index.

Source

pub fn kind(&self) -> &IndexKind

The label storage / kind.

Source

pub fn name(&self) -> Option<&str>

The index name, if any (pandas Index.name).

Source

pub fn with_name(self, name: Option<String>) -> Index

Return this index with its name set (builder; consumes self).

Source

pub fn from_column(col: &Column) -> Result<Index>

Build an unnamed index from a column (for set_index): a Datetime column becomes a DatetimeIndex, an I64 column an Int64Index, a Str column a string index. Float / bool columns are not valid labels.

Source

pub fn from_column_tz(col: &Column, tz: Tz) -> Result<Index>

Build an unnamed index from a column, tagging a Datetime column with tz (otherwise the tz is ignored).

An I64 / Str column carrying volas.NA is rejected: an int/str index has no missing-label representation, so building one would silently turn each NA into its physical placeholder (0 / "") — an ordinary label a .loc lookup can match (C2/C4). Datetime is the one nullable index kind: NaT is a physical sentinel inside the label vector itself, rendered as NaT and sorted last.

Source

pub fn tz(&self) -> Tz

The timezone of a Datetime index (Tz::Naive for every other kind).

Source

pub fn with_tz(self, tz: Tz) -> Index

Return this index with its timezone set (no-op for a non-datetime index); the name is preserved.

Source

pub fn len(&self) -> usize

Number of labels.

Source

pub fn label_at(&self, i: usize) -> Label

The label at position i (for membership tests like drop).

Source

pub fn is_empty(&self) -> bool

Whether the index is empty.

Source

pub fn to_i64_labels(&self) -> Vec<i64>

Materialize the numeric labels as i64. Numeric indexes only — string indexes are handled by their own paths (label_slice / append guard).

Source

pub fn slice(&self, start: usize, end: usize) -> Index

A [start, end) slice (the name and a datetime tz are preserved).

Source

pub fn take(&self, idx: &[usize]) -> Index

Gather the given positions (the name and a datetime tz are preserved).

Source

pub fn label_eq(&self, other: &Index) -> bool

Value equality of the labels (pandas .equals index semantics): a RangeIndex equals the same integer labels materialized as Int64, but an integer index never equals a datetime or string index. The index name and a datetime tz (display metadata) are ignored.

Source

pub fn argsort(&self, ascending: bool) -> Vec<usize>

The positions that sort the index by label (sort_index). Numeric kinds sort numerically, a string index lexicographically.

Source

pub fn to_column(&self) -> Column

Materialize the labels as a Column (for reset_index).

Source

pub fn append(&self, other: &Index) -> Result<Index>

Concatenate two indexes (extending labels), keeping the left index’s name. Same-kind indexes preserve their kind; mixing numeric kinds yields Int64; mixing a string index with a numeric one is an error.

Source

pub fn extend(&mut self, other: &Index) -> Result<()>

Extend in place by the labels of other — the amortized-O(1) counterpart of append, used by the live single-bar hot path; the growing index keeps its own name (so appending an unnamed bar to a named index does not drop the name). Same-kind indexes grow their buffer; a numeric-kind mix collapses to Int64; mixing a string index with a numeric one is an error.

Source

pub fn position_of(&self, label: &Label) -> Option<usize>

Position of the first label exactly equal to label. Returns None if the label’s kind does not match the index’s kind.

Source

pub fn label_slice( &self, lo: Option<&Label>, hi: Option<&Label>, ) -> (usize, usize)

[start, end) positions covering the inclusive label range [lo, hi] (ascending labels; pandas .loc slice semantics). Either bound may be None for open-ended. Numeric indexes compare numerically; a string index compares lexicographically.

Trait Implementations§

Source§

impl Clone for Index

Source§

fn clone(&self) -> Index

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 Debug for Index

Source§

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

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

impl PartialEq for Index

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Index

Auto Trait Implementations§

§

impl Freeze for Index

§

impl RefUnwindSafe for Index

§

impl Send for Index

§

impl Sync for Index

§

impl Unpin for Index

§

impl UnsafeUnpin for Index

§

impl UnwindSafe for Index

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