{"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":"validation","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/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/interval.py#L1142-L1178","documentation":"Raised in IntervalArray._validate_listlike when constructing IntervalArray(value) from the supplied list-like raises TypeError - meaning the value is not a sequence of Intervals/NA. Reached via __setitem__, fillna, and take(fill_value=...) paths that accept list-like inputs.","triggerScenarios":"arr[i] = [1, 2, 3]; arr.fillna([0, 1]); arr[i:j] = 'x'; assigning plain numbers/lists where Interval objects are required.","commonSituations":"Assigning raw endpoint pairs instead of Interval objects; passing arbitrary list-likes into interval setitem.","solutions":["Wrap values as Intervals: [pd.Interval(a, b, closed=arr.closed) for a, b in pairs].","Pass an IntervalArray or list of Interval objects / pd.NA.","For NA filling use np.nan or pd.NA."],"exampleFix":"// before\narr[0] = [1, 2]\n// after\narr[0] = pd.Interval(1, 2, closed=arr.closed)","handlingStrategy":"type-guard","validationCode":"import pandas as pd\n\ndef to_interval_list(pairs, closed):\n    return [pd.Interval(a, b, closed=closed) for a, b in pairs]","typeGuard":"import pandas as pd\n\ndef is_interval_listlike(v):\n    return all(x is pd.NA or isinstance(x, pd.Interval) for x in v)","tryCatchPattern":"try:\n    arr[key] = value\nexcept TypeError as e:\n    if 'should be an interval type' in str(e):\n        arr[key] = [pd.Interval(a, b, closed=arr.closed) for a, b in value]\n    else:\n        raise","preventionTips":["Always wrap endpoint pairs as Interval objects before assignment.","Pass IntervalArray or list[Interval|NA] to interval setitem/fillna.","Use pd.NA for missing values, not raw sentinels."],"tags":["interval-array","setitem","validation"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}