Skip to content

BUG: Fix ExtensionArray binary op protocol #61990

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
BUG: Return NotImplemented for non-1D operands in BooleanArray ops; a…
…dd tests for numeric EA shape errors
  • Loading branch information
tisjayy committed Jul 29, 2025
commit 949656952b94b3c55a51ef3a758d1622f8f82bbc
2 changes: 1 addition & 1 deletion pandas/core/arrays/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
31 changes: 31 additions & 0 deletions pandas/tests/arithmetic/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ def test_df_div_zero_series_does_not_commute(self):
res2 = df / ser
assert not res.fillna(0).equals(res2.fillna(0))



# ------------------------------------------------------------------
# Mod By Zero

Expand Down Expand Up @@ -855,6 +857,35 @@ def test_modulo_zero_int(self):
result = 0 % s
expected = Series([np.nan, 0.0])
tm.assert_series_equal(result, expected)

def test_np_array_mul_ea_array_returns_extensionarray():
np_array = np.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0])
ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0])
result = np_array * ea_array
tm.assert_isinstance(result, type(ea_array))
tm.assert_equal(result, pd.array([1, 4, 9, 16, 25], dtype=tm.SIGNED_INT_EA_DTYPES[0]))
tm.assert_equal(result, pd.array([1, 4, 9, 16, 25], dtype=tm.SIGNED_INT_EA_DTYPES[0]))

def test_df_mul_np_and_ea_array_shape_and_errors():
df = pd.DataFrame(np.arange(50).reshape(10, 5)).notna().values
NP_array = pd.array([i for i in range(10)], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]).reshape(10, 1)
EA_array = pd.array([i for i in range(10)], dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape(10, 1)

result_np = df * NP_array
tm.assert_isinstance(result_np, np.ndarray)
tm.assert_equal(result_np.shape, (10, 5))

with tm.assert_raises(TypeError):
_ = df * EA_array

def test_non_1d_ea_raises_typeerror():
ea_array = pd.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_EA_DTYPES[0]).reshape(5, 1)
np_array = np.array([1, 2, 3, 4, 5], dtype=tm.SIGNED_INT_NUMPY_DTYPES[0]).reshape(5, 1)

with tm.assert_raises(TypeError):
_ = ea_array * np_array
with tm.assert_raises(TypeError):
_ = np_array * ea_array


class TestAdditionSubtraction:
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy