{"record":{"id":"2f1ca703eaff001d","repo":"pandas-dev/pandas","slug":"must-not-have-differing-left-type-left-name","errorCode":null,"errorMessage":"must not have differing left [{type(left).__name__}] and right [{type(right).__name__}] types","messagePattern":"must not have differing left \\[(.+?)\\] and right \\[(.+?)\\] types","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/interval.py","lineNumber":323,"sourceCode":"\n            if dtype.closed is None:\n                # possibly loading an old pickle\n                dtype = IntervalDtype(dtype.subtype, closed)\n            elif closed != dtype.closed:\n                raise ValueError(\"closed keyword does not match dtype.closed\")\n\n        # coerce dtypes to match if needed\n        if is_float_dtype(left.dtype) and is_integer_dtype(right.dtype):\n            right = right.astype(left.dtype)\n        elif is_float_dtype(right.dtype) and is_integer_dtype(left.dtype):\n            left = left.astype(right.dtype)\n\n        if type(left) != type(right):\n            msg = (\n                f\"must not have differing left [{type(left).__name__}] and \"\n                f\"right [{type(right).__name__}] types\"\n            )\n            raise ValueError(msg)\n        if (\n            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}'\"","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/interval.py#L305-L341","documentation":"Raised after IntervalArray coerces float/integer mismatches when the underlying Python types of `left` and `right` still differ (e.g., one is a pandas Index and the other a bare numpy array, or one is an ExtensionArray-backed object and the other is not). The IntervalArray requires both sides to be the same array type so it can store them symmetrically. Fires at pandas/core/arrays/interval.py:323.","triggerScenarios":"Mixing an `Index` for one side and a list/ndarray/ExtensionArray for the other when calling `pd.IntervalArray(left, right)` or `IntervalIndex.from_arrays`, or mixing an Arrow-backed array with a numpy-backed one.","commonSituations":"Building intervals where one side comes from a DataFrame column (Index/Series-backed) and the other is computed inline as a Python list or numpy array; mixing pyarrow-backed and numpy-backed data.","solutions":["Wrap both sides in the same container before passing: `pd.Index(left)` and `pd.Index(right)`.","If using ArrowExtensionArray on one side, convert both via `.convert_dtypes(dtype_backend='pyarrow')` or fall back to numpy on both.","Build from equal-typed numpy arrays: `np.asarray(left)`, `np.asarray(right)`."],"exampleFix":"// before\npd.IntervalArray(df['low'].index, np.asarray(df['high']))\n// after\npd.IntervalArray(pd.Index(df['low']), pd.Index(df['high']))","handlingStrategy":"validation","validationCode":"def coerce_interval_inputs(left, right):\n    import pandas as pd\n    left = pd.Index(left)\n    right = pd.Index(right)\n    if type(left) is not type(right):\n        # fall back to plain Index of common dtype\n        left = pd.Index(left.to_numpy())\n        right = pd.Index(right.to_numpy())\n    return left, right","typeGuard":"def same_container_type(left, right) -> bool:\n    return type(left) is type(right)","tryCatchPattern":"try:\n    ia = pd.IntervalArray(left, right)\nexcept ValueError as e:\n    if \"differing left\" in str(e):\n        ia = pd.IntervalArray(pd.Index(left), pd.Index(right))\n    else:\n        raise","preventionTips":["Wrap both bounds in pd.Index before constructing the IntervalArray.","Avoid mixing pyarrow-backed and numpy-backed arrays for the two sides.","Add a fixture in tests that always uses Index on both sides."],"tags":["interval","dtype","constructor","type-mismatch"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}