pandas-dev/pandas · error · TypeError
Not supported to convert IntervalArray to type with differen
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 by IntervalArray.__arrow_array__ when the caller passes an explicit target pyarrow type that is an ArrowIntervalType but does not equal the array's natural interval_type — i.e. its subtype or closed differs from the source. The library refuses to silently reinterpret closure or precision during conversion.
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 71959b8cb9)
Solutions
- Align the target ArrowIntervalType's subtype and closed with the source: pa.array(arr, type=ArrowIntervalType(pa.from_numpy_dtype(arr.dtype.subtype), arr.closed)).
- Drop the explicit type argument and let pandas infer it.
- Re-cast arr (arr.astype / arr.set_closed) so it matches the target schema before conversion.
Example fix
# before from pandas.core.arrays.arrow.extension_types import ArrowIntervalType target = ArrowIntervalType(pa.int32(), 'left') pa.array(arr, type=target) # arr is interval[int64, right] # after target = ArrowIntervalType(pa.int64(), 'right') pa.array(arr, type=target)
Defensive patterns
Strategy: validation
Validate before calling
import pyarrow as pa
from pandas.core.arrays.arrow.extension_types import ArrowIntervalType
def matching_arrow_type(arr):
subtype = pa.from_numpy_dtype(arr.dtype.subtype)
return ArrowIntervalType(subtype, arr.closed) Type guard
def arrow_type_matches(arr, target) -> bool:
import pyarrow as pa
from pandas.core.arrays.arrow.extension_types import ArrowIntervalType
if not isinstance(target, ArrowIntervalType):
return False
return (target.subtype == pa.from_numpy_dtype(arr.dtype.subtype)
and target.closed == arr.closed) Prevention
- Derive the target ArrowIntervalType from the source array instead of hardcoding it.
- Keep closure conventions consistent between Arrow schema and pandas source.
- Unit-test schema conversion against representative samples.
When it happens
Trigger: Calling pa.array(arr, type=ArrowIntervalType(pa.int32(), 'left')) on an array whose subtype is int64 and closed='right', or any mismatched (subtype, closed) pair.
Common situations: Schema-driven ETL pipelines that pass a fixed ArrowIntervalType without aligning it to the source, or migrations that change closure conventions.
Related errors
- Conversion to arrow with subtype '{self.dtype.subtype}' is n
- Not supported to convert IntervalArray to '{type}' type
- Invalid side: {side}. Side must be one of 'left', 'right', '
- invalid normalization form
- replace is not supported with a re.Pattern, callable repl, c
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/000b116235278e0d.
Report an issue: GitHub.