pandas-dev/pandas · error · TypeError

'value' should be an interval type, got

Error message

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

What it means

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.

Solutions

  1. Wrap values as Intervals: [pd.Interval(a, b, closed=arr.closed) for a, b in pairs].
  2. Pass an IntervalArray or list of Interval objects / pd.NA.
  3. For NA filling use np.nan or pd.NA.

Example fix

// before
arr[0] = [1, 2]
// after
arr[0] = pd.Interval(1, 2, closed=arr.closed)
Defensive patterns

Strategy: type-guard

Validate before calling

import pandas as pd

def to_interval_list(pairs, closed):
    return [pd.Interval(a, b, closed=closed) for a, b in pairs]

Type guard

import pandas as pd

def is_interval_listlike(v):
    return all(x is pd.NA or isinstance(x, pd.Interval) for x in v)

Try / catch

try:
    arr[key] = value
except TypeError as e:
    if 'should be an interval type' in str(e):
        arr[key] = [pd.Interval(a, b, closed=arr.closed) for a, b in value]
    else:
        raise

Prevention

When it happens

Trigger: arr[i] = [1, 2, 3]; arr.fillna([0, 1]); arr[i:j] = 'x'; assigning plain numbers/lists where Interval objects are required.

Common situations: Assigning raw endpoint pairs instead of Interval objects; passing arbitrary list-likes into interval setitem.

Related errors


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

Appendix: 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 3b7651241d)