Skip to content
Open
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/core/arrays/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def _logical_method(self, other, op):
if isinstance(other, BooleanArray):
other, mask = other._data, other._mask
elif is_list_like(other):
other = np.asarray(other, dtype="bool")
other = np.asarray(other, dtype=object)
if other.ndim > 1:
return NotImplemented
other, mask = coerce_to_array(other, copy=False)
Comment on lines 397 to 403
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

object comes with performance penalties, I'm thinking we should use a Boolean array here, e.g.

other = BooleanArray._from_sequence(other)
other, mask = other._data, other._mask

cc @jbrockmendel

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think that risks casting non-bool items to bools. pd.array might be safer?

But I'm not sure we want to support this. For non-EA cases we made a choice years ago to raise on &, |, ^ when given a dtype-less sequence

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm +1 on aligning with Series here and deprecating this case entirely.

Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/arrays/boolean/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ def test_abs(self):
result = abs(arr)

tm.assert_extension_array_equal(result, arr)

def test_booleanarray_and_list_with_na(self):
b = pd.array([True, False], dtype="boolean")
result = b & [pd.NA, False]
expected = pd.array([pd.NA, False], dtype="boolean")
tm.assert_extension_array_equal(result, expected)
Loading