polars_core/datatypes/
schema.rs

1use super::*;
2
3pub trait SchemaExtPl {
4    // Answers if this schema matches the given schema.
5    //
6    // Allows (nested) Null types in this schema to match any type in the schema,
7    // but not vice versa. In such a case Ok(true) is returned, because a cast
8    // is necessary. If no cast is necessary Ok(false) is returned, and an
9    // error is returned if the types are incompatible.
10    fn matches_schema(&self, other: &Schema) -> PolarsResult<bool>;
11}
12
13impl SchemaExtPl for Schema {
14    fn matches_schema(&self, other: &Schema) -> PolarsResult<bool> {
15        polars_ensure!(self.len() == other.len(), SchemaMismatch: "found different number of fields in schema's\n\nLeft schema: {} fields, right schema: {} fields.", self.len(), other.len());
16        let mut cast = false;
17        for (a, b) in self.iter_values().zip(other.iter_values()) {
18            cast |= a.matches_schema_type(b)?;
19        }
20        Ok(cast)
21    }
22}