{"record":{"id":"ca6d79d64a187d0e","repo":"pandas-dev/pandas","slug":"expected-array-of-boolean-type-got-array-type-i","errorCode":null,"errorMessage":"Expected array of boolean type, got {array.type} instead","messagePattern":"Expected array of boolean type, got (.+?) instead","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/boolean.py","lineNumber":141,"sourceCode":"\n    @property\n    def _is_boolean(self) -> bool:\n        return True\n\n    @property\n    def _is_numeric(self) -> bool:\n        return True\n\n    def __from_arrow__(\n        self, array: pyarrow.Array | pyarrow.ChunkedArray\n    ) -> BooleanArray:\n        \"\"\"\n        Construct BooleanArray from pyarrow Array/ChunkedArray.\n        \"\"\"\n        import pyarrow\n\n        if array.type != pyarrow.bool_() and not pyarrow.types.is_null(array.type):\n            raise TypeError(f\"Expected array of boolean type, got {array.type} instead\")\n\n        if isinstance(array, pyarrow.Array):\n            chunks = [array]\n            length = len(array)\n        else:\n            # pyarrow.ChunkedArray\n            chunks = array.chunks\n            length = array.length()\n\n        if pyarrow.types.is_null(array.type):\n            mask = np.ones(length, dtype=bool)\n            # No need to init data, since all null\n            data = np.empty(length, dtype=bool)\n            return BooleanArray(data, mask)\n\n        results = []\n        for arr in chunks:\n            buflist = arr.buffers()","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/boolean.py#L123-L159","documentation":"Raised by BooleanDtype.__from_arrow__ when the incoming pyarrow array is neither pyarrow.bool_() nor a null type. Arrow interop requires the source type to be boolean (or all-null, which is permitted); any other arrow type is rejected because converting it to a BooleanArray would be lossy or ambiguous.","triggerScenarios":"Calling pd.array(pa_array, dtype='boolean') or letting pandas convert an arrow array where the arrow type is int8, string, int32, etc. Also triggered by pd.DataFrame(pa_table) where a column destined for BooleanArray has a non-bool arrow type.","commonSituations":"Arrow tables with integer-coded booleans (0/1) instead of true bools; reading Parquet/Arrow IPC where the writer used int8 for flags; schema mismatches after an ETL change; pyarrow version differences in type promotion.","solutions":["Cast the arrow array to bool before conversion: pa_array.cast(pa.bool_()).","Fix the upstream writer to emit boolean columns as pa.bool_().","Convert through pandas: pd.array(pa_array.to_numpy(zero_copy_only=False).astype(bool), dtype='boolean')."],"exampleFix":"// before\ns = pd.array(pa.array([0, 1, 1]), dtype='boolean')\n// after\ns = pd.array(pa.array([0, 1, 1]).cast(pa.bool_()), dtype='boolean')","handlingStrategy":"validation","validationCode":"import pyarrow\nif array.type != pyarrow.bool_() and not pyarrow.types.is_null(array.type):\n    array = array.cast(pyarrow.bool_())","typeGuard":"def is_arrow_bool_or_null(arr) -> bool:\n    import pyarrow\n    return arr.type == pyarrow.bool_() or pyarrow.types.is_null(arr.type)","tryCatchPattern":"try:\n    pd.array(arrow_arr, dtype='boolean')\nexcept TypeError as e:\n    if 'Expected array of boolean type' in str(e):\n        arrow_arr = arrow_arr.cast(pyarrow.bool_())\n        ...","preventionTips":["Cast arrow arrays to pa.bool_() before BooleanArray conversion.","Audit Parquet schemas for int-coded booleans."],"tags":["arrow","pyarrow","boolean","dtype","interop"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}