Skip to main content

DataFrame

Struct DataFrame 

Source
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

Source

pub fn new( names: Vec<String>, columns: Vec<Column>, index: Option<Index>, ) -> Result<DataFrame, VolasError>

Construct a frame from parallel names / columns, validating shape.

Source

pub fn height(&self) -> usize

Number of rows.

Source

pub fn width(&self) -> usize

Number of columns.

Source

pub fn names(&self) -> &[String]

Column names in order.

Source

pub fn index(&self) -> &Arc<Index>

The shared row index.

Source

pub fn columns(&self) -> &[Column]

Columns in order.

Source

pub fn column_pos(&self, name: &str) -> Option<usize>

Position of a column by name (alias-aware).

Source

pub fn has_column(&self, name: &str) -> bool

Whether a column exists (alias-aware).

Source

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.

Source

pub fn take(&self, positions: &[usize]) -> DataFrame

Gather rows by position into a new frame (carries aliases).

Source

pub fn column(&self, name: &str) -> Result<&Column, VolasError>

Borrow a column by name.

Source

pub fn series(&self, name: &str) -> Result<Series, VolasError>

Extract a column as a Series sharing this frame’s index.

Source

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

Source

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

Source

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.

Source

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.

Source

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

Source

pub fn select(&self, names: &[String]) -> Result<DataFrame, VolasError>

Select a subset of columns into a new frame sharing this index.

Source

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

Source

pub fn filter_mask(&self, mask: &[bool]) -> Result<DataFrame, VolasError>

Filter rows by a boolean mask.

Source

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.

Source

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.

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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.

Source

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.

Source

pub fn computed_columns(&self) -> Vec<(String, ComputedMeta)>

Snapshot of the materialized-directive columns (name, meta).

Source

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.

Source

pub fn computed_names(&self) -> Vec<String>

Names of all materialized-directive columns.

Source

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

Source

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.

Source

pub fn invalidate_computed_on_write(&mut self, written_name: &str)

Name-based variant for the df[name] = value whole-column replace path.

Trait Implementations§

Source§

impl Clone for DataFrame

Source§

fn clone(&self) -> DataFrame

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 DataFrame

Source§

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

Formats the value using the given formatter. Read more

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