-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
9496569
08e0e37
f0c9157
ae5b4c1
e8db699
8f02e65
390fa8e
cb445f3
7454a7d
9ea1744
1ef4eb5
17159b6
079547d
f8fff38
672e7cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -856,6 +856,33 @@ 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): | ||
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")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this actually affected by this PR? if not i expect it is already tested? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test checks that multiplying a NumPy array by an ExtensionArray gives the correct type (an ExtensionArray), which means the fallback via NotImplemented is working as intended. I couldnt find anything similar in test_numeric.py or some other files i tried to look into. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you think its checked elsewhere, i will remove it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, the 1D version is tested elsewhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. once this is removed, ping on green and ill merge There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have removed it! thanks for the help |
||
|
||
def test_df_mul_np_and_ea_array_shape_and_errors(self): | ||
df = pd.DataFrame(np.arange(50).reshape(10, 5)).notna().values | ||
NP_array = np.array(list(range(10)), dtype=np.int64).reshape(10, 1) | ||
EA_array = array(list(range(10)), dtype="Int64").reshape(10, 1) | ||
result_np = df * NP_array | ||
tisjayy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert isinstance(result_np, np.ndarray) | ||
tm.assert_equal(result_np.shape, (10, 5)) | ||
|
||
with pytest.raises(NotImplementedError): | ||
_ = df * EA_array | ||
tisjayy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def test_non_1d_ea_raises_typeerror(self): | ||
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) | ||
|
||
with pytest.raises(NotImplementedError): | ||
tisjayy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_ = ea_array * np_array | ||
with pytest.raises(NotImplementedError): | ||
_ = np_array * ea_array | ||
|
||
|
||
class TestAdditionSubtraction: | ||
# __add__, __sub__, __radd__, __rsub__, __iadd__, __isub__ | ||
|
Uh oh!
There was an error while loading. Please reload this page.