Skip to main content

assert_dataframe_equal

Function assert_dataframe_equal 

Source
pub fn assert_dataframe_equal(
    left: &DataFrame,
    right: &DataFrame,
    options: DataFrameEqualOptions,
) -> PolarsResult<()>
Expand description

Verifies that two DataFrames are equal according to a set of configurable criteria.

This function serves as the main entry point for comparing DataFrames, first validating schema compatibility and then comparing the actual data values column by column.

§Arguments

  • left - The first DataFrame to compare
  • right - The second DataFrame to compare
  • options - A DataFrameEqualOptions struct containing configuration parameters:
    • check_row_order - If true, rows must be in the same order
    • check_column_order - If true, columns must be in the same order
    • check_dtypes - If true, verifies data types match for corresponding columns
    • check_exact - If true, requires exact equality for float values
    • rel_tol - Relative tolerance for float comparison
    • abs_tol - Absolute tolerance for float comparison
    • categorical_as_str - If true, converts categorical values to strings before comparison

§Returns

  • Ok(()) if DataFrames match according to all specified criteria
  • Err with details about the first mismatch encountered:
    • Schema mismatches (column names, order, or data types)
    • Height (row count) mismatch
    • Value mismatches in specific columns

§Order of Checks

  1. Schema validation (column names, order, and data types via assert_dataframe_schema_equal)
  2. DataFrame height (row count)
  3. Row ordering (sorts both DataFrames if check_row_order is false)
  4. Column-by-column value comparison (delegated to assert_series_values_equal)

§Behavior

When check_row_order is false, both DataFrames are sorted using all columns to ensure consistent ordering before value comparison. This allows for row-order-independent equality checking while maintaining deterministic results.