{"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":"validation","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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/boolean.py#L123-L159","documentation":"BooleanDtype.__from_arrow__ (boolean.py:141) requires the incoming pyarrow array to be of type bool (or null); any other arrow type (int, float, string, etc.) raises TypeError naming the actual type. This guards zero-copy construction of a BooleanArray from arrow buffers, which only makes sense for boolean arrow data.","triggerScenarios":"Converting a non-boolean pyarrow array to pandas with the 'boolean' dtype, e.g. table.schema.types mismatch, pa.array([1,0,1]).cast(...) then to_pandas(dtype='boolean'), or arrow exchange protocols that route a wrong-typed chunk into __from_arrow__.","commonSituations":"Reading parquet/arrow tables whose columns are int8/uint8 flags meant to be boolean; explicit dtype='boolean' on to_pandas; pyarrow schema mismatches after ETL.","solutions":["Cast the pyarrow array to bool before conversion: pa_array.cast(pa.bool_()).","Let pandas infer the dtype and convert afterwards via pd.array(values, dtype='boolean').","Fix the upstream schema so flag columns are produced as arrow bool.","Drop the offending column or handle it with a separate path."],"exampleFix":"# before\nimport pyarrow as pa\npa.array([1, 0, 1]).to_pandas(dtype=\"boolean\")  # raises\n\n# after\npa.array([1, 0, 1]).cast(pa.bool_()).to_pandas(dtype=\"boolean\")","handlingStrategy":"validation","validationCode":"def to_boolean_from_arrow(pa_arr):\n    import pyarrow as pa\n    if pa_arr.type != pa.bool_() and not pa.types.is_null(pa_arr.type):\n        pa_arr = pa_arr.cast(pa.bool_())\n    return pa_arr.to_pandas(dtype=\"boolean\")","typeGuard":"def is_arrow_bool(pa_arr) -> bool:\n    import pyarrow as pa\n    return pa_arr.type == pa.bool_() or pa.types.is_null(pa_arr.type)","tryCatchPattern":"try:\n    series = pa_array.to_pandas(dtype=\"boolean\")\nexcept TypeError as e:\n    if \"Expected array of boolean type\" in str(e):\n        import pyarrow as pa\n        series = pa_array.cast(pa.bool_()).to_pandas(dtype=\"boolean\")\n    else:\n        raise","preventionTips":["Cast arrow arrays to bool before to_pandas(dtype='boolean')","Validate arrow schema types in ETL","Use pd.array on converted data as a fallback"],"tags":["arrow","boolean","dtype-mismatch","interoperability"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}