{"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":"validation","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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/interval.py#L305-L341","documentation":"Raised when the Python `type(left)` differs from `type(right)` after dtype coercion (e.g. left is a Series and right is an Index, or left is a plain Index and right is a DatetimeIndex). IntervalArray requires both sides to be the same concrete index subclass so its internals stay symmetric.","triggerScenarios":"`IntervalArray.from_arrays(pd.Series([0,1]), pd.Index([1,2]))`; mixing a DatetimeIndex with a plain Index of timestamps; passing a numpy array on one side and an Index on the other in a way that survives the earlier coercion.","commonSituations":"Constructing intervals from heterogeneous sources (DataFrame column vs Index, db result vs list); refactors that changed one side's container type; unit tests building left/right with different helpers.","solutions":["Wrap both sides in the same container: `pd.Index(left)` and `pd.Index(right)`.","Extract values uniformly with `np.asarray` if you want raw arrays, then pass to from_arrays.","Normalise datetimelike sides with `ensure_wrapped_if_datetimelike` semantics — convert both to DatetimeIndex when dealing with timestamps."],"exampleFix":"# before\nIntervalArray.from_arrays(pd.Series([0,1]), pd.Index([1,2]))\n\n# after\nIntervalArray.from_arrays(pd.Index([0,1]), pd.Index([1,2]))","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef normalise_bounds(left, right):\n    if type(left) != type(right):\n        left = pd.Index(left)\n        right = pd.Index(right)\n    return left, right","typeGuard":"def same_bound_type(left, right) -> bool:\n    return type(left) is type(right)","tryCatchPattern":"try:\n    arr = IntervalArray.from_arrays(left, right)\nexcept ValueError as e:\n    if 'differing left' in str(e):\n        arr = IntervalArray.from_arrays(pd.Index(left), pd.Index(right))\n    else:\n        raise","preventionTips":["Wrap both bounds with pd.Index (or np.asarray) uniformly before from_arrays.","Avoid mixing Series and Index as bound sources.","For datetime bounds, ensure both are DatetimeIndex."],"tags":["interval","type-mismatch","from-arrays","value-error"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}