LocalDataFrame

Struct LocalDataFrame 

Source
pub struct LocalDataFrame {
    pub schema: Schema,
    pub data: Vec<Column>,
    pub n_threads: usize,
    /* private fields */
}
Expand description

Represents a local data frame which contains data stored in a columnar format and a well-defined Schema. Is useful for data sets that fit into memory or for testing/debugging purposes.

Fields§

§schema: Schema

The Schema of this data frame

§data: Vec<Column>

The data of this data frame, in columnar format

§n_threads: usize

Number of threads for this computer

Implementations§

Source§

impl LocalDataFrame

An implementation for a LocalDataFrame, inspired by the data frames used in pandas and R.

Source

pub fn from_sor(file_name: &str, from: usize, len: usize) -> Self

Creates a new LocalDataFrame from the given file by reading it in parallel using the number of cores available on this machine. Only reads len bytes of the file, starting at the given byte offset from.

Source

pub fn new(schema: &Schema) -> Self

Creates an empty LocalDataFrame from the given Schema. The LocalDataFrame is created with no rows, but the names of the columns in the given schema are cloned.

Source

pub fn get_schema(&self) -> &Schema

Obtains a reference to the schema of this LocalDataFrame

Source

pub fn add_column( &mut self, col: Column, name: Option<String>, ) -> Result<(), LiquidError>

Adds a Column to this LocalDataFrame with an optional name. Returns a LiquidError::NameAlreadyExists if the given name is not unique.

Source

pub fn get(&self, col_idx: usize, row_idx: usize) -> Result<Data, LiquidError>

Get the Data at the given col_idx, row_idx offsets.

Source

pub fn get_col_idx(&self, col_name: &str) -> Option<usize>

Get the index of the Column with the given col_name. Returns Some if a Column with the given name exists, or None otherwise.

Source

pub fn col_name(&self, col_idx: usize) -> Result<Option<&str>, LiquidError>

Given a column index, returns its name

Source

pub fn set_string( &mut self, col_idx: usize, row_idx: usize, data: String, ) -> Result<(), LiquidError>

Mutates the value in this DataFrame at the given col_idx, row_idx to be changed to the given data.

Source

pub fn set_bool( &mut self, col_idx: usize, row_idx: usize, data: bool, ) -> Result<(), LiquidError>

Mutates the value in this DataFrame at the given col_idx, row_idx to be changed to the given data.

Source

pub fn set_float( &mut self, col_idx: usize, row_idx: usize, data: f64, ) -> Result<(), LiquidError>

Mutates the value in this DataFrame at the given col_idx, row_idx to be changed to the given data.

Source

pub fn set_int( &mut self, col_idx: usize, row_idx: usize, data: i64, ) -> Result<(), LiquidError>

Mutates the value in this DataFrame at the given col_idx, row_idx to be changed to the given data.

Source

pub fn fill_row( &self, row_index: usize, row: &mut Row, ) -> Result<(), LiquidError>

Set the fields of the given Row struct with values from this DataFrame at the given row_index.

If the row does not have the same schema as this DataFrame, a LiquidError::TypeMismatch error will be returned.

Source

pub fn add_row(&mut self, row: &Row) -> Result<(), LiquidError>

Add a Row at the end of this DataFrame.

If the row does not have the same schema as this DataFrame, a LiquidError::TypeMismatch error will be returned.

Source

pub fn map<T: Rower>(&self, rower: T) -> T

Applies the given rower synchronously to every row in this LocalDataFrame

Since map takes an immutable reference to self, the rower can not mutate this DataFrame. If mutation is desired, the rower must create its own DataFrame internally, clone each Row from this DataFrame as it visits them, and mutate the cloned row during each visit.

Source

pub fn pmap<T: Rower + Clone + Send>(&self, rower: T) -> T

Applies the given rower to every row sequentially in this DataFrame The rower is cloned n_threads times, according to the value of n_threads for this LocalDataFrame. Each rower gets operates on a chunk of this LocalDataFrame and are run in parallel.

Since pmap takes an immutable reference to self, the rower can not mutate this LocalDataFrame. If mutation is desired, the rower must create its own LocalDataFrame internally by building one up as it visit rows, and mutates that.

n_threads defaults to the number of cores available on this machine.

Source

pub fn filter<T: Rower>(&self, rower: &mut T) -> Self

Creates a new LocalDataFrame by applying the given rower to every row sequentially in this LocalDataFrame and cloning rows for which the given rower returns true from its accept method. Is run synchronously.

Source

pub fn pfilter<T: Rower + Clone + Send>(&self, rower: &mut T) -> Self

Creates a new LocalDataFrame by applying the given rower to every row in this data frame sequentially, and cloning rows for which the given rower returns true from its accept method. The rower is cloned n_threads times, according to the value of n_threads for this LocalDataFrame. Each rower gets operates on a chunk of this LocalDataFrame and are run in parallel.

n_threads defaults to the number of cores available on this machine.

Source

pub fn combine(self, other: Self) -> Result<Self, LiquidError>

Consumes this LocalDataFrame and the other given LocalDataFrame, returning a combined LocalDataFrame if successful.

  • The columns names and the number of threads for the resulting LocalDataFrame are from this LocalDataFrame and the column names and n_threads in other are ignored
  • The data of other is appended to the data of this LocalDataFrame
§Errors

If the schema of this LocalDataFrame and other have different DataTypes

Source

pub fn n_rows(&self) -> usize

Return the number of rows in this DataFrame.

Source

pub fn n_cols(&self) -> usize

Return the number of columns in this DataFrame.

Trait Implementations§

Source§

impl Clone for LocalDataFrame

Source§

fn clone(&self) -> LocalDataFrame

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for LocalDataFrame

Source§

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

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

impl DeepSizeOf for LocalDataFrame

Source§

fn deep_size_of_children(&self, context: &mut Context) -> usize

Returns an estimation of the heap-managed storage of this object. This does not include the size of the object itself. Read more
Source§

fn deep_size_of(&self) -> usize

Returns an estimation of a total size of memory owned by the object, including heap-managed storage. Read more
Source§

fn recurse_deep_size_of(&self, context: &mut Context) -> usize

👎Deprecated since 0.1.1: use std::mem::size_of_val(val) + val.deep_size_of_children() instead
Deprecated: equivalent to std::mem::size_of_val(val) + val.deep_size_of_children()
Source§

impl<'de> Deserialize<'de> for LocalDataFrame

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 LocalDataFrame

Source§

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

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

impl From<Column> for LocalDataFrame

Source§

fn from(column: Column) -> Self

Construct a new DataFrame with the given column.

Source§

impl From<Data> for LocalDataFrame

Source§

fn from(scalar: Data) -> Self

Construct a new DataFrame with the given scalar value.

Source§

impl From<Vec<Column>> for LocalDataFrame

Source§

fn from(data: Vec<Column>) -> Self

Construct a new DataFrame with the given columns.

Source§

impl PartialEq for LocalDataFrame

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 LocalDataFrame

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 LocalDataFrame

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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