pandas-dev/pandas · error · TypeError

Expected array of boolean type, got

Error message

Expected array of boolean type, got {array.type} instead

What it means

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.

Solutions

  1. Cast the arrow array to bool before conversion: pa_array.cast(pa.bool_()).
  2. Fix the upstream writer to emit boolean columns as pa.bool_().
  3. Convert through pandas: pd.array(pa_array.to_numpy(zero_copy_only=False).astype(bool), dtype='boolean').

Example fix

// before
s = pd.array(pa.array([0, 1, 1]), dtype='boolean')
// after
s = pd.array(pa.array([0, 1, 1]).cast(pa.bool_()), dtype='boolean')
Defensive patterns

Strategy: validation

Validate before calling

import pyarrow
if array.type != pyarrow.bool_() and not pyarrow.types.is_null(array.type):
    array = array.cast(pyarrow.bool_())

Type guard

def is_arrow_bool_or_null(arr) -> bool:
    import pyarrow
    return arr.type == pyarrow.bool_() or pyarrow.types.is_null(arr.type)

Try / catch

try:
    pd.array(arrow_arr, dtype='boolean')
except TypeError as e:
    if 'Expected array of boolean type' in str(e):
        arrow_arr = arrow_arr.cast(pyarrow.bool_())
        ...

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11). Data as JSON: /api/errors/ca6d79d64a187d0e. Report an issue: GitHub.

Appendix: source

Thrown at pandas/core/arrays/boolean.py:141

    @property
    def _is_boolean(self) -> bool:
        return True

    @property
    def _is_numeric(self) -> bool:
        return True

    def __from_arrow__(
        self, array: pyarrow.Array | pyarrow.ChunkedArray
    ) -> BooleanArray:
        """
        Construct BooleanArray from pyarrow Array/ChunkedArray.
        """
        import pyarrow

        if array.type != pyarrow.bool_() and not pyarrow.types.is_null(array.type):
            raise TypeError(f"Expected array of boolean type, got {array.type} instead")

        if isinstance(array, pyarrow.Array):
            chunks = [array]
            length = len(array)
        else:
            # pyarrow.ChunkedArray
            chunks = array.chunks
            length = array.length()

        if pyarrow.types.is_null(array.type):
            mask = np.ones(length, dtype=bool)
            # No need to init data, since all null
            data = np.empty(length, dtype=bool)
            return BooleanArray(data, mask)

        results = []
        for arr in chunks:
            buflist = arr.buffers()

View on GitHub (pinned to 3b7651241d)