pandas-dev/pandas · error · AssertionError
is not
Error message
{left_base!r} is not {right_base!r} What it means
Raised inside `assert_numpy_array_equal` when `check_same='same'` is set and the two arrays do NOT share the same memory base. This flag verifies memory-sharing semantics (whether two arrays are views of the same buffer), not value equality. The message prints the `.base` of each side to show which buffer each points to.
Solutions
- If a copy is now expected, change `check_same='same'` to `check_same='copy'`.
- If a view is required, restructure the producing code to slice rather than copy (e.g. `df['x'].values` vs `df['x'].to_numpy()`).
- For value-only tests, omit `check_same` entirely.
Example fix
// before assert_numpy_array_equal(a, b, check_same='same') // after assert_numpy_array_equal(a, b, check_same='copy')
Defensive patterns
Strategy: validation
Validate before calling
def shares_base(a, b) -> bool:
import numpy as np
ga = a.base if getattr(a, 'base', None) is not None else a
gb = b.base if getattr(b, 'base', None) is not None else b
return ga is gb
assert shares_base(left, right) Prevention
- Use check_same only when you specifically need to test memory sharing.
- Prefer value-equality tests for behavior verification.
When it happens
Trigger: Calling `assert_numpy_array_equal(a, b, check_same='same')` where `b` is a copy of `a` rather than a view; testing that an operation returned a view when it actually returned new memory (e.g. after a dtype change or a reset_index).
Common situations: Internal pandas development tests verifying copy/view semantics; refactors that change whether an op returns a view; copy-on-write changes that introduce defensive copies.
Related errors
- {err_msg}
- is
- Cannot override builtin dialect.
- check_like must be False if check_index is False
- Expected type , found instead
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/209e5558a1b28856.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/_testing/asserters.py:790
appropriate assertion message.
"""
__tracebackhide__ = True
# instance validation
# Show a detailed error message when classes are different
assert_class_equal(left, right, obj=class_obj or obj)
# both classes must be an np.ndarray
_check_isinstance(left, right, np.ndarray)
def _get_base(obj: np.ndarray) -> Any:
return obj.base if getattr(obj, "base", None) is not None else obj
left_base = _get_base(left)
right_base = _get_base(right)
if check_same == "same":
if left_base is not right_base:
raise AssertionError(f"{left_base!r} is not {right_base!r}")
elif check_same == "copy":
if left_base is right_base:
raise AssertionError(f"{left_base!r} is {right_base!r}")
def _raise(left: np.ndarray, right: np.ndarray, err_msg: str | None) -> NoReturn:
if err_msg is None:
if left.shape != right.shape:
raise_assert_detail(
obj, f"{obj} shapes are different", left.shape, right.shape
)
diff = 0.0
for left_arr, right_arr in zip(left, right, strict=True):
# count up differences
if not array_equivalent(left_arr, right_arr, strict_nan=strict_nan):
diff += 1
diff = diff * 100.0 / left.sizeView on GitHub (pinned to 3b7651241d)