polars_schema::schema

Struct Schema

Source
pub struct Schema<D> { /* private fields */ }

Implementations§

Source§

impl<D> Schema<D>

Source

pub fn with_capacity(capacity: usize) -> Self

Source

pub fn reserve(&mut self, additional: usize)

Reserve additional memory spaces in the schema.

Source

pub fn len(&self) -> usize

The number of fields in the schema.

Source

pub fn is_empty(&self) -> bool

Source

pub fn rename(&mut self, old: &str, new: PlSmallStr) -> Option<PlSmallStr>

Rename field old to new, and return the (owned) old name.

If old is not present in the schema, the schema is not modified and None is returned. Otherwise the schema is updated and Some(old_name) is returned.

Source

pub fn insert(&mut self, key: PlSmallStr, value: D) -> Option<D>

Source

pub fn insert_at_index( &mut self, index: usize, name: PlSmallStr, dtype: D, ) -> PolarsResult<Option<D>>

Insert a field with name and dtype at the given index into this schema.

If a field named name already exists, it is updated with the new dtype. Regardless, the field named name is always moved to the given index. Valid indices range from 0 (front of the schema) to self.len() (after the end of the schema).

For a non-mutating version that clones the schema, see new_inserting_at_index.

Runtime: O(n) where n is the number of fields in the schema.

Returns:

  • If index is out of bounds, Err(PolarsError)
  • Else if name was already in the schema, Ok(Some(old_dtype))
  • Else Ok(None)
Source

pub fn get(&self, name: &str) -> Option<&D>

Get a reference to the dtype of the field named name, or None if the field doesn’t exist.

Source

pub fn try_get(&self, name: &str) -> PolarsResult<&D>

Get a reference to the dtype of the field named name, or Err(PolarsErr) if the field doesn’t exist.

Source

pub fn try_get_mut(&mut self, name: &str) -> PolarsResult<&mut D>

Get a mutable reference to the dtype of the field named name, or Err(PolarsErr) if the field doesn’t exist.

Source

pub fn get_full(&self, name: &str) -> Option<(usize, &PlSmallStr, &D)>

Return all data about the field named name: its index in the schema, its name, and its dtype.

Returns Some((index, &name, &dtype)) if the field exists, None if it doesn’t.

Source

pub fn try_get_full(&self, name: &str) -> PolarsResult<(usize, &PlSmallStr, &D)>

Return all data about the field named name: its index in the schema, its name, and its dtype.

Returns Ok((index, &name, &dtype)) if the field exists, Err(PolarsErr) if it doesn’t.

Source

pub fn get_at_index(&self, index: usize) -> Option<(&PlSmallStr, &D)>

Get references to the name and dtype of the field at index.

If index is inbounds, returns Some((&name, &dtype)), else None. See get_at_index_mut for a mutable version.

Source

pub fn try_get_at_index(&self, index: usize) -> PolarsResult<(&PlSmallStr, &D)>

Source

pub fn get_at_index_mut( &mut self, index: usize, ) -> Option<(&mut PlSmallStr, &mut D)>

Get mutable references to the name and dtype of the field at index.

If index is inbounds, returns Some((&mut name, &mut dtype)), else None. See get_at_index for an immutable version.

Source

pub fn remove(&mut self, name: &str) -> Option<D>

Swap-remove a field by name and, if the field existed, return its dtype.

If the field does not exist, the schema is not modified and None is returned.

This method does a swap_remove, which is O(1) but changes the order of the schema: the field named name is replaced by the last field, which takes its position. For a slower, but order-preserving, method, use shift_remove.

Source

pub fn shift_remove(&mut self, name: &str) -> Option<D>

Remove a field by name, preserving order, and, if the field existed, return its dtype.

If the field does not exist, the schema is not modified and None is returned.

This method does a shift_remove, which preserves the order of the fields in the schema but is O(n). For a faster, but not order-preserving, method, use remove.

Source

pub fn shift_remove_index(&mut self, index: usize) -> Option<(PlSmallStr, D)>

Remove a field by name, preserving order, and, if the field existed, return its dtype.

If the field does not exist, the schema is not modified and None is returned.

This method does a shift_remove, which preserves the order of the fields in the schema but is O(n). For a faster, but not order-preserving, method, use remove.

Source

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

Whether the schema contains a field named name.

Source

pub fn set_dtype(&mut self, name: &str, dtype: D) -> Option<D>

Change the field named name to the given dtype and return the previous dtype.

If name doesn’t already exist in the schema, the schema is not modified and None is returned. Otherwise returns Some(old_dtype).

This method only ever modifies an existing field and never adds a new field to the schema. To add a new field, use with_column or insert_at_index.

Source

pub fn set_dtype_at_index(&mut self, index: usize, dtype: D) -> Option<D>

Change the field at the given index to the given dtype and return the previous dtype.

If the index is out of bounds, the schema is not modified and None is returned. Otherwise returns Some(old_dtype).

This method only ever modifies an existing index and never adds a new field to the schema. To add a new field, use with_column or insert_at_index.

