pub struct DataFrame { /* private fields */ }Expand description
A 2-D, column-oriented, time-indexed table. All columns share one index and
have equal length (height).
Implementations§
Source§impl DataFrame
impl DataFrame
Sourcepub fn new(
names: Vec<String>,
columns: Vec<Column>,
index: Option<Index>,
) -> Result<DataFrame, VolasError>
pub fn new( names: Vec<String>, columns: Vec<Column>, index: Option<Index>, ) -> Result<DataFrame, VolasError>
Construct a frame from parallel names / columns, validating shape.
Sourcepub fn column_pos(&self, name: &str) -> Option<usize>
pub fn column_pos(&self, name: &str) -> Option<usize>
Position of a column by name (alias-aware).
Sourcepub fn has_column(&self, name: &str) -> bool
pub fn has_column(&self, name: &str) -> bool
Whether a column exists (alias-aware).
Sourcepub fn with_alias(
&self,
as_name: &str,
src_name: &str,
) -> Result<DataFrame, VolasError>
pub fn with_alias( &self, as_name: &str, src_name: &str, ) -> Result<DataFrame, VolasError>
Define a column alias (as_name -> src_name), returning a new frame.
Errors if as_name is already a real column, or src_name does not exist.
Sourcepub fn take(&self, positions: &[usize]) -> DataFrame
pub fn take(&self, positions: &[usize]) -> DataFrame
Gather rows by position into a new frame (carries aliases).
Sourcepub fn series(&self, name: &str) -> Result<Series, VolasError>
pub fn series(&self, name: &str) -> Result<Series, VolasError>
Extract a column as a Series sharing this frame’s index.
Sourcepub fn set_column(&mut self, name: &str, col: Column) -> Result<(), VolasError>
pub fn set_column(&mut self, name: &str, col: Column) -> Result<(), VolasError>
Add a new column or replace an existing one (must match height, unless
the frame currently has no columns).
Sourcepub fn set_index(&self, name: &str) -> Result<DataFrame, VolasError>
pub fn set_index(&self, name: &str) -> Result<DataFrame, VolasError>
Move a column out of the frame and use it as the row index (pandas
set_index). The column is removed; its values become the index
(datetime / int64 — see Index::from_column).
Sourcepub fn tz_convert(&self, tz: Tz) -> Result<DataFrame, VolasError>
pub fn tz_convert(&self, tz: Tz) -> Result<DataFrame, VolasError>
Change the DatetimeIndex’s display / matching timezone without moving
any instant (pandas tz_convert): stored UTC ns are unchanged; only how
they render and how bare-string .loc matches changes. Returns a new frame
(columns shared). Errors if the index is not a DatetimeIndex.
Sourcepub fn set_index_tz(&self, tz: Tz) -> Result<DataFrame, VolasError>
pub fn set_index_tz(&self, tz: Tz) -> Result<DataFrame, VolasError>
Tag the DatetimeIndex’s zone directly, without the naive-axis guard of
Self::tz_convert. For importers (from_pandas) whose instants are
ALREADY true UTC and arrive carrying their zone — not a user-facing API.
Sourcepub fn tz_localize(&self, tz: Tz) -> Result<DataFrame, VolasError>
pub fn tz_localize(&self, tz: Tz) -> Result<DataFrame, VolasError>
Reinterpret the index’s wall-clock as tz (pandas tz_localize): each
instant is recomputed so the displayed wall-clock is unchanged but now
correct for tz. Use this when data was ingested without a tz and you need
to attach the right one. Returns a new frame. Errors if the index is not a
DatetimeIndex or a wall-clock does not exist in tz (a DST spring-forward
gap).
Sourcepub fn select(&self, names: &[String]) -> Result<DataFrame, VolasError>
pub fn select(&self, names: &[String]) -> Result<DataFrame, VolasError>
Select a subset of columns into a new frame sharing this index.
Sourcepub fn slice(&self, start: usize, end: usize) -> DataFrame
pub fn slice(&self, start: usize, end: usize) -> DataFrame
A [start, end) row slice.
Deliberately a value copy (each column’s window is copied), not a zero-copy view into the parent buffer: a slice is an independent frame, so slicing the recent tail of a long history does not pin the whole history alive — the right default for a live system. (A view would be ~1.5x faster here but would retain the parent’s full buffer; we keep the safer copy.)
Sourcepub fn filter_mask(&self, mask: &[bool]) -> Result<DataFrame, VolasError>
pub fn filter_mask(&self, mask: &[bool]) -> Result<DataFrame, VolasError>
Filter rows by a boolean mask.
Sourcepub fn append(&mut self, other: &DataFrame) -> Result<(), VolasError>
pub fn append(&mut self, other: &DataFrame) -> Result<(), VolasError>
Append the rows of other (matched by column name) in place. Columns of
self absent from other are NaN-padded (so a frame with materialized
directive columns can take raw bars; fulfill then refreshes them).
Computed-column metadata is retained, leaving the new rows stale.
Sourcepub fn assign_positions(
&mut self,
col: usize,
positions: &[usize],
values: &Column,
) -> Result<(), VolasError>
pub fn assign_positions( &mut self, col: usize, positions: &[usize], values: &Column, ) -> Result<(), VolasError>
Assign values into column position col at the given row positions
(copy-on-write via Arc::make_mut). values is broadcast when it has
length 1, otherwise its length must equal positions.len(). This backs
df.loc[...] = , df.iloc[...] = , df.at[...] = and df.iat[...] = .
Dtype handling is delegated to Column::scatter, the single assignment
primitive shared with the Series and boolean-mask surfaces: it keeps the
target column’s dtype and updates its validity (a write into an existing NA
cell makes it present; a missing / NaN source marks the cell NA without
widening an int column to float; a present non-integral value into an int
column is a lossy error).
A manual write into a cached directive column drops its computed status
(it becomes plain data) so a later fulfill can never silently clobber the
override.
Sourcepub fn rename(
&self,
mapping: &HashMap<String, String>,
) -> Result<DataFrame, VolasError>
pub fn rename( &self, mapping: &HashMap<String, String>, ) -> Result<DataFrame, VolasError>
Rename columns (pandas rename(columns=...)), returning a new frame.
Names not in mapping are kept; columns and index are shared (cheap).
Sourcepub fn astype(
&self,
mapping: &HashMap<String, DType>,
) -> Result<DataFrame, VolasError>
pub fn astype( &self, mapping: &HashMap<String, DType>, ) -> Result<DataFrame, VolasError>
Cast the named columns to new dtypes (pandas astype), returning a new
frame. Untouched columns are shared (cheap).
Sourcepub fn equals(&self, other: &DataFrame) -> bool
pub fn equals(&self, other: &DataFrame) -> bool
Value equality (pandas DataFrame.equals): same column names + order,
same index labels, and value-equal columns (NaN == NaN). The index
name is metadata and is ignored, matching pandas (.equals ignores it).
Sourcepub fn to_row_major_f64(&self) -> (Vec<f64>, usize, usize)
pub fn to_row_major_f64(&self) -> (Vec<f64>, usize, usize)
Flatten to a row-major (C-order) 2-D f64 buffer for NumPy export,
returning (data, height, width). Each column is materialized through the
validity-aware to_f64_vec, so a missing cell (int/bool NA, datetime NaT,
str) exports as NaN — not the raw placeholder — matching the 1-D
Series export and pandas Int64.to_numpy().
Sourcepub fn to_row_major_i64(&self) -> (Vec<i64>, usize, usize)
pub fn to_row_major_i64(&self) -> (Vec<i64>, usize, usize)
Flatten to a row-major (C-order) 2-D i64 buffer for an exact integer
(or datetime64[ns]) NumPy export, returning (data, height, width). A
datetime column contributes its raw epoch-ns — so sub-2⁵³ ns and NaT
(which stays i64::MIN, the datetime64 sentinel) survive, unlike the
to_row_major_f64 channel — and an i64 column its exact value (no
float round-trip past 2⁵³). A float column truncates toward zero. A str
column has no integer meaning; the export boundary rejects it before
calling this, so it contributes a 0 placeholder it never reaches.
Source§impl DataFrame
impl DataFrame
Sourcepub fn set_computed(&mut self, name: &str, directive: String, lookback: usize)
pub fn set_computed(&mut self, name: &str, directive: String, lookback: usize)
Record that column name is a materialized directive result (valid for
all current rows).
Sourcepub fn set_computed_state(&mut self, name: &str, state: Option<Vec<f64>>)
pub fn set_computed_state(&mut self, name: &str, state: Option<Vec<f64>>)
Attach (or replace) the carried recursive ComputedMeta::state for a
cached column, enabling an O(new-rows) append resume. No-op if name is
not a tracked computed column.
Sourcepub fn has_stale_computed(&self) -> bool
pub fn has_stale_computed(&self) -> bool
Whether any materialized directive column is stale (its valid_rows lags
height after an append), i.e. a bulk read would see NaN until fulfill.
Sourcepub fn computed_columns(&self) -> Vec<(String, ComputedMeta)>
pub fn computed_columns(&self) -> Vec<(String, ComputedMeta)>
Snapshot of the materialized-directive columns (name, meta).
Sourcepub fn stale_computed_columns(
&self,
only: Option<&str>,
) -> Vec<(String, ComputedMeta)>
pub fn stale_computed_columns( &self, only: Option<&str>, ) -> Vec<(String, ComputedMeta)>
Snapshot only stale materialized-directive columns. This keeps the live append/fulfill path from cloning unrelated computed metadata.
Sourcepub fn computed_names(&self) -> Vec<String>
pub fn computed_names(&self) -> Vec<String>
Names of all materialized-directive columns.
Sourcepub fn update_computed_tail(
&mut self,
name: &str,
from: usize,
tail: &Column,
) -> Result<(), VolasError>
pub fn update_computed_tail( &mut self, name: &str, from: usize, tail: &Column, ) -> Result<(), VolasError>
Overwrite a computed column’s rows [from, from + tail.len()) in place
(copy-on-write) with the recomputed tail, and mark it valid up to the
full height. Directive results are F64 or Bool, so both are handled.
O(tail.len()).
Sourcepub fn update_computed_f64_value(
&mut self,
name: &str,
row: usize,
value: f64,
) -> Result<(), VolasError>
pub fn update_computed_f64_value( &mut self, name: &str, row: usize, value: f64, ) -> Result<(), VolasError>
Overwrite one F64 computed value and mark the computed column current. This avoids allocating a one-value tail column on the single-bar append path.
Sourcepub fn invalidate_computed_on_write(&mut self, written_name: &str)
pub fn invalidate_computed_on_write(&mut self, written_name: &str)
Name-based variant for the df[name] = value whole-column replace path.