{"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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/_testing/asserters.py#L772-L808","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nassert_numpy_array_equal(a, b, check_same='same')\n\n// after\nassert_numpy_array_equal(a, b, check_same='copy')","handlingStrategy":"validation","validationCode":"def shares_base(a, b) -> bool:\n    import numpy as np\n    ga = a.base if getattr(a, 'base', None) is not None else a\n    gb = b.base if getattr(b, 'base', None) is not None else b\n    return ga is gb\nassert shares_base(left, right)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use check_same only when you specifically need to test memory sharing.","Prefer value-equality tests for behavior verification."],"tags":["testing","memory-sharing","numpy-arrays"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}