Struct DataFrame

Source
pub struct DataFrame {
    pub constants: HashMap<Key, DataValue>,
    pub dataframe: ColumnFrame,
    pub metadata: HashMap<String, DataValue>,
}
Expand description

DataFrame holds information about ColumnFrame. This is used to store the data and the metadata for the candidates.

Fields§

§constants: HashMap<Key, DataValue>

Constants for the dataframe - mikro optimization for the data Values which is constant for the whole dataframe are stored here

§dataframe: ColumnFrame

Dataframe with the candidates

§metadata: HashMap<String, DataValue>

Metadata for the dataframe. Here you can store the information about the dataframe

Implementations§

Source§

impl DataFrame

Source

pub fn init() -> Self

Create a new empty DataFrame.

Source

pub fn from_dict(df: HashMap<String, Vec<DataValue>>) -> Self

Create a DataFrame from a dictionary.

df = tdf.DataFrame.from_dict({"a": [1, 2, 3], "b": [4, 5, 6]})
Source

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

Returns the keys of the DataFrame.

Source

pub fn apply(&mut self, function: Bound<'_, PyAny>) -> Result<(), PyErr>

Apply a function to the DataFrame. The function should accept a DataFrame and return a DataFrame.

def my_function(df):
   # Perform some operations on the DataFrame
  return df
/// df = tdf.DataFrame.init()
df.apply(my_function)
Source

pub fn as_numpy_u32<'py>( &self, keys: Option<Vec<String>>, transposed: Option<bool>, py: Python<'py>, ) -> PyResult<Bound<'py, PyArray2<u32>>>

Returns slice from dataframe as numpy.array of uint32 of the given keys. If transposed is true, the keys will be transposed. If keys is None, all keys will be used.

import numpy as np
df = tdf.DataFrame.init()
df.push({"key1": 1, "key2": 2})
df.push({"key1": 11, "key2": 21})
a_np = df.as_numpy_u32(['key1', 'key2'])
assert np.array_equal(a_np, np.array([[1, 11], [2, 21]], dtype=np.uint32))
Source

pub fn as_numpy_u64<'py>( &self, keys: Option<Vec<String>>, transposed: Option<bool>, py: Python<'py>, ) -> PyResult<Bound<'py, PyArray2<u64>>>

Returns slice from dataframe as numpy.array of uint64 of the given keys. If transposed is true, the keys will be transposed. If keys is None, all keys will be used.

import numpy as np
df = tdf.DataFrame.init()
df.push({"key1": 1, "key2": 2})
df.push({"key1": 11, "key2": 21})
a_np = df.as_numpy_u64(['key1', 'key2'])
assert np.array_equal(a_np, np.array([[1, 11], [2, 21]], dtype=np.uint64))
Source

pub fn as_numpy_i32<'py>( &self, keys: Option<Vec<String>>, transposed: Option<bool>, py: Python<'py>, ) -> PyResult<Bound<'py, PyArray2<i32>>>

Returns slice from dataframe as numpy.array of int32 of the given keys. If transposed is true, the keys will be transposed. If keys is None, all keys will be used.

import numpy as np
df = tdf.DataFrame.init()
df.push({"key1": 1, "key2": 2})
df.push({"key1": 11, "key2": 21})
a_np = df.as_numpy_i32(['key1', 'key2'])
assert np.array_equal(a_np, np.array([[1, 11], [2, 21]], dtype=np.int32))
Source

pub fn as_numpy_i64<'py>( &self, keys: Option<Vec<String>>, transposed: Option<bool>, py: Python<'py>, ) -> PyResult<Bound<'py, PyArray2<i64>>>

Returns slice from dataframe as numpy.array of int64 of the given keys. If transposed is true, the keys will be transposed. If keys is None, all keys will be used.

import numpy as np
df = tdf.DataFrame.init()
df.push({"key1": 1, "key2": 2})
df.push({"key1": 11, "key2": 21})
a_np = df.as_numpy_i64(['key1', 'key2'])
assert np.array_equal(a_np, np.array([[1, 11], [2, 21]], dtype=np.int64))
Source

pub fn as_numpy_f32<'py>( &self, keys: Option<Vec<String>>, transposed: Option<bool>, py: Python<'py>, ) -> PyResult<Bound<'py, PyArray2<f32>>>

Returns slice from dataframe as numpy.array of float32 of the given keys. If transposed is true, the keys will be transposed. If keys is None, all keys will be used.

