{"record":{"id":"000b116235278e0d","repo":"pandas-dev/pandas","slug":"not-supported-to-convert-intervalarray-to-type-wit","errorCode":null,"errorMessage":"Not supported to convert IntervalArray to type with different 'subtype' ({self.dtype.subtype} vs {type.subtype}) and 'closed' ({self.closed} vs {type.closed}) attributes","messagePattern":"Not supported to convert IntervalArray to type with different 'subtype' \\((.+?) vs (.+?)\\) and 'closed' \\((.+?) vs (.+?)\\) attributes","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/interval.py","lineNumber":1625,"sourceCode":"        )\n        mask = self.isna()\n        if mask.any():\n            # if there are missing values, set validity bitmap also on the array level\n            null_bitmap = pyarrow.array(~mask).buffers()[1]\n            storage_array = pyarrow.StructArray.from_buffers(\n                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.","sourceCodeStart":1607,"sourceCodeEnd":1643,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/interval.py#L1607-L1643","documentation":"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.","triggerScenarios":"pyarrow.array(arr, type=ArrowIntervalType(pa.int32(), 'left')) when arr is int64/right; specifying a mismatched closed value during arrow conversion.","commonSituations":"Explicit type specification during pyarrow conversion that does not align with the source; schema-driven conversion with a fixed interval type.","solutions":["Match the target subtype and closed to the source's: read arr.dtype.subtype and arr.closed.","Cast the IntervalArray first (astype + set_closed) so attributes align with the requested type.","Omit the 'type' argument to let pandas infer the correct interval type."],"exampleFix":"// before\npyarrow.array(arr, type=ArrowIntervalType(pa.int32(), 'left'))\n// after\narr2 = arr.astype('interval[int32]').set_closed('left')\npyarrow.array(arr2, type=ArrowIntervalType(pa.int32(), 'left'))","handlingStrategy":"validation","validationCode":"import pyarrow\n\ndef arrow_type_matches(arr, arrow_type):\n    inferred = pyarrow.from_numpy_dtype(arr.dtype.subtype)\n    return (arrow_type.subtype == inferred and arrow_type.closed == arr.closed)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Align the target interval's subtype and closed with the source before specifying an explicit arrow type.","Omit the 'type' argument to let pandas infer the correct interval type.","Cast (astype + set_closed) the source to match the schema when needed."],"tags":["interval-array","arrow","type-mismatch","pyarrow"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}