pandas-dev/pandas · error · TypeError

Not supported to convert IntervalArray to '{type}' type

Error message

Not supported to convert IntervalArray to '{type}' type

What it means

Raised by IntervalArray.__arrow_array__ when the explicit target type is neither the array's storage_type nor an ArrowIntervalType. Pandas cannot store interval data into an unrelated arrow type and refuses silent reinterpretation.

Source

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

                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.

        Parameters
        ----------
        na_tuple : bool, default True
            If ``True``, return ``NA`` as a tuple ``(nan, nan)``. If ``False``,
            just return ``NA`` as ``nan``.

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Omit the type argument so the natural ArrowIntervalType is used.
  2. If a primitive column is truly required, convert first: pa.array(arr.to_numpy().astype(str), type=pa.string()).
  3. Use arr.to_tuples() to expose (left, right) and store as a pa.struct([field('left',...), field('right',...)]).

Example fix

# before
pa.array(interval_arr, type=pa.string())

# after
pa.array(interval_arr)  # use ArrowIntervalType
# or
pa.array(interval_arr.to_tuples().tolist(), type=pa.string())
Defensive patterns

Strategy: validation

Validate before calling

import pyarrow as pa
from pandas.core.arrays.arrow.extension_types import ArrowIntervalType

def safe_arrow_array(arr, target=None):
    if target is not None and not isinstance(target, ArrowIntervalType):
        raise TypeError('target must be an ArrowIntervalType or None')
    return pa.array(arr, type=target)

Type guard

def is_interval_arrow_type(target) -> bool:
    from pandas.core.arrays.arrow.extension_types import ArrowIntervalType
    return isinstance(target, ArrowIntervalType)

Prevention

When it happens

Trigger: Calling pa.array(arr, type=pa.string()) or pa.array(arr, type=pa.int64()) on an IntervalArray, or schema-driven converters that pass a primitive target type.

Common situations: Auto-generated schemas that default to primitive types, or attempts to 'flatten' intervals into a numeric/string column via Arrow.

Related errors


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