{"record":{"id":"568fa7082bb9070b","repo":"pandas-dev/pandas","slug":"value-should-be-an-interval-type-got-type-valu","errorCode":null,"errorMessage":"'value' should be an interval type, got {type(value)} instead.","messagePattern":"'value' should be an interval type, got (.+?) instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/interval.py","lineNumber":1160,"sourceCode":"        left_take = take(\n            self._left, indices, allow_fill=allow_fill, fill_value=fill_left\n        )\n        right_take = take(\n            self._right, indices, allow_fill=allow_fill, fill_value=fill_right\n        )\n\n        return self._shallow_copy(left_take, right_take)\n\n    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)","sourceCodeStart":1142,"sourceCodeEnd":1178,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/interval.py#L1142-L1178","documentation":"Raised by IntervalArray._validate_listlike when the value supplied to a setitem-like operation cannot be coerced into an IntervalArray (it is neither interval-shaped nor list-like of intervals). The inner construction IntervalArray(value) raises TypeError, which is rewrapped with the offending value's type so the caller knows the input shape is wrong. It guards assignment into interval-backed storage against non-interval payloads.","triggerScenarios":"Assigning a scalar/list of scalars (strings, plain numbers, dicts) into an IntervalArray slot, e.g. arr[i] = [1, 2, 3] where arr is an IntervalArray; or fillna/where with a list-like that contains no Interval objects.","commonSituations":"Users confusing endpoint-tuple assignment with interval assignment, mixing in raw float/int values, passing objects produced by .tolist() expecting round-trip behavior, or pipelines that previously stored generic objects.","solutions":["Wrap each element in pd.Interval(left, right, closed=arr.closed) before assignment so the value is interval-shaped.","Construct the value with pd.arrays.IntervalArray.from_tuples([...], closed=arr.closed) and assign that array.","If the intent was NA, pass pd.NA / np.nan instead of a list-like of scalars."],"exampleFix":"# before\narr = pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)])\narr[0] = [10, 20]\n\n# after\narr[0] = pd.Interval(10, 20, closed=arr.closed)","handlingStrategy":"type-guard","validationCode":"def to_interval_payload(value, closed):\n    if isinstance(value, pd.Interval):\n        return value\n    if isinstance(value, (list, tuple, np.ndarray, pd.arrays.IntervalArray)):\n        return pd.arrays.IntervalArray.from_tuples(value, closed=closed)\n    raise TypeError(f'cannot use {type(value)} as interval payload')","typeGuard":"def is_interval_like(value) -> bool:\n    return isinstance(value, (pd.Interval, pd.arrays.IntervalArray, pd.IntervalIndex)) or (\n        hasattr(value, '__iter__') and all(isinstance(v, pd.Interval) for v in value)\n    )","tryCatchPattern":"try:\n    arr[i] = value\nexcept TypeError as e:\n    if 'should be an interval type' in str(e):\n        arr[i] = to_interval_payload(value, arr.closed)","preventionTips":["Always wrap endpoints in pd.Interval before assigning to interval storage.","Type-check payloads at the boundary of your data pipeline.","Prefer building values with pd.arrays.IntervalArray.from_tuples over hand-rolled lists."],"tags":["interval-array","type-error","setitem"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}