Skip to content

Commit 23aae9f

Browse files
BUG: Fix ExtensionArray binary op protocol (#61990)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1d22331 commit 23aae9f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pandas/core/arrays/boolean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def _logical_method(self, other, op): # type: ignore[override]
378378
elif is_list_like(other):
379379
other = np.asarray(other, dtype="bool")
380380
if other.ndim > 1:
381-
raise NotImplementedError("can only perform ops with 1-d structures")
381+
return NotImplemented
382382
other, mask = coerce_to_array(other, copy=False)
383383
elif isinstance(other, np.bool_):
384384
other = other.item()

pandas/tests/arithmetic/test_numeric.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,19 @@ def test_modulo_zero_int(self):
862862
expected = Series([np.nan, 0.0])
863863
tm.assert_series_equal(result, expected)
864864

865+
def test_non_1d_ea_raises_notimplementederror(self):
866+
# GH#61866
867+
ea_array = array([1, 2, 3, 4, 5], dtype="Int64").reshape(5, 1)
868+
np_array = np.array([1, 2, 3, 4, 5], dtype=np.int64).reshape(5, 1)
869+
870+
msg = "can only perform ops with 1-d structures"
871+
872+
with pytest.raises(NotImplementedError, match=msg):
873+
ea_array * np_array
874+
875+
with pytest.raises(NotImplementedError, match=msg):
876+
np_array * ea_array
877+
865878

866879
class TestAdditionSubtraction:
867880
# __add__, __sub__, __radd__, __rsub__, __iadd__, __isub__

0 commit comments

Comments
 (0)