pandas-dev/pandas · error · AssertionError
{obj} are different {message}
Error message
{obj} are different
{message} What it means
raise_assert_detail (asserters.py:694-735) is the central failure-reporting function for pandas.testing assertions. It assembles a structured message — object name, what differs, [index], [left], [right], optional [diff] and first-diff — and raises AssertionError. It is the body you see when assert_index_equal, assert_series_equal, assert_frame_equal, assert_numpy_array_equal, or assert_extension_array_equal find an actual inequality.
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.
ParametersView on GitHub (pinned to 71959b8cb9)
Solutions
- Read the [left]/[right]/[diff] blocks in the message to locate the first divergence.
- If the difference is floating-point noise, pass check_dtype=False and use rtol/atol (or check_exact=False).
- If index/names differ, set check_names=False or check_index=False only if intentionally skipping that check.
- Fix the data or the expected fixture so the objects truly match.
Example fix
# before — fails on float dtype/values assert_series_equal(pd.Series([1.0]), pd.Series([1.000001])) # after assert_series_equal(pd.Series([1.0]), pd.Series([1.000001]), check_exact=False, rtol=1e-4)
Defensive patterns
Strategy: validation
Validate before calling
# Decide on exactness/tolerance before asserting
import numpy as np
if left.dtype.kind in 'iu' and right.dtype.kind in 'iu':
check_exact = True
else:
check_exact = False # use rtol/atol for floats Try / catch
try:
assert_series_equal(left, right, check_exact=False, rtol=1e-5, atol=1e-8)
except AssertionError as e:
# log the structured diff for diagnosis
raise Prevention
- For float data always pass check_exact=False with explicit rtol/atol.
- Set check_dtype=False when dtype precision (int32/int64) is not material.
- Align timezones and normalize dtypes on both sides before comparing.
When it happens
Trigger: Two pandas objects that are genuinely unequal: differing values, differing shapes/lengths, differing dtype when check_dtype=True, differing names when check_names=True, or differing categorical categories. raise_assert_detail is invoked from inside the assert_*_equal functions after a comparison fails, so hitting it means a real test failure.
Common situations: Float comparisons without rtol/atol; dtype drift (int32 vs int64); timezone-naive vs timezone-aware datetimes; index alignment differences; categorical category ordering; the expected fixture was updated but not the assertion.
Related errors
- {left_base!r} is not {right_base!r}
- {left_base!r} is {right_base!r}
- [datetimelike_compat=True] {left._values} is not equal to {r
- {cls_name} Expected type {cls}, found {type(left)} instead
- {cls_name} Expected type {cls}, found {type(right)} instead
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/34b49ab37ad8de7c.
Report an issue: GitHub.