From 90a2824241604371053d220402c1ea09f252de7e Mon Sep 17 00:00:00 2001 From: Simon Lin Date: Wed, 4 Sep 2024 14:50:53 +1000 Subject: [PATCH] c --- crates/polars-core/src/schema.rs | 36 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/crates/polars-core/src/schema.rs b/crates/polars-core/src/schema.rs index cfc761287701..0bf6f1bb2045 100644 --- a/crates/polars-core/src/schema.rs +++ b/crates/polars-core/src/schema.rs @@ -11,32 +11,14 @@ pub type Schema = polars_schema::schema::Schema; pub trait SchemaExt { fn from_arrow_schema(value: &ArrowSchema) -> Self; - /// 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]. fn get_field(&self, name: &str) -> Option; - /// 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]. fn try_get_field(&self, name: &str) -> PolarsResult; - /// Convert self to `ArrowSchema` by cloning the fields. fn to_arrow(&self, compat_level: CompatLevel) -> ArrowSchema; - /// Iterates the [`Field`]s 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)`. fn iter_fields(&self) -> impl ExactSizeIterator + '_; - /// Take another [`Schema`] and try to find the supertypes between them. fn to_supertype(&mut self, other: &Schema) -> PolarsResult; } @@ -49,17 +31,30 @@ impl SchemaExt for Schema { .collect() } + /// 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]. fn get_field(&self, name: &str) -> Option { self.get_full(name) .map(|(_, name, dtype)| Field::new(name.clone(), dtype.clone())) } + /// 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]. fn try_get_field(&self, name: &str) -> PolarsResult { self.get_full(name) .ok_or_else(|| polars_err!(SchemaFieldNotFound: "{}", name)) .map(|(_, name, dtype)| Field::new(name.clone(), dtype.clone())) } + /// Convert self to `ArrowSchema` by cloning the fields. fn to_arrow(&self, compat_level: CompatLevel) -> ArrowSchema { let fields: Vec<_> = self .iter() @@ -68,11 +63,16 @@ impl SchemaExt for Schema { ArrowSchema::from(fields) } + /// Iterates the [`Field`]s 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)`. fn iter_fields(&self) -> impl ExactSizeIterator + '_ { self.iter() .map(|(name, dtype)| Field::new(name.clone(), dtype.clone())) } + /// Take another [`Schema`] and try to find the supertypes between them. fn to_supertype(&mut self, other: &Schema) -> PolarsResult { polars_ensure!(self.len() == other.len(), ComputeError: "schema lengths differ");