{"record":{"id":"ec18d0e316331086","repo":"pandas-dev/pandas","slug":"datetimelike-compat-true-left-values-is-not-e","errorCode":null,"errorMessage":"[datetimelike_compat=True] {left._values} is not equal to {right._values}.","messagePattern":"\\[datetimelike_compat=True\\] (.+?) is not equal to (.+?)\\.","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"pandas/_testing/asserters.py","lineNumber":1207,"sourceCode":"                obj=str(obj),\n                class_obj=f\"{obj} values\",\n                index_values=left.index,\n            )\n    elif check_datetimelike_compat and (\n        needs_i8_conversion(left.dtype) or needs_i8_conversion(right.dtype)\n    ):\n        # we want to check only if we have compat dtypes\n        # e.g. integer and M|m are NOT compat, but we can simply check\n        # the values in that case\n\n        # datetimelike may have different objects (e.g. datetime.datetime\n        # vs Timestamp) but will compare equal\n        if not Index(left._values).equals(Index(right._values)):\n            msg = (\n                f\"[datetimelike_compat=True] {left._values} \"\n                f\"is not equal to {right._values}.\"\n            )\n            raise AssertionError(msg)\n    elif isinstance(left.dtype, IntervalDtype) and isinstance(\n        right.dtype, IntervalDtype\n    ):\n        assert_interval_array_equal(\n            cast(\"IntervalArray\", left.array), cast(\"IntervalArray\", right.array)\n        )\n    elif isinstance(left.dtype, CategoricalDtype) or isinstance(\n        right.dtype, CategoricalDtype\n    ):\n        _testing.assert_almost_equal(\n            left._values,\n            right._values,\n            rtol=rtol,\n            atol=atol,\n            check_dtype=bool(check_dtype),\n            obj=str(obj),\n            index_values=left.index,\n        )","sourceCodeStart":1189,"sourceCodeEnd":1225,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/_testing/asserters.py#L1189-L1225","documentation":"Raised by assert_series_equal (asserters.py:1193-1207) in the datetimelike-compat branch. When check_datetimelike_compat=True and one side has a datetime-like dtype (needs_i8_conversion), the code compares the underlying values directly because datetime objects may differ in Python type (datetime.datetime vs Timestamp) yet be equal. If Index(left._values).equals(Index(right._values)) is False, it raises AssertionError with the [datetimelike_compat=True] prefix.","triggerScenarios":"Calling assert_series_equal(left, right, check_datetimelike_compat=True) where one Series is datetime64/datetime tz-aware/period/timedelta and the underlying values genuinely differ (different timestamps, different tz offsets, NaT mismatches). This branch only activates when at least one dtype needs i8 conversion.","commonSituations":"Comparing timezone-aware datetimes across different tz representations; mixing datetime.datetime scalars with pd.Timestamp; period vs datetime confusion; NaT handling differences between the two sides.","solutions":["Inspect the printed left._values vs right._values to find the first differing element.","Normalize timezones on both sides (e.g. .dt.tz_convert('UTC')) before comparing.","If only the Python-level object type differs but instants match, ensure both sides use Timestamp (e.g. pd.to_datetime) so they fall in the standard equality branch.","Re-evaluate whether check_datetimelike_compat=True is needed; remove it if both sides have identical dtypes."],"exampleFix":"# before\nassert_series_equal(\n    pd.Series(pd.to_datetime(['2020-01-01'])),\n    pd.Series(pd.to_datetime(['2020-01-01 00:00:01'])),\n    check_datetimelike_compat=True,\n)\n\n# after — align the values\nassert_series_equal(\n    pd.Series(pd.to_datetime(['2020-01-01'])),\n    pd.Series(pd.to_datetime(['2020-01-01'])),\n)","handlingStrategy":"validation","validationCode":"import pandas as pd\n# normalize tz/dtype before comparing datetimelike series\nleft_n = left.dt.tz_convert('UTC') if left.dt.tz else left\nright_n = right.dt.tz_convert('UTC') if right.dt.tz else right\nassert_series_equal(left_n, right_n)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize timezones on both sides before comparing datetimelike data.","Use pd.to_datetime on both sides so they share Timestamp scalars.","Drop check_datetimelike_compat=True when both dtypes already match."],"tags":["testing","assertion","datetime","tz","assert-series-equal","assertionerror"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}