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: IndexKindThe label storage / kind.
Implementations§
Source§impl Index
impl Index
Sourcepub fn datetime(labels: Vec<i64>, tz: Tz) -> Index
pub fn datetime(labels: Vec<i64>, tz: Tz) -> Index
An unnamed datetime index (UTC-ns labels, tagged with tz).
Sourcepub fn with_name(self, name: Option<String>) -> Index
pub fn with_name(self, name: Option<String>) -> Index
Return this index with its name set (builder; consumes self).
Sourcepub fn from_column(col: &Column) -> Result<Index>
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.
Sourcepub fn from_column_tz(col: &Column, tz: Tz) -> Result<Index>
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.
Sourcepub fn with_tz(self, tz: Tz) -> Index
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.
Sourcepub fn label_at(&self, i: usize) -> Label
pub fn label_at(&self, i: usize) -> Label
The label at position i (for membership tests like drop).
Sourcepub fn to_i64_labels(&self) -> Vec<i64>
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).
Sourcepub fn slice(&self, start: usize, end: usize) -> Index
pub fn slice(&self, start: usize, end: usize) -> Index
A [start, end) slice (the name and a datetime tz are preserved).
Sourcepub fn take(&self, idx: &[usize]) -> Index
pub fn take(&self, idx: &[usize]) -> Index
Gather the given positions (the name and a datetime tz are preserved).
Sourcepub fn label_eq(&self, other: &Index) -> bool
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.
Sourcepub fn argsort(&self, ascending: bool) -> Vec<usize>
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.
Sourcepub fn append(&self, other: &Index) -> Result<Index>
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.
Sourcepub fn extend(&mut self, other: &Index) -> Result<()>
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.
Sourcepub fn position_of(&self, label: &Label) -> Option<usize>
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.
Sourcepub fn label_slice(
&self,
lo: Option<&Label>,
hi: Option<&Label>,
) -> (usize, usize)
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.