{"record":{"id":"62fdabce717dde6a","repo":"pandas-dev/pandas","slug":"left-base-r-is-right-base-r","errorCode":null,"errorMessage":"{left_base!r} is {right_base!r}","messagePattern":"\\{left_base!r\\} is \\{right_base!r\\}","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"pandas/_testing/asserters.py","lineNumber":793,"sourceCode":"\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\n            msg = f\"{obj} values are different ({np.round(diff, 5)} %)\"\n            raise_assert_detail(obj, msg, left, right, index_values=index_values)\n","sourceCodeStart":775,"sourceCodeEnd":811,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/_testing/asserters.py#L775-L811","documentation":"Raised inside `assert_numpy_array_equal` when `check_same='copy'` is set and the two arrays DO share the same memory base. This asserts that an operation produced an independent copy when the test expected one. The message prints both `.base` values to show they alias the same buffer.","triggerScenarios":"Calling `assert_numpy_array_equal(a, b, check_same='copy')` where `b = a` or `b = a[:]` (a view, not a copy); pandas-internal tests that confirm CoW produced a defensive copy finding that it instead returned the original buffer.","commonSituations":"Copy-on-write regressions; refactors to indexing code; numpy version changes that alter slicing semantics.","solutions":["If a view is now expected, switch to `check_same='same'`.","If a true copy is required, force one at the producing site (`np.ascontiguousarray(x)` or `x.copy()`).","Remove `check_same` for pure value-equality tests."],"exampleFix":"// before\nb = a[:]\nassert_numpy_array_equal(a, b, check_same='copy')\n\n// after\nb = a.copy()\nassert_numpy_array_equal(a, b, check_same='copy')","handlingStrategy":"validation","validationCode":"def are_independent(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 not gb\nassert are_independent(left, right)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use .copy() at producing sites where independence must be guaranteed.","Don't conflate slicing with copying under CoW."],"tags":["testing","memory-sharing","copy-on-write"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}