Skip to content

BUG: Fixed IntegerArray.__array_ufunc__ with nout #36913

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

Merged
Merged
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 doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ ExtensionArray

- Fixed Bug where :class:`DataFrame` column set to scalar extension type via a dict instantion was considered an object type rather than the extension type (:issue:`35965`)
- Fixed bug where ``astype()`` with equal dtype and ``copy=False`` would return a new object (:issue:`284881`)
-
- Fixed bug when applying a NumPy ufunc with multiple outputs to a :class:`pandas.arrays.IntegerArray` returning None (:issue:`36913`)


Other
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def reconstruct(x):

result = getattr(ufunc, method)(*inputs2, **kwargs)
if isinstance(result, tuple):
tuple(reconstruct(x) for x in result)
return tuple(reconstruct(x) for x in result)
else:
return reconstruct(result)

Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/arrays/integer/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ def test_ufuncs_binary_int(ufunc):
tm.assert_extension_array_equal(result, expected)


def test_ufunc_binary_output():
a = integer_array([1, 2, np.nan])
result = np.modf(a)
Copy link
Member

Choose a reason for hiding this comment

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

could parametrize over the (few?) functions that could go through here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The binary ufuncs that overlap with dunder methods hit a different code path. I'm not sure of others (and I'm also not sure I see the value in parametrizing over them. Given the current structure of the code they should be redundant).

expected = np.modf(a.to_numpy(na_value=np.nan, dtype="float"))

assert isinstance(result, tuple)
assert len(result) == 2

for x, y in zip(result, expected):
# TODO(FloatArray): This will return an extension array.
# y = integer_array(y)
tm.assert_numpy_array_equal(x, y)


@pytest.mark.parametrize("values", [[0, 1], [0, None]])
def test_ufunc_reduce_raises(values):
a = integer_array(values)
Expand Down