pola-rs/polars · error · AssertionError

Series are equal (but are expected not to be)

Error message

Series are equal (but are expected not to be)

What it means

assert_series_not_equal asserts that two Series differ; when assert_series_equal succeeds (the series are actually equal) it raises AssertionError 'Series are equal (but are expected not to be)' — a test-helper inversion, not a data error.

Solutions

  1. Print/compare both series to verify a difference actually exists.
  2. Adjust the code expected to mutate the series so it truly changes values.
  3. Relax/tighten equality options (check_names=False, check_dtype=False) if the intended distinction lies outside the compared aspects — only when semantically correct.

Example fix

# before
s2 = s.cast(pl.Int64)  # s already Int64 -> equal
assert_series_not_equal(s, s2)

# after
s2 = s + 1
assert_series_not_equal(s, s2)
Defensive patterns

Strategy: validation

Validate before calling

if s1.equals(s2):
    pytest.fail("series unexpectedly equal; test premise invalid")

Prevention

When it happens

Trigger: Comparing two Series that turn out identical, e.g. timezone conversion that results in the same displayed values, or comparisons where check_names/check_dtype defaults ignore the actual difference.

Common situations: Timezone tests where both series render the same instants; order-sensitive tests where data was already sorted; empty-series comparisons where both are empty.

Related errors


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

Appendix: source

Thrown at py-polars/src/polars/testing/asserts/series.py:228

    _assert_correct_input_type(left, right)
    try:
        assert_series_equal(
            left=left,
            right=right,
            check_dtypes=check_dtypes,
            check_names=check_names,
            check_order=check_order,
            check_exact=check_exact,
            rel_tol=rel_tol,
            abs_tol=abs_tol,
            categorical_as_str=categorical_as_str,
        )
    except AssertionError:
        return
    else:
        msg = "Series are equal (but are expected not to be)"
        raise AssertionError(msg)

View on GitHub (pinned to fe841f959e)