{"record":{"id":"209e5558a1b28856","repo":"pandas-dev/pandas","slug":"left-base-r-is-not-right-base-r","errorCode":null,"errorMessage":"{left_base!r} is not {right_base!r}","messagePattern":"(.+?) is not (.+?)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"pandas/_testing/asserters.py","lineNumber":790,"sourceCode":"        appropriate assertion message.\n    \"\"\"\n    __tracebackhide__ = True\n\n    # instance validation\n    # Show a detailed error message when classes are different\n    assert_class_equal(left, right, obj=class_obj or obj)\n    # both classes must be an np.ndarray\n    _check_isinstance(left, right, np.ndarray)\n\n    def _get_base(obj: np.ndarray) -> Any:\n        return obj.base if getattr(obj, \"base\", None) is not None else obj\n\n    left_base = _get_base(left)\n    right_base = _get_base(right)\n\n    if check_same == \"same\":\n        if left_base is not right_base:\n            raise AssertionError(f\"{left_base!r} is not {right_base!r}\")\n    elif check_same == \"copy\":\n        if left_base is right_base:\n            raise AssertionError(f\"{left_base!r} is {right_base!r}\")\n\n    def _raise(left: np.ndarray, right: np.ndarray, err_msg: str | None) -> NoReturn:\n        if err_msg is None:\n            if left.shape != right.shape:\n                raise_assert_detail(\n                    obj, f\"{obj} shapes are different\", left.shape, right.shape\n                )\n\n            diff = 0.0\n            for left_arr, right_arr in zip(left, right, strict=True):\n                # count up differences\n                if not array_equivalent(left_arr, right_arr, strict_nan=strict_nan):\n                    diff += 1\n\n            diff = diff * 100.0 / left.size","sourceCodeStart":772,"sourceCodeEnd":808,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/_testing/asserters.py#L772-L808","documentation":"Inside assert_numpy_array_equal (asserters.py:788-790), when check_same='same' the function asserts that left and right numpy arrays share the same underlying base memory (i.e. one is a view/alias of the other). If left_base is not right_base it raises AssertionError(\"{left_base!r} is not {right_base!r}\"). This is an internal testing utility used to verify memory-sharing behavior, not value equality.","triggerScenarios":"Calling assert_numpy_array_equal(a, b, check_same='same') where a and b are distinct arrays (a copy was made, or they were constructed independently). The check looks at the .base attribute (numpy's view-chain root) to decide if they alias the same buffer.","commonSituations":"Pandas-internal tests asserting that an operation returns a view rather than a copy; accidentally passing check_same='same' when you meant to compare values; a refactoring that introduced a copy where a view was expected.","solutions":["If you want value equality, remove check_same (or set it to None) and rely on the default value comparison.","If you genuinely want same-memory, ensure right = left or right = left.view(...) so they share base memory.","For copy-vs-view tests, build the right operand as right = left to satisfy check_same='same'."],"exampleFix":"# before\nassert_numpy_array_equal(arr, arr.copy(), check_same='same')\n\n# after\nassert_numpy_array_equal(arr, arr, check_same='same')","handlingStrategy":"validation","validationCode":"def same_base(a, b):\n    la = a.base if getattr(a, 'base', None) is not None else a\n    lb = b.base if getattr(b, 'base', None) is not None else b\n    return la is lb\n# only call check_same='same' when same_base(left, right) is True","typeGuard":"import numpy as np\n\ndef shares_base(a: np.ndarray, b: np.ndarray) -> bool:\n    la = a.base if getattr(a, 'base', None) is not None else a\n    lb = b.base if getattr(b, 'base', None) is not None else b\n    return la is lb","tryCatchPattern":null,"preventionTips":["Use check_same only for explicit view/copy semantics tests.","Verify '.base is .base' in a REPL before asserting.","For value equality, omit check_same entirely."],"tags":["testing","assertion","numpy","memory","view","assertionerror"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}