pola-rs/polars · error · panic

{}

Error message

{}

What it means

The assert_frame_equal macro in polars-testing panics with the full mismatch report produced by assert_dataframe_equal when two DataFrames are not equal. The panic message ('{}') is the formatted DataFrameEqualError, which describes which columns, dtypes, or cell values differ. This is a test-side assertion, not a runtime data error.

Solutions

  1. Inspect the printed mismatch report to find the differing column/dtype/value
  2. Use DataFrameEqualOptions (e.g. check_dtype: false, float tolerance/check_row_order) to relax non-essential checks
  3. Round or cast float columns before comparison, or sort both frames if ordering is irrelevant

Example fix

// before
assert_frame_equal!(result, expected);
// after
assert_frame_equal!(
    result,
    expected,
    DataFrameEqualOptions::default().with_float_cmp(rust_decimal::Decimal::from_f64_retain(1e-6).unwrap())
);
Defensive patterns

Strategy: try-catch

Validate before calling

// Rust: pre-check shapes before asserting
assert_eq!(left.height(), right.height());
assert_eq!(left.width(), right.width());
assert_eq!(left.get_column_names(), right.get_column_names());

Try / catch

// in tests, prefer should_panic with a message fragment
#[test]
#[should_panic(expected = "dtypes are not equal")]
fn mismatched_dtypes_fail() { assert_frame_equal!(a, b); }

Prevention

When it happens

Trigger: Invoking assert_frame_equal!(left, right) (optionally with options) where the two frames differ in shape, column names, dtypes, or cell values.

Common situations: Unit tests comparing a computed frame against an expected fixture; float rounding differences; schema drift after a Polars version upgrade; column ordering changes.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/964a84226c525998. Report an issue: GitHub.

Appendix: source

Thrown at crates/polars-testing/src/asserts/frame.rs:49

///     .with_check_row_order(false);
/// assert_dataframe_equal!(&df1, &df2, options);
/// ```
///
/// # Panics
///
/// Panics when the DataFrames are not equal according to the specified comparison criteria.
///
#[macro_export]
macro_rules! assert_dataframe_equal {
    ($left:expr, $right:expr $(, $options:expr)?) => {
        #[allow(unused_assignments)]
        #[allow(unused_mut)]
        let mut options = $crate::asserts::DataFrameEqualOptions::default();
        $(options = $options;)?

        match $crate::asserts::assert_dataframe_equal($left, $right, options) {
            Ok(_) => {},
            Err(e) => panic!("{}", e),
        }
    };
}

#[cfg(test)]
mod tests {
    #[allow(unused_imports)]
    use polars_core::prelude::*;

    // Testing default struct implementation
    #[test]
    fn test_dataframe_equal_options() {
        let options = crate::asserts::DataFrameEqualOptions::default();

        assert!(options.check_row_order);
        assert!(options.check_column_order);
        assert!(options.check_dtypes);
        assert!(!options.check_exact);

View on GitHub (pinned to fe841f959e)