{"record":{"id":"bcfed529da17683a","repo":"pandas-dev/pandas","slug":"err-msg","errorCode":null,"errorMessage":"{err_msg}","messagePattern":"\\{err_msg\\}","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"pandas/_testing/asserters.py","lineNumber":812,"sourceCode":"\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\n        raise AssertionError(err_msg)\n\n    # compare shape and values\n    if not array_equivalent(left, right, strict_nan=strict_nan):\n        _raise(left, right, err_msg)\n\n    if check_dtype:\n        if isinstance(left, np.ndarray) and isinstance(right, np.ndarray):\n            assert_attr_equal(\"dtype\", left, right, obj=obj)\n\n\n@set_module(\"pandas.testing\")\ndef assert_extension_array_equal(\n    left: ExtensionArray,\n    right: ExtensionArray,\n    check_dtype: bool | Literal[\"equiv\"] = True,\n    index_values: Index | np.ndarray | None = None,\n    check_exact: bool | lib.NoDefault = lib.no_default,\n    rtol: float | lib.NoDefault = lib.no_default,","sourceCodeStart":794,"sourceCodeEnd":830,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/_testing/asserters.py#L794-L830","documentation":"Raised by `assert_numpy_array_equal` when the caller supplies a custom `err_msg` and the arrays turn out not to be equal. When `err_msg` is provided it bypasses pandas' detailed diff formatting and the caller's message is re-raised verbatim. When `err_msg` is None pandas instead builds a richer message with shape and percentage-different detail (other branches).","triggerScenarios":"Calling `assert_numpy_array_equal(left, right, err_msg='my custom diagnostic')` where left and right differ in value or shape; internal pandas asserts that pipe a context message through `err_msg`.","commonSituations":"Test suites that add custom diagnostics to numpy comparisons; running an older test where the underlying data changed.","solutions":["Set `err_msg=None` temporarily to see pandas' detailed diff and pinpoint the mismatch.","Inspect the values of `left` and `right` directly before the assert call.","If shape differs, fix the producing code so both sides have matching dimensions."],"exampleFix":"// before\nassert_numpy_array_equal(left, right, err_msg='arrays differ')\n\n// after\nassert_numpy_array_equal(left, right)  # shows detailed diff","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    assert_numpy_array_equal(left, right)  # err_msg=None\nexcept AssertionError:\n    # your custom diagnostic with full context\n    raise AssertionError(f'pipeline stage X produced mismatch: {left} vs {right}')","preventionTips":["Develop with err_msg=None to see pandas' detailed diff first.","Add err_msg only after the failure root cause is understood."],"tags":["testing","assertions","numpy-arrays"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}