Skip to main content

assert_schema_equal

Function assert_schema_equal 

Source
pub fn assert_schema_equal(
    left_schema: &Schema,
    right_schema: &Schema,
    check_dtypes: bool,
    check_column_order: bool,
) -> PolarsResult<()>
Expand description

Compares schemas for equality based on specified criteria.

This function validates that two schemas have compatible schemas by checking column names, their order, and optionally their data types according to the provided configuration parameters.

§Arguments

  • left - The first schema to compare
  • right - The second schema to compare
  • check_dtypes - If true, requires data types to match for corresponding columns
  • check_column_order - If true, requires columns to appear in the same order

§Returns

  • Ok(()) if schemas match according to specified criteria
  • Err with details about schema mismatches if schemas differ

§Behavior

The function performs schema validation in the following order:

  1. Fast path: Returns immediately if schemas are identical
  2. Column name validation: Ensures both schemas have the same set of column names
    • Reports columns present in left but missing in right
    • Reports columns present in right but missing in left
  3. Column order validation: If check_column_order is true, verifies columns appear in the same sequence
  4. Data type validation: If check_dtypes is true, ensures corresponding columns have matching data types
    • When check_column_order is false, compares data type sets for equality
    • When check_column_order is true, performs more precise type checking