pandas-dev/pandas · error · TypeError

Not supported to convert IntervalArray to type with…

Error message

Not supported to convert IntervalArray to type with different 'subtype' ({self.dtype.subtype} vs {type.subtype}) and 'closed' ({self.closed} vs {type.closed}) attributes

What it means

Raised in IntervalArray.__arrow_array__ when the caller supplies an explicit 'type' that is an ArrowIntervalType but its subtype and/or closed attributes do not match the inferred interval_type. The target interval attributes must match the source exactly.

Solutions

  1. Match the target subtype and closed to the source's: read arr.dtype.subtype and arr.closed.
  2. Cast the IntervalArray first (astype + set_closed) so attributes align with the requested type.
  3. Omit the 'type' argument to let pandas infer the correct interval type.

Example fix

// before
pyarrow.array(arr, type=ArrowIntervalType(pa.int32(), 'left'))
// after
arr2 = arr.astype('interval[int32]').set_closed('left')
pyarrow.array(arr2, type=ArrowIntervalType(pa.int32(), 'left'))
Defensive patterns

Strategy: validation

Validate before calling

import pyarrow

def arrow_type_matches(arr, arrow_type):
    inferred = pyarrow.from_numpy_dtype(arr.dtype.subtype)
    return (arrow_type.subtype == inferred and arrow_type.closed == arr.closed)

Prevention

When it happens

Trigger: pyarrow.array(arr, type=ArrowIntervalType(pa.int32(), 'left')) when arr is int64/right; specifying a mismatched closed value during arrow conversion.

Common situations: Explicit type specification during pyarrow conversion that does not align with the source; schema-driven conversion with a fixed interval type.

Related errors


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

Appendix: source

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

        )
        mask = self.isna()
        if mask.any():
            # if there are missing values, set validity bitmap also on the array level
            null_bitmap = pyarrow.array(~mask).buffers()[1]
            storage_array = pyarrow.StructArray.from_buffers(
                storage_array.type,
                len(storage_array),
                [null_bitmap],
                children=[storage_array.field(0), storage_array.field(1)],
            )

        if type is not None:
            if type.equals(interval_type.storage_type):
                return storage_array
            elif isinstance(type, ArrowIntervalType):
                # ensure we have the same subtype and closed attributes
                if not type.equals(interval_type):
                    raise TypeError(
                        "Not supported to convert IntervalArray to type with "
                        f"different 'subtype' ({self.dtype.subtype} vs {type.subtype}) "
                        f"and 'closed' ({self.closed} vs {type.closed}) attributes"
                    )
            else:
                raise TypeError(
                    f"Not supported to convert IntervalArray to '{type}' type"
                )

        return pyarrow.ExtensionArray.from_storage(interval_type, storage_array)

    def to_tuples(self, na_tuple: bool = True) -> np.ndarray:
        """
        Return an ndarray (if self is IntervalArray) or Index \
        (if self is IntervalIndex) of tuples of the form (left, right).

        This method extracts the bounds of each interval as a tuple,
        useful for iteration or conversion to other data structures.

View on GitHub (pinned to 3b7651241d)