Source

pub fn with_column(&mut self, name: PlSmallStr, dtype: D) -> Option<D>

Insert a new column in the Schema.

If an equivalent name already exists in the schema: the name remains and retains in its place in the order, its corresponding value is updated with [D] and the older dtype is returned inside Some(_).

If no equivalent key existed in the map: the new name-dtype pair is inserted, last in order, and None is returned.

To enforce the index of the resulting field, use insert_at_index.

Computes in O(1) time (amortized average).

Source

pub fn merge(&mut self, other: Self)

Merge other into self.

Merging logic:

  • Fields that occur in self but not other are unmodified
  • Fields that occur in other but not self are appended, in order, to the end of self
  • Fields that occur in both self and other are updated with the dtype from other, but keep their original index
Source

pub fn iter(&self) -> impl ExactSizeIterator<Item = (&PlSmallStr, &D)> + '_

Iterates over the (&name, &dtype) pairs in this schema.

For an owned version, use [iter_fields][Self::iter_fields], which clones the data to iterate owned Fields

Source

pub fn iter_mut( &mut self, ) -> impl ExactSizeIterator<Item = (&PlSmallStr, &mut D)> + '_

Source

pub fn iter_names(&self) -> impl '_ + ExactSizeIterator<Item = &PlSmallStr>

Iterates over references to the names in this schema.

Source

pub fn iter_names_cloned( &self, ) -> impl '_ + ExactSizeIterator<Item = PlSmallStr>

Source

pub fn iter_values(&self) -> impl '_ + ExactSizeIterator<Item = &D>

Iterates over references to the dtypes in this schema.

Source

pub fn into_iter_values(self) -> impl ExactSizeIterator<Item = D>

Source

pub fn iter_values_mut(&mut self) -> impl '_ + ExactSizeIterator<Item = &mut D>

Iterates over mut references to the dtypes in this schema.

Source

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

Source

pub fn try_index_of(&self, name: &str) -> PolarsResult<usize>

Source§

impl<D> Schema<D>
where D: Clone + Default,

Source

pub fn new_inserting_at_index( &self, index: usize, name: PlSmallStr, field: D, ) -> PolarsResult<Self>

Create a new schema from this one, inserting a field with name and dtype at the given index.

If a field named name already exists, it is updated with the new dtype. Regardless, the field named name is always moved to the given index. Valid indices range from 0 (front of the schema) to self.len() (after the end of the schema).

For a mutating version that doesn’t clone, see insert_at_index.

Runtime: O(m * n) where m is the (average) length of the field names and n is the number of fields in the schema. This method clones every field in the schema.

Returns: Ok(new_schema) if index <= self.len(), else Err(PolarsError)

Source

pub fn merge_from_ref(&mut self, other: &Self)

Merge borrowed other into self.

Merging logic:

  • Fields that occur in self but not other are unmodified
  • Fields that occur in other but not self are appended, in order, to the end of self
  • Fields that occur in both self and other are updated with the dtype from other, but keep their original index
Source

pub fn try_project<I>(&self, columns: I) -> PolarsResult<Self>
where I: IntoIterator, I::Item: AsRef<str>,

Generates another schema with just the specified columns selected from this one.

Source

pub fn try_project_indices(&self, indices: &[usize]) -> PolarsResult<Self>

Source

pub fn filter<F: Fn(usize, &D) -> bool>(self, predicate: F) -> Self

Returns a new Schema with a subset of all fields whose predicate evaluates to true.

Trait Implementations§

Source§

impl<D: Clone> Clone for Schema<D>

Source§

fn clone(&self) -> Schema<D>

Returns a copy 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<D: Debug> Debug for Schema<D>

Source§

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

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

impl<D: Default> Default for Schema<D>

Source§

fn default() -> Schema<D>

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

impl<D> From<IndexMap<PlSmallStr, D, RandomState>> for Schema<D>

Source§

fn from(fields: PlIndexMap<PlSmallStr, D>) -> Self

Converts to this type from the input type.
Source§

impl<F, D> FromIterator<F> for Schema<D>
where F: Into<(PlSmallStr, D)>,

Source§

fn from_iter<I: IntoIterator<Item = F>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<D: Hash> Hash for Schema<D>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<D> IntoIterator for Schema<D>

Source§

type IntoIter = <IndexMap<PlSmallStr, D, RandomState> as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?
Source§

type Item = (PlSmallStr, D)

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<D: PartialEq> PartialEq for Schema<D>

Source§

fn eq(&self, other: &Self) -> 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<D: Eq> Eq for Schema<D>

Auto Trait Implementations§

§

impl<D> Freeze for Schema<D>

§

impl<D> RefUnwindSafe for Schema<D>
where D: RefUnwindSafe,

§

impl<D> Send for Schema<D>
where D: Send,

§

impl<D> Sync for Schema<D>
where D: Sync,

§

impl<D> Unpin for Schema<D>
where D: Unpin,

§

impl<D> UnwindSafe for Schema<D>
where D: UnwindSafe,

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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, 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.