{"record":{"id":"e1b57327ba272b11","repo":"pandas-dev/pandas","slug":"not-supported-to-convert-intervalarray-to-type","errorCode":null,"errorMessage":"Not supported to convert IntervalArray to '{type}' type","messagePattern":"Not supported to convert IntervalArray to '(.+?)' type","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/interval.py","lineNumber":1631,"sourceCode":"                storage_array.type,\n                len(storage_array),\n                [null_bitmap],\n                children=[storage_array.field(0), storage_array.field(1)],\n            )\n\n        if type is not None:\n            if type.equals(interval_type.storage_type):\n                return storage_array\n            elif isinstance(type, ArrowIntervalType):\n                # ensure we have the same subtype and closed attributes\n                if not type.equals(interval_type):\n                    raise TypeError(\n                        \"Not supported to convert IntervalArray to type with \"\n                        f\"different 'subtype' ({self.dtype.subtype} vs {type.subtype}) \"\n                        f\"and 'closed' ({self.closed} vs {type.closed}) attributes\"\n                    )\n            else:\n                raise TypeError(\n                    f\"Not supported to convert IntervalArray to '{type}' type\"\n                )\n\n        return pyarrow.ExtensionArray.from_storage(interval_type, storage_array)\n\n    def to_tuples(self, na_tuple: bool = True) -> np.ndarray:\n        \"\"\"\n        Return an ndarray (if self is IntervalArray) or Index \\\n        (if self is IntervalIndex) of tuples of the form (left, right).\n\n        This method extracts the bounds of each interval as a tuple,\n        useful for iteration or conversion to other data structures.\n\n        Parameters\n        ----------\n        na_tuple : bool, default True\n            If ``True``, return ``NA`` as a tuple ``(nan, nan)``. If ``False``,\n            just return ``NA`` as ``nan``.","sourceCodeStart":1613,"sourceCodeEnd":1649,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/interval.py#L1613-L1649","documentation":"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.","triggerScenarios":"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.","commonSituations":"Auto-generated schemas that default to primitive types, or attempts to 'flatten' intervals into a numeric/string column via Arrow.","solutions":["Omit the type argument so the natural ArrowIntervalType is used.","If a primitive column is truly required, convert first: pa.array(arr.to_numpy().astype(str), type=pa.string()).","Use arr.to_tuples() to expose (left, right) and store as a pa.struct([field('left',...), field('right',...)])."],"exampleFix":"# before\npa.array(interval_arr, type=pa.string())\n\n# after\npa.array(interval_arr)  # use ArrowIntervalType\n# or\npa.array(interval_arr.to_tuples().tolist(), type=pa.string())","handlingStrategy":"validation","validationCode":"import pyarrow as pa\nfrom pandas.core.arrays.arrow.extension_types import ArrowIntervalType\n\ndef safe_arrow_array(arr, target=None):\n    if target is not None and not isinstance(target, ArrowIntervalType):\n        raise TypeError('target must be an ArrowIntervalType or None')\n    return pa.array(arr, type=target)","typeGuard":"def is_interval_arrow_type(target) -> bool:\n    from pandas.core.arrays.arrow.extension_types import ArrowIntervalType\n    return isinstance(target, ArrowIntervalType)","tryCatchPattern":null,"preventionTips":["Omit the type argument for interval arrays unless you have a matching ArrowIntervalType.","Convert intervals to tuples/structs if you genuinely need a primitive Arrow type.","Validate target type against ArrowIntervalType before pa.array(...)."],"tags":["interval-array","pyarrow","type-error","interop"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}