pandas-dev/pandas · error · AssertionError

{obj} are different {message} [left]: {left} [right]: {rig

Error message

{obj} are different

{message}
[left]:  {left}
[right]: {right}

What it means

Raised by `raise_assert_detail`, the central failure formatter for pandas' testing asserters. It is the AssertionError surfaced when an equivalence check (lengths, shapes, classes, dtypes, values) finds a real difference. The message bundles the human-readable `[left]`/`[right]` reprs plus an optional `[diff]`, `[index]`, and first-difference block. This is the canonical 'your two objects are not equal' test failure.

Source

Thrown at pandas/_testing/asserters.py:735

    elif isinstance(left, (CategoricalDtype, StringDtype, NumpyEADtype)):
        left = repr(left)

    if isinstance(right, np.ndarray):
        right = pprint_thing(right)
    elif isinstance(right, (CategoricalDtype, StringDtype, NumpyEADtype)):
        right = repr(right)

    msg += f"""
[left]:  {left}
[right]: {right}"""

    if diff is not None:
        msg += f"\n[diff]: {diff}"

    if first_diff is not None:
        msg += f"\n{first_diff}"

    raise AssertionError(msg)


def assert_numpy_array_equal(
    left: Any,
    right: Any,
    strict_nan: bool = False,
    check_dtype: bool | Literal["equiv"] = True,
    err_msg: str | None = None,
    check_same: Literal["copy", "same"] | None = None,
    obj: str = "numpy array",
    index_values: Index | np.ndarray | None = None,
    *,
    class_obj: str | None = None,
) -> None:
    """
    Check that 'np.ndarray' is equivalent.

    Parameters

View on GitHub (pinned to 3b7651241d)

Solutions

  1. Read the `[left]`/`[right]` blocks to identify the exact differing cell or property.
  2. If the difference is floating-point noise, pass `check_exact=False` with appropriate `rtol`/`atol`.
  3. If order is irrelevant, use `check_like=True` (for Series/Index) or sort both sides before asserting.
  4. If dtype is the only diff, set `check_dtype=False` only when the difference is intentional.

Example fix

// before
pd.testing.assert_series_equal(s_a, s_b)

// after
pd.testing.assert_series_equal(s_a, s_b, check_exact=False, rtol=1e-6)
Defensive patterns

Strategy: validation

Validate before calling

if not left.equals(right):
    print(left.compare(right))  # preview the diff before asserting

Try / catch

try:
    pd.testing.assert_frame_equal(a, b, check_exact=False, rtol=1e-6)
except AssertionError as e:
    # save diff to a file for CI artifacts
    raise

Prevention

When it happens

Trigger: Any failed `assert_frame_equal`/`assert_series_equal`/`assert_index_equal` where left and right disagree on values, shape, dtype, or class; calling with `check_like=True` after reindexing that still leaves differences.

Common situations: Data pipeline regression tests where upstream produced a different dtype or rounding; refactors that reorder rows; floating-point comparisons done with default tolerance where rtol is too tight.

Related errors


AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11). Data as JSON: /api/errors/ea8ae02cd2c3769e. Report an issue: GitHub.