pola-rs/polars · error · AssertionError
are equal (but are expected not to be)
Error message
{objects} are equal (but are expected not to be) What it means
assert_frame_not_equal first runs assert_frame_equal; if equality succeeds (no AssertionError), the frames ARE equal, so the not-equal assertion fails with this message. It confirms your expectation of difference was wrong.
Solutions
- Inspect both frames (df1.equals(df2), print) to confirm a real difference exists.
- Fix the transformation under test so it actually alters the data.
- If difference is only in dtypes/order you do care about, pass check_dtypes=False / check_column_order=False so equality logic matches intent — but only when the intent is genuinely 'not equal under these criteria'.
Example fix
# before
df2 = df.with_columns(pl.lit(1).alias('x'))
df2 = df2.drop('x') # no-op net effect -> frames equal
assert_frame_not_equal(df, df2) # AssertionError
# after
df2 = df.with_columns(pl.col('x') + 1)
assert_frame_not_equal(df, df2) Defensive patterns
Strategy: validation
Validate before calling
assert not df1.equals(df2), "precondition: frames must differ before assert_frame_not_equal"
Prevention
- Print or diff both frames when a not-equal assertion fails
- Ensure the transformation under test has an observable effect
- Be deliberate about check_dtypes/check_column_order flags vs actual test intent
When it happens
Trigger: Calling assert_frame_not_equal(df1, df2) where the two frames compare identical, including when both are empty LazyFrames or the only intended difference is ignored by the equality options.
Common situations: Testing that a transformation changed data but the transformation is a no-op (e.g. cache bug tests like cspe nondeterminism cases); comparing delta-scanned versions of an unchanged table; forgetting check_dtype/column_order flags that mask real differences.
Related errors
- are different ( )\n[left]: \n[right]
- Series are equal (but are expected not to be)
- invalid profile name
- map keys cannot be a nested dtype, got
- map keys cannot be Null; specify a key type, e.g…
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/b9d252d95b8b02ab.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/testing/asserts/frame.py:240
lazy = _assert_correct_input_type(left, right)
try:
assert_frame_equal(
left=left,
right=right,
check_column_order=check_column_order,
check_row_order=check_row_order,
check_dtypes=check_dtypes,
check_exact=check_exact,
rel_tol=rel_tol,
abs_tol=abs_tol,
categorical_as_str=categorical_as_str,
)
except AssertionError:
return
else:
objects = "LazyFrames" if lazy else "DataFrames"
msg = f"{objects} are equal (but are expected not to be)"
raise AssertionError(msg)
View on GitHub (pinned to fe841f959e)