pandas-dev/pandas · error · TypeError

'value' should be an interval type, got {type(value)} instea

Error message

'value' should be an interval type, got {type(value)} instead.

What it means

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.

Source

Thrown at pandas/core/arrays/interval.py:1160

        left_take = take(
            self._left, indices, allow_fill=allow_fill, fill_value=fill_left
        )
        right_take = take(
            self._right, indices, allow_fill=allow_fill, fill_value=fill_right
        )

        return self._shallow_copy(left_take, right_take)

    def _validate_listlike(self, value):
        # list-like of intervals
        try:
            array = IntervalArray(value)
            self._check_closed_matches(array, name="value")
            value_left, value_right = array.left, array.right
        except TypeError as err:
            # wrong type: not interval or NA
            msg = f"'value' should be an interval type, got {type(value)} instead."
            raise TypeError(msg) from err

        try:
            self.left._validate_fill_value(value_left)
        except (LossySetitemError, TypeError) as err:
            msg = (
                "'value' should be a compatible interval type, "
                f"got {type(value)} instead."
            )
            raise TypeError(msg) from err

        return value_left, value_right

    def _validate_scalar(self, value):
        if isinstance(value, Interval):
            self._check_closed_matches(value, name="value")
            left, right = value.left, value.right
            self.left._validate_fill_value(left)
            self.left._validate_fill_value(right)

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Wrap each element in pd.Interval(left, right, closed=arr.closed) before assignment so the value is interval-shaped.
  2. Construct the value with pd.arrays.IntervalArray.from_tuples([...], closed=arr.closed) and assign that array.
  3. If the intent was NA, pass pd.NA / np.nan instead of a list-like of scalars.

Example fix

# before
arr = pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)])
arr[0] = [10, 20]

# after
arr[0] = pd.Interval(10, 20, closed=arr.closed)
Defensive patterns

Strategy: type-guard

Validate before calling

def to_interval_payload(value, closed):
    if isinstance(value, pd.Interval):
        return value
    if isinstance(value, (list, tuple, np.ndarray, pd.arrays.IntervalArray)):
        return pd.arrays.IntervalArray.from_tuples(value, closed=closed)
    raise TypeError(f'cannot use {type(value)} as interval payload')

Type guard

def is_interval_like(value) -> bool:
    return isinstance(value, (pd.Interval, pd.arrays.IntervalArray, pd.IntervalIndex)) or (
        hasattr(value, '__iter__') and all(isinstance(v, pd.Interval) for v in value)
    )

Try / catch

try:
    arr[i] = value
except TypeError as e:
    if 'should be an interval type' in str(e):
        arr[i] = to_interval_payload(value, arr.closed)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/568fa7082bb9070b. Report an issue: GitHub.