Type Alias Schema

Source
pub type Schema = Schema<DataType>;

Aliased Type§

struct Schema { /* private fields */ }

Implementations

§

impl<D> Schema<D>

pub fn with_capacity(capacity: usize) -> Schema<D>

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

Reserve additional memory spaces in the schema.

pub fn len(&self) -> usize

The number of fields in the schema.

pub fn is_empty(&self) -> bool

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.

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

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

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][Self::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)

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.

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

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

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

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

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

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

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.

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

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.

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][Self::get_at_index_mut] for a mutable version.

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

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][Self::get_at_index] for an immutable version.

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][Self::shift_remove].

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][Self::remove].

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][Self::remove].

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

Whether the schema contains a field named name.

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][Self::with_column] or [insert_at_index][Self::insert_at_index].

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][Self::with_column] or [insert_at_index][Self::insert_at_index].

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

Insert a column into the [Schema].

If the schema already has this column, this instead updates it with the new value and returns the old one. Otherwise, the column is inserted at the end.

To enforce the index of the resulting field, use [insert_at_index][Self::insert_at_index].

pub fn try_insert( &mut self, name: PlSmallStr, value: D, ) -> Result<(), PolarsError>

Raises DuplicateError if this column already exists in the schema.

pub fn hstack_mut( &mut self, columns: impl IntoIterator<Item = impl Into<(PlSmallStr, D)>>, ) -> Result<(), PolarsError>

Performs [Schema::try_insert] for every column.

Raises DuplicateError if a column already exists in the schema.

pub fn hstack( self, columns: impl IntoIterator<Item = impl Into<(PlSmallStr, D)>>, ) -> Result<Schema<D>, PolarsError>

Performs [Schema::try_insert] for every column.

Raises DuplicateError if a column already exists in the schema.

pub fn merge(&mut self, other: Schema<D>)

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

pub fn iter(&self) -> impl ExactSizeIterator

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

pub fn iter_mut(&mut self) -> impl ExactSizeIterator

pub fn iter_names(&self) -> impl ExactSizeIterator

Iterates over references to the names in this schema.

pub fn iter_names_cloned(&self) -> impl ExactSizeIterator

pub fn iter_values(&self) -> impl ExactSizeIterator

Iterates over references to the dtypes in this schema.

pub fn into_iter_values(self) -> impl ExactSizeIterator

pub fn iter_values_mut(&mut self) -> impl ExactSizeIterator

Iterates over mut references to the dtypes in this schema.

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

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

pub fn field_compare<'a, 'b>( &'a self, other: &'b Schema<D>, self_extra: &mut Vec<(usize, (&'a PlSmallStr, &'a D))>, other_extra: &mut Vec<(usize, (&'b PlSmallStr, &'b D))>, )

Compare the fields between two schema returning the additional columns that each schema has.

§

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

pub fn new_inserting_at_index( &self, index: usize, name: PlSmallStr, field: D, ) -> Result<Schema<D>, PolarsError>

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][Self::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)

pub fn merge_from_ref(&mut self, other: &Schema<D>)

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

pub fn try_project<I>(&self, columns: I) -> Result<Schema<D>, PolarsError>
where I: IntoIterator, <I as IntoIterator>::Item: AsRef<str>,

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

pub fn try_project_indices( &self, indices: &[usize], ) -> Result<Schema<D>, PolarsError>

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

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

Trait Implementations

§

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

§

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
§

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

§

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

Formats the value using the given formatter. Read more
§

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

§

fn default() -> Schema<D>

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

impl<'de, D> Deserialize<'de> for Schema<D>
where D: Deserialize<'de>,

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Schema<D>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

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

§

fn extend<T>(&mut self, iter: T)
where T: IntoIterator<Item = F>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<&Row<'_>> for Schema<DataType>

Source§

fn from(row: &Row<'_>) -> Schema<DataType>

Converts to this type from the input type.
§

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

§

fn from(fields: IndexMap<PlSmallStr, D, RandomState>) -> Schema<D>

Converts to this type from the input type.
§

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

§

fn from_iter<I>(iter: I) -> Schema<D>
where I: IntoIterator<Item = F>,

Creates a value from an iterator. Read more
§

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

§

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

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
§

impl<D> IntoIterator for Schema<D>

§

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

Which kind of iterator are we turning this into?
§

type Item = (PlSmallStr, D)

The type of the elements being iterated over.
§

fn into_iter(self) -> <Schema<D> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

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

§

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

Source§

fn get_field(&self, name: &str) -> Option<Field>

Look up the name in the schema and return an owned Field by cloning the data.

Returns None if the field does not exist.

This method constructs the Field by cloning the name and dtype. For a version that returns references, see [get][Self::get] or [get_full][Self::get_full].

Source§

fn try_get_field(&self, name: &str) -> Result<Field, PolarsError>

Look up the name in the schema and return an owned Field by cloning the data.

Returns Err(PolarsErr) if the field does not exist.

This method constructs the Field by cloning the name and dtype. For a version that returns references, see [get][Self::get] or [get_full][Self::get_full].

Source§

fn to_arrow(&self, compat_level: CompatLevel) -> Schema<Field>

Convert self to ArrowSchema by cloning the fields.

Source§

fn iter_fields(&self) -> impl ExactSizeIterator

Iterates the Fields in this schema, constructing them anew by cloning each (&name, &dtype) pair.

Note that this clones each name and dtype in order to form an owned Field. For a clone-free version, use [iter][Self::iter], which returns (&name, &dtype).

Source§

fn to_supertype( &mut self, other: &Schema<DataType>, ) -> Result<bool, PolarsError>

Take another Schema and try to find the supertypes between them.

Source§

fn from_arrow_schema(value: &Schema<Field>) -> Schema<DataType>

Source§

fn project_select(&self, select: &Bitmap) -> Schema<DataType>

Select fields using a bitmap.
Source§

impl SchemaExtPl for Schema<DataType>

Source§

fn matches_schema(&self, other: &Schema<DataType>) -> Result<bool, PolarsError>

Source§

impl SchemaNamesAndDtypes for Schema<DataType>

§

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

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

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