diff --git a/pandas/core/arrays/boolean.py b/pandas/core/arrays/boolean.py index 87c18fe346c62..812b507ea22c1 100644 --- a/pandas/core/arrays/boolean.py +++ b/pandas/core/arrays/boolean.py @@ -379,7 +379,7 @@ def _logical_method(self, other, op): # type: ignore[override] elif is_list_like(other): other = np.asarray(other, dtype="bool") if other.ndim > 1: - raise NotImplementedError("can only perform ops with 1-d structures") + return NotImplemented other, mask = coerce_to_array(other, copy=False) elif isinstance(other, np.bool_): other = other.item() diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index d205569270705..ae12ca892cd23 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -856,6 +856,27 @@ def test_modulo_zero_int(self): expected = Series([np.nan, 0.0]) tm.assert_series_equal(result, expected) + def test_np_array_mul_ea_array_returns_extensionarray(self): + # GH#61866 + np_array = np.array([1, 2, 3, 4, 5], dtype=np.int64) + ea_array = array([1, 2, 3, 4, 5], dtype="Int64") + result = np_array * ea_array + assert isinstance(result, type(ea_array)) + tm.assert_equal(result, array([1, 4, 9, 16, 25], dtype="Int64")) + + def test_non_1d_ea_raises_notimplementederror(self): + # GH#61866 + ea_array = array([1, 2, 3, 4, 5], dtype="Int64").reshape(5, 1) + np_array = np.array([1, 2, 3, 4, 5], dtype=np.int64).reshape(5, 1) + + msg = "can only perform ops with 1-d structures" + + with pytest.raises(NotImplementedError, match=msg): + ea_array * np_array + + with pytest.raises(NotImplementedError, match=msg): + np_array * ea_array + class TestAdditionSubtraction: # __add__, __sub__, __radd__, __rsub__, __iadd__, __isub__