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: SchemaThe Schema of this data frame
data: Vec<Column>The data of this data frame, in columnar format
n_threads: usizeNumber of threads for this computer
Implementations§
Source§impl LocalDataFrame
An implementation for a LocalDataFrame, inspired by the data frames used
in pandas and R.
impl LocalDataFrame
An implementation for a LocalDataFrame, inspired by the data frames used
in pandas and R.
Sourcepub fn from_sor(file_name: &str, from: usize, len: usize) -> Self
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.
Sourcepub fn new(schema: &Schema) -> Self
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.
Sourcepub fn get_schema(&self) -> &Schema
pub fn get_schema(&self) -> &Schema
Obtains a reference to the schema of this LocalDataFrame
Sourcepub fn add_column(
&mut self,
col: Column,
name: Option<String>,
) -> Result<(), LiquidError>
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.
Sourcepub fn get(&self, col_idx: usize, row_idx: usize) -> Result<Data, LiquidError>
pub fn get(&self, col_idx: usize, row_idx: usize) -> Result<Data, LiquidError>
Get the Data at the given col_idx, row_idx offsets.
Sourcepub fn get_col_idx(&self, col_name: &str) -> Option<usize>
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.
Sourcepub fn col_name(&self, col_idx: usize) -> Result<Option<&str>, LiquidError>
pub fn col_name(&self, col_idx: usize) -> Result<Option<&str>, LiquidError>
Given a column index, returns its name
Sourcepub fn set_string(
&mut self,
col_idx: usize,
row_idx: usize,
data: String,
) -> Result<(), LiquidError>
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.
Sourcepub fn set_bool(
&mut self,
col_idx: usize,
row_idx: usize,
data: bool,
) -> Result<(), LiquidError>
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.
Sourcepub fn set_float(
&mut self,
col_idx: usize,
row_idx: usize,
data: f64,
) -> Result<(), LiquidError>
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.
Sourcepub fn set_int(
&mut self,
col_idx: usize,
row_idx: usize,
data: i64,
) -> Result<(), LiquidError>
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.
Sourcepub fn fill_row(
&self,
row_index: usize,
row: &mut Row,
) -> Result<(), LiquidError>
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.
Sourcepub fn add_row(&mut self, row: &Row) -> Result<(), LiquidError>
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.
Sourcepub fn map<T: Rower>(&self, rower: T) -> T
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.
Sourcepub fn pmap<T: Rower + Clone + Send>(&self, rower: T) -> T
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.
Sourcepub fn filter<T: Rower>(&self, rower: &mut T) -> Self
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.
Sourcepub fn pfilter<T: Rower + Clone + Send>(&self, rower: &mut T) -> Self
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.
Sourcepub fn combine(self, other: Self) -> Result<Self, LiquidError>
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
LocalDataFrameare from thisLocalDataFrameand the column names andn_threadsinotherare ignored - The data of
otheris appended to the data of thisLocalDataFrame
§Errors
If the schema of this LocalDataFrame and other have different
DataTypes
Trait Implementations§
Source§impl Clone for LocalDataFrame
impl Clone for LocalDataFrame
Source§fn clone(&self) -> LocalDataFrame
fn clone(&self) -> LocalDataFrame
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LocalDataFrame
impl Debug for LocalDataFrame
Source§impl DeepSizeOf for LocalDataFrame
impl DeepSizeOf for LocalDataFrame
Source§fn deep_size_of_children(&self, context: &mut Context) -> usize
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§fn deep_size_of(&self) -> usize
fn deep_size_of(&self) -> usize
Source§fn recurse_deep_size_of(&self, context: &mut Context) -> usize
fn recurse_deep_size_of(&self, context: &mut Context) -> usize
std::mem::size_of_val(val) + val.deep_size_of_children() insteadstd::mem::size_of_val(val) + val.deep_size_of_children()Source§impl<'de> Deserialize<'de> for LocalDataFrame
impl<'de> Deserialize<'de> for LocalDataFrame
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for LocalDataFrame
impl Display for LocalDataFrame
Source§impl From<Column> for LocalDataFrame
impl From<Column> for LocalDataFrame
Source§impl From<Data> for LocalDataFrame
impl From<Data> for LocalDataFrame
Source§impl PartialEq for LocalDataFrame
impl PartialEq for LocalDataFrame
Source§impl Serialize for LocalDataFrame
impl Serialize for LocalDataFrame
impl StructuralPartialEq for LocalDataFrame
Auto Trait Implementations§
impl Freeze for LocalDataFrame
impl RefUnwindSafe for LocalDataFrame
impl Send for LocalDataFrame
impl Sync for LocalDataFrame
impl Unpin for LocalDataFrame
impl UnwindSafe for LocalDataFrame
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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