import numpy as np
df = tdf.DataFrame.init()
df.push({"key1": 1, "key2": 2})
df.push({"key1": 11, "key2": 21})
a_np = df.as_numpy_f32(['key1', 'key2'])
assert np.array_equal(a_np, np.array([[1, 11], [2, 21]], dtype=np.float32))
Source

pub fn as_numpy_f64<'py>( &self, keys: Option<Vec<String>>, transposed: Option<bool>, py: Python<'py>, ) -> PyResult<Bound<'py, PyArray2<f64>>>

Returns slice from dataframe as numpy.array of float64 of the given keys. If transposed is true, the keys will be transposed. If keys is None, all keys will be used.

import numpy as np
df = tdf.DataFrame.init()
df.push({"key1": 1, "key2": 2})
df.push({"key1": 11, "key2": 21})
a_np = df.as_numpy_f64(['key1', 'key2'])
assert np.array_equal(a_np, np.array([[1, 11], [2, 21]], dtype=np.float64))
Source

pub fn py_shrink(&mut self)

Source

pub fn py_add_metadata(&mut self, key: String, value: DataValue)

Source

pub fn py_get_metadata(&self, key: &str) -> Option<DataValue>

Source

pub fn py_rename_key(&mut self, key: &str, new_name: &str) -> Result<(), PyErr>

Source

pub fn py_add_alias(&mut self, key: &str, new_name: &str) -> Result<(), PyErr>

Source

pub fn py_select<'py>( &self, py: Python<'py>, keys: Option<Vec<String>>, transposed: Option<bool>, ) -> Result<Bound<'py, PyList>, PyErr>

Selects data from the DataFrame. If keys is None, all keys will be used. If keys is provided, only the specified keys will be selected. Returns a list of lists, where each inner list represents a row of data.

import trs_dataframe as tdf
df = tdf.DataFrame.init()
df.push({"key1": 1, "key2": 2})
df.push({"key1": 11, "key2": 21})
# selected = df.select(["key1", "key2"])
# assert selected == [[1, 2], [11, 21]]
# selected = df.select()
Source

pub fn py_select_column<'py>( &self, py: Python<'py>, key: String, ) -> Result<Bound<'py, PyList>, PyErr>

Selects a column from the DataFrame. If the column does not exist, it will raise a TypeError. Returns a list of values in the selected column.

import trs_dataframe as tdf
df = tdf.DataFrame.init()
df.push({"key1": 1, "key2": 2})
df.push({"key1": 11, "key2": 21})
# selected = df.select_column("key1")
# assert selected == [1, 11]
# selected = df.select_column("key2")
# assert selected == [2, 21]
# selected = df.select_column("non_existing_key")  # Raises TypeError
Source

pub fn py_join( &mut self, other: DataFrame, join_type: JoinRelation, ) -> Result<(), PyErr>

Joins the current DataFrame with another DataFrame. The join type is specified by the join_type parameter. see JoinRelation for available join types.

import trs_dataframe as tdf
df1 = tdf.DataFrame.init()
df1.push({"key1": 1, "key2": 2})
df1.push({"key1": 11, "key2": 21})
df2 = tdf.DataFrame.init()
df2.push({"key1": 1, "key2": 3})
df2.push({"key1": 11, "key2": 23})
df1.join(df2, tei.JoinRelation.extend())
assert df1.select(["key1", "key2"]) == [[1, 2], [11, 21], [1, 3], [11, 23]]
Source

pub fn py_push(&mut self, data: HashMap<Key, DataValue>) -> Result<(), PyErr>

Pushes a new row of data into the DataFrame. The data should be provided as a dictionary where keys are column names and values are the corresponding data values.

import trs_dataframe as tdf
df = tdf.DataFrame.init()
df.push({"key1": 1, "key2": 2})
df.push({"key1": 11, "key2": 21})
Source

pub fn py_add_column( &mut self, key: Key, data: Vec<DataValue>, ) -> Result<(), PyErr>

Adds a new column to the DataFrame. The column is specified by a key and a vector of data values. If the length of the data vector does not match the number of rows in the DataFrame, it will raise a TypeError.

import trs_dataframe as tdf
df = tdf.DataFrame.init()
df.push({"key1": 1, "key2": 2})
df.push({"key1": 11, "key2": 21})
df.add_column("key3", [3, 4])
assert df.select(["key1", "key2", "key3"]) == [[1, 2, 3], [11, 21, 4]]
Source

pub fn add_constant( &mut self, key: Key, feature: DataValue, ) -> Result<(), PyErr>

Source

pub fn filter_by_expression( &mut self, expression: String, ) -> Result<Self, PyErr>

Filters the DataFrame by a given expression. The expression should be a string that can be parsed by the DataFrame’s filter method

import trs_dataframe as tdf
df = tdf.DataFrame.init()
df.push({"key1": 1, "key2": 2})
df.push({"key1": 11, "key2": 21})
df.filter_by_expression("key1 > 5")
assert df.select(["key1", "key2"]) == [[11, 21 ]]
Source

pub fn __iadd__(&mut self, object: Bound<'_, PyAny>) -> Result<(), PyErr>

Source

pub fn __isub__(&mut self, object: Bound<'_, PyAny>) -> Result<(), PyErr>

Source

pub fn __imul__(&mut self, object: Bound<'_, PyAny>) -> Result<(), PyErr>

Source

pub fn __itruediv__(&mut self, object: Bound<'_, PyAny>) -> Result<(), PyErr>

Source

pub fn __len__(&mut self) -> Result<usize, PyErr>

Source§

impl DataFrame

Source

pub fn new<C: Into<ColumnFrame>>(dataframe: C) -> Self

Source

pub fn shrink(&mut self)

Source

pub fn add_metadata(&mut self, key: String, value: DataValue)

Source

pub fn get_metadata(&self, key: &str) -> Option<&DataValue>

Source

pub fn join( &mut self, other: Self, join_type: &JoinRelation, ) -> Result<(), Error>

Source

pub fn apply_function<F>(&mut self, keys: &[Key], func: F) -> Result<(), Error>
where F: FnMut(&[Key], &mut ColumnFrame) -> Result<(), Error>,

Source

pub fn select(&self, keys: Option<&[Key]>) -> Result<Array2<DataValue>, Error>

Source

pub fn select_transposed_typed<D: Extract>(&self, keys: &[Key]) -> Vec<Vec<D>>

Source

pub fn select_column(&self, key: Key) -> Option<ArrayView1<'_, DataValue>>

Source

pub fn select_transposed( &self, keys: Option<&[Key]>, ) -> Result<Array2<DataValue>, Error>

Source

pub fn insert_constant(&mut self, key: Key, value: DataValue)

Source

pub fn push<C: CandidateData>(&mut self, item: C) -> Result<(), Error>

Source

pub fn remove_column(&mut self, keys: &[Key]) -> Result<Self, Error>

Source

pub fn extend(&mut self, items: Self) -> Result<(), Error>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn add_single_column<K: Into<Key>>( &mut self, key: K, values: Array1<DataValue>, ) -> Result<(), Error>

Source

pub fn get_single_column(&self, key: &Key) -> Option<ArrayView1<'_, DataValue>>

Source

pub fn sorted(&self, key: &Key) -> Result<SortedDataFrame<'_>, Error>

Source

pub fn filter(&self, filter: &FilterRules) -> Result<Self, Error>

Trait Implementations§

Source§

impl Clone for DataFrame

Source§

fn clone(&self) -> DataFrame

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 DataFrame

Source§

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

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

impl Default for DataFrame

Source§

fn default() -> DataFrame

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for DataFrame

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 DataFrame

Source§

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

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

impl From<ColumnFrame> for DataFrame

Source§

fn from(dataframe: ColumnFrame) -> Self

Converts to this type from the input type.
Source§

impl From<HashMap<String, ArrayBase<OwnedRepr<DataValue>, Dim<[usize; 1]>>>> for DataFrame

Source§

fn from(dataframe: HashMap<String, Array1<DataValue>>) -> Self

Converts to this type from the input type.
Source§

impl From<HashMap<String, Vec<DataValue>>> for DataFrame

Source§

fn from(dataframe: HashMap<String, Vec<DataValue>>) -> Self

Converts to this type from the input type.
Source§

impl From<SizedHashMap<SmartString<LazyCompact>, Vec<DataValue>>> for DataFrame

Source§

fn from(dataframe: MLChefMap) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<(Key, Vec<DataValue>)>> for DataFrame

Source§

fn from(dataframe: Vec<(Key, Vec<DataValue>)>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<HashMap<Key, DataValue>>> for DataFrame

Source§

fn from(dataframe: Vec<HashMap<Key, DataValue>>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<SizedHashMap<Key, DataValue>>> for DataFrame

Source§

fn from(dataframe: Vec<HashMap<Key, DataValue>>) -> Self

Converts to this type from the input type.
Source§

impl IntoPy<Py<PyAny>> for DataFrame

Source§

fn into_py(self, py: Python<'_>) -> PyObject

👎Deprecated since 0.23.0: IntoPy is going to be replaced by IntoPyObject. See the migration guide (https://pyo3.rs/v0.23.0/migration) for more information.
Performs the conversion.
Source§

impl<'py> IntoPyObject<'py> for DataFrame

Source§

type Target = DataFrame

The Python output type
Source§

type Output = Bound<'py, <DataFrame as IntoPyObject<'py>>::Target>

The smart pointer type to use. Read more
Source§

type Error = PyErr

The type returned in the event of a conversion error.
Source§

fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>

Performs the conversion.
Source§

impl PartialEq for DataFrame

Source§

fn eq(&self, other: &DataFrame) -> 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 PyClass for DataFrame

Source§

type Frozen = False

Whether the pyclass is frozen. Read more
Source§

impl PyClassImpl for DataFrame

Source§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
Source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
Source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
Source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
Source§

type BaseType = PyAny

Base class
Source§

type ThreadChecker = SendablePyClass<DataFrame>

This handles following two situations: Read more
Source§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
Source§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
Source§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
Source§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
Source§

fn items_iter() -> PyClassItemsIter

Source§

fn doc(py: Python<'_>) -> PyResult<&'static CStr>

Rendered class doc
Source§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

Source§

fn dict_offset() -> Option<isize>

Source§

fn weaklist_offset() -> Option<isize>

Source§

impl PyClassNewTextSignature<DataFrame> for PyClassImplCollector<DataFrame>

Source§

fn new_text_signature(self) -> Option<&'static str>

Source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a DataFrame

Source§

type Holder = Option<PyRef<'py, DataFrame>>

Source§

fn extract( obj: &'a Bound<'py, PyAny>, holder: &'a mut Self::Holder, ) -> PyResult<Self>

Source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut DataFrame

Source§

type Holder = Option<PyRefMut<'py, DataFrame>>

Source§

fn extract( obj: &'a Bound<'py, PyAny>, holder: &'a mut Self::Holder, ) -> PyResult<Self>

Source§

impl PyMethods<DataFrame> for PyClassImplCollector<DataFrame>

Source§

fn py_methods(self) -> &'static PyClassItems

Source§

impl PyTypeInfo for DataFrame

Source§

const NAME: &'static str = "DataFrame"

Class name.
Source§

const MODULE: Option<&'static str> = ::core::option::Option::None

Module name, if any.
Source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
Source§

fn type_object(py: Python<'_>) -> Bound<'_, PyType>

Returns the safe abstraction over the type object.
Source§

fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>

👎Deprecated since 0.23.0: renamed to PyTypeInfo::type_object
Deprecated name for PyTypeInfo::type_object.
Source§

fn is_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type or a subclass of this type.
Source§

fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool

👎Deprecated since 0.23.0: renamed to PyTypeInfo::is_type_of
Deprecated name for PyTypeInfo::is_type_of.
Source§

fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type.
Source§

fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool

👎Deprecated since 0.23.0: renamed to PyTypeInfo::is_exact_type_of
Deprecated name for PyTypeInfo::is_exact_type_of.
Source§

impl Serialize for DataFrame

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 DerefToPyAny for DataFrame

Source§

impl StructuralPartialEq for DataFrame

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> FromPyObject<'_> for T
where T: PyClass + Clone,

Source§

fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>

Extracts Self from the bound smart pointer obj. Read more
Source§

impl<'py, T> FromPyObjectBound<'_, 'py> for T
where T: FromPyObject<'py>,

Source§

fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>

Extracts Self from the bound smart pointer obj. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<'py, T> IntoPyObjectExt<'py> for T
where T: IntoPyObject<'py>,

Source§

fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>

Converts self into an owned Python object, dropping type information.
Source§

fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>

Converts self into an owned Python object, dropping type information and unbinding it from the 'py lifetime.
Source§

fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>

Converts self into a Python object. Read more
Source§

impl<T> PyErrArguments for T
where T: for<'py> IntoPyObject<'py> + Send + Sync,

Source§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
Source§

impl<T> PyTypeCheck for T
where T: PyTypeInfo,

Source§

const NAME: &'static str = <T as PyTypeInfo>::NAME

Name of self. This is used in error messages, for example.
Source§

fn type_check(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of Self, which may include a subtype. 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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

Source§

impl<T> Ungil for T
where T: Send,