{"record":{"id":"4597bebf2d49d587","repo":"pola-rs/polars","slug":"objects-are-different-detail-n-left-left-n-right-right","errorCode":null,"errorMessage":"{objects} are different ({detail})\\n[left]:  {left}\\n[right]: {right}","messagePattern":"(.+?) are different \\((.+?)\\)\\\\n\\[left\\]:  (.+?)\\\\n\\[right\\]: (.+?)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/testing/asserts/utils.py","lineNumber":12,"sourceCode":"from __future__ import annotations\n\nfrom typing import Any, NoReturn\n\n\ndef raise_assertion_error(\n    objects: str, detail: str, left: Any, right: Any, *, cause: Exception | None = None\n) -> NoReturn:\n    \"\"\"Raise a detailed assertion error.\"\"\"\n    __tracebackhide__ = True\n    msg = f\"{objects} are different ({detail})\\n[left]:  {left}\\n[right]: {right}\"\n    raise AssertionError(msg) from cause\n","sourceCodeStart":1,"sourceCodeEnd":13,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/testing/asserts/utils.py#L1-L13","documentation":"Shared helper that formats and raises the standard polars testing 'X are different (detail)' AssertionError with left/right values. It is the single raise site behind assert_series_equal / assert_frame_equal mismatch details.","triggerScenarios":"Any assert_series_equal/assert_frame_equal call where values, dtypes, names, shapes, or null counts differ; _assert_correct_input_type when a wrong input type is passed to a testing helper.","commonSituations":"Unit tests comparing floats with NaN without check_nan; dtype drift after polars upgrade (Int32 vs Int64); column name mismatches (check_names); null vs NaN comparisons.","solutions":["Read the (detail) field: 'dtype mismatch', 'string_value mismatch', 'shape mismatch', etc., and fix the flagged aspect.","For float data, pass check_exact=False with an appropriate abs_tol/rel_tol.","Align dtypes explicitly with .cast() before comparing if the difference is benign.","Set check_names=False when intentionally comparing series with different names."],"exampleFix":"# before\nassert_series_equal(pl.Series([0.1 + 0.2]), pl.Series([0.3]))  # fails\n\n# after\nassert_series_equal(pl.Series([0.1 + 0.2]), pl.Series([0.3]), check_exact=False, abs_tol=1e-9)","handlingStrategy":"validation","validationCode":"if s1.dtype != s2.dtype:\n    s2 = s2.cast(s1.dtype)\nassert_series_equal(s1, s2)","typeGuard":null,"tryCatchPattern":"try:\n    assert_series_equal(left, right)\nexcept AssertionError as e:\n    print(e)  # detail names the mismatched aspect\n    raise","preventionTips":["Read the (detail) line of the assertion message first","Use check_exact=False with tolerances for floats","Cast dtypes explicitly before comparisons to survive polars upgrades"],"tags":["polars","testing","assertion","comparison"],"backgroundTag":"unexpected-response-shape","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}