pandas-dev/pandas · error · TypeError

'value' should be a compatible interval type, got

Error message

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

What it means

Raised in IntervalArray._validate_listlike after IntervalArray(value) succeeds, when validating the left endpoint values against the array's subtype fails with LossySetitemError or TypeError. The values are interval-shaped but their endpoints cannot be stored losslessly in this array's subtype (e.g., float intervals into an integer-backed array).

Solutions

  1. Cast the target array to a wider/float subtype first: arr.astype('interval[float64]').
  2. Clean or round endpoint values so they fit the subtype.
  3. Construct a fresh IntervalArray with the appropriate subtype.

Example fix

// before
int_arr[0] = [pd.Interval(1.5, 2.5)]
// after
arr = int_arr.astype('interval[float64]')
arr[0] = [pd.Interval(1.5, 2.5)]
Defensive patterns

Strategy: validation

Validate before calling

def endpoints_fit(arr, value_arr):
    arr.left._validate_fill_value(value_arr.left)
    arr.left._validate_fill_value(value_arr.right)
    return True

Prevention

When it happens

Trigger: Setting [pd.Interval(1.5, 2.5)] into an int-backed IntervalArray; assigning intervals whose endpoints overflow or do not fit the subtype.

Common situations: Mixed-precision interval data; assigning results of float computations to integer interval arrays.

Related errors


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

Appendix: source

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

    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)
        elif is_valid_na_for_dtype(value, self.left.dtype):
            # GH#18295
            left = right = self.left._na_value
        else:
            raise TypeError(
                "can only insert Interval objects and NA into an IntervalArray"
            )
        return left, right

View on GitHub (pinned to 3b7651241d)