{"record":{"id":"ce02c3ab5c8509a9","repo":"pandas-dev/pandas","slug":"left-and-right-must-have-the-same-time-zone-got","errorCode":null,"errorMessage":"left and right must have the same time zone, got '{left.tz}' and '{right.tz}'","messagePattern":"left and right must have the same time zone, got '(.+?)' and '(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/interval.py","lineNumber":343,"sourceCode":"            isinstance(left.dtype, CategoricalDtype)\n            or is_string_dtype(left.dtype)\n            or is_string_dtype(right.dtype)\n        ):\n            # GH 19016, GH 66518: reject unsupported right-side dtypes too.\n            msg = (\n                \"category, object, and string subtypes are not supported \"\n                \"for IntervalArray\"\n            )\n            raise TypeError(msg)\n        if isinstance(left, ABCPeriodIndex):\n            msg = \"Period dtypes are not supported, use a PeriodIndex instead\"\n            raise ValueError(msg)\n        if isinstance(left, ABCDatetimeIndex) and str(left.tz) != str(right.tz):\n            msg = (\n                \"left and right must have the same time zone, got \"\n                f\"'{left.tz}' and '{right.tz}'\"\n            )\n            raise ValueError(msg)\n        elif needs_i8_conversion(left.dtype) and left.unit != right.unit:\n            # e.g. m8[s] vs m8[ms], try to cast to a common dtype GH#55714\n            left_arr, right_arr = left._data._ensure_matching_resos(right._data)\n            left = ensure_index(left_arr)\n            right = ensure_index(right_arr)\n\n        # For dt64/td64 we want DatetimeArray/TimedeltaArray instead of ndarray\n        left = ensure_wrapped_if_datetimelike(left)\n        left = extract_array(left, extract_numpy=True)\n        right = ensure_wrapped_if_datetimelike(right)\n        right = extract_array(right, extract_numpy=True)\n\n        if isinstance(left, ArrowExtensionArray) or isinstance(\n            right, ArrowExtensionArray\n        ):\n            pass\n        else:\n            lbase = getattr(left, \"_ndarray\", left)","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/interval.py#L325-L361","documentation":"Raised when both bounds are timezone-aware DatetimeIndex objects but their time zones differ. IntervalArray requires a single consistent tz for both endpoints. Fires at pandas/core/arrays/interval.py:343.","triggerScenarios":"`pd.IntervalIndex.from_arrays(ts_utc, ts_us)`, or constructing from columns sourced from joins of differently-tz-aware datetime data.","commonSituations":"Merging datasets where one side is stored UTC and the other in a local tz; reading parquet/csv that applies different tz inference per column.","solutions":["Localize both to a common tz: `left = left.tz_convert('UTC')`, `right = right.tz_convert('UTC')`.","If one side is tz-naive, localize it first: `left.tz_localize('UTC')`.","Strip tz from both if wall-clock equality is intended: `left.tz_localize(None)`."],"exampleFix":"// before\npd.IntervalIndex.from_arrays(df['start_utc'], df['end_local'])\n// after\npd.IntervalIndex.from_arrays(df['start_utc'].dt.tz_convert('UTC'), df['end_local'].dt.tz_convert('UTC'))","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef align_tz(left, right, target='UTC'):\n    if getattr(left, 'tz', None) is None:\n        left = left.tz_localize(target)\n    else:\n        left = left.tz_convert(target)\n    if getattr(right, 'tz', None) is None:\n        right = right.tz_localize(target)\n    else:\n        right = right.tz_convert(target)\n    return left, right","typeGuard":"def same_tz(left, right) -> bool:\n    return str(getattr(left, 'tz', None)) == str(getattr(right, 'tz', None))","tryCatchPattern":"try:\n    ia = pd.IntervalArray(left, right)\nexcept ValueError as e:\n    if \"same time zone\" in str(e):\n        ia = pd.IntervalArray(left.tz_convert('UTC'), right.tz_convert('UTC'))\n    else:\n        raise","preventionTips":["Standardize all datetime columns to UTC at ingestion.","Assert `str(left.tz) == str(right.tz)` before constructing intervals.","Watch for parquet/csv readers that infer tz differently per column."],"tags":["interval","datetime","timezone","constructor"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}