BUG: AttributeError: 'BooleanArray' object has no attribute 'sum' while infer types · Issue #44079 · pandas-dev/pandas (original) (raw)

Line 694 in the pandas/io/parsers/base_parser.py file,

        if issubclass(values.dtype.type, (np.number, np.bool_)):
            # error: Argument 2 to "isin" has incompatible type "List[Any]"; expected
            # "Union[Union[ExtensionArray, ndarray], Index, Series]"
            mask = algorithms.isin(values, list(na_values))  # type: ignore[arg-type]
            na_count =mask.sum()
            ^^^^^^^^^^^^^THIS
            if na_count > 0:
                if is_integer_dtype(values):
                    values = values.astype(np.float64)
                np.putmask(values, mask, np.nan)
            return values, na_count

Caused an "AttributeError: 'BooleanArray' object has no attribute 'sum'" following some global ananconda update. Changed the line to
na_count =mask.astype('uint8').sum()

fixed the error in my case.

Edit by rhshadrach:

Minimal example

from io import StringIO

import pandas as pd

df = pd.read_csv(
     StringIO("0,1"),
     names=['a', 'b'],
     index_col=['a'],
     dtype={'a': 'UInt8'},
)