{"record":{"id":"99cbf9a95bdec9e4","repo":"pandas-dev/pandas","slug":"value-should-be-a-compatible-interval-type-got","errorCode":null,"errorMessage":"'value' should be a compatible interval type, got {type(value)} instead.","messagePattern":"'value' should be a compatible interval type, got (.+?) instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/interval.py","lineNumber":1169,"sourceCode":"    def _validate_listlike(self, value):\n        # list-like of intervals\n        try:\n            array = IntervalArray(value)\n            self._check_closed_matches(array, name=\"value\")\n            value_left, value_right = array.left, array.right\n        except TypeError as err:\n            # wrong type: not interval or NA\n            msg = f\"'value' should be an interval type, got {type(value)} instead.\"\n            raise TypeError(msg) from err\n\n        try:\n            self.left._validate_fill_value(value_left)\n        except (LossySetitemError, TypeError) as err:\n            msg = (\n                \"'value' should be a compatible interval type, \"\n                f\"got {type(value)} instead.\"\n            )\n            raise TypeError(msg) from err\n\n        return value_left, value_right\n\n    def _validate_scalar(self, value):\n        if isinstance(value, Interval):\n            self._check_closed_matches(value, name=\"value\")\n            left, right = value.left, value.right\n            self.left._validate_fill_value(left)\n            self.left._validate_fill_value(right)\n        elif is_valid_na_for_dtype(value, self.left.dtype):\n            # GH#18295\n            left = right = self.left._na_value\n        else:\n            raise TypeError(\n                \"can only insert Interval objects and NA into an IntervalArray\"\n            )\n        return left, right\n","sourceCodeStart":1151,"sourceCodeEnd":1187,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/interval.py#L1151-L1187","documentation":"Raised after the value is successfully parsed as an IntervalArray but its endpoint dtype is rejected by self.left._validate_fill_value (raises LossySetitemError or TypeError). This means the value is interval-shaped but its subtype is incompatible with the target's subtype, e.g. assigning datetime intervals into a numeric-backed IntervalArray. The error distinguishes 'shape ok, dtype wrong' from error 321 ('shape wrong').","triggerScenarios":"Assigning intervals whose endpoints are floats into an int64-backed IntervalArray with values that would truncate, or assigning Timestamp-backed intervals into a numeric interval array, via arr[i] = other_array.","commonSituations":"Mixing interval arrays created with different subtypes (int vs float vs datetime), merging interval columns from heterogeneous sources, or attempting to widen/narrow precision during assignment.","solutions":["Cast the target array to a wider subtype first: arr = arr.astype('interval[float64]') before assignment.","Rebuild the value with endpoints matching arr.dtype.subtype, e.g. pd.Interval(int(left), int(right)).","Confirm closed matches too via arr._check_closed_matches(value) before assigning."],"exampleFix":"# before\narr = pd.arrays.IntervalArray.from_tuples([(0, 1)], dtype='interval[int64]')\narr[0] = pd.Interval(0.5, 1.5)\n\n# after\narr = arr.astype('interval[float64]')\narr[0] = pd.Interval(0.5, 1.5)","handlingStrategy":"validation","validationCode":"def compatible_value(arr, value):\n    iv = value if isinstance(value, pd.Interval) else pd.arrays.IntervalArray(value)\n    sub = iv.left.dtype if isinstance(iv, pd.arrays.IntervalArray) else type(iv.left)\n    if not np.can_cast(sub, arr.dtype.subtype):\n        raise TypeError(f'value subtype {sub} incompatible with {arr.dtype.subtype}')\n    return iv","typeGuard":"def endpoints_compatible(arr, value) -> bool:\n    try:\n        arr.left._validate_fill_value(getattr(value, 'left', value))\n        return True\n    except (TypeError, Exception):\n        return False","tryCatchPattern":"try:\n    arr[i] = value\nexcept TypeError as e:\n    if 'compatible interval type' in str(e):\n        arr = arr.astype('interval[float64]')\n        arr[i] = value","preventionTips":["Standardize interval subtype across the pipeline (e.g. always float64 for analytic columns).","Cast the target array wider before assigning heterogeneous values.","Verify arr.dtype.subtype against the value's endpoint dtype before assignment."],"tags":["interval-array","dtype","setitem"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}