Skip to content

BUG: AttributeError: 'BooleanArray' object has no attribute 'sum' while infer types #44423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/io/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ def _infer_types(self, values, na_values, try_num_bool=True):
# 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()
na_count = mask.astype("uint8").sum()
if na_count > 0:
if is_integer_dtype(values):
values = values.astype(np.float64)
Expand Down
21 changes: 21 additions & 0 deletions pandas/tests/io/parser/test_index_col.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,24 @@ def test_multiindex_columns_index_col_with_data(all_parsers):
index=Index(["data"]),
)
tm.assert_frame_equal(result, expected)


@skip_pyarrow
def test_infer_types_boolean_sum(all_parsers):
# GH#44079
parser = all_parsers
result = parser.read_csv(
StringIO("0,1"),
names=["a", "b"],
index_col=["a"],
dtype={"a": "UInt8"},
)
expected = DataFrame(
data={
"a": [
0,
],
"b": [1],
}
).set_index("a")
tm.assert_frame_equal(result, expected, check_index_type=False)