diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 6a5b4b3b9ff16..2b0aea12bea42 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -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 diff --git a/pandas/core/arrays/integer.py b/pandas/core/arrays/integer.py index 94af013d6df2c..05c3a0517078a 100644 --- a/pandas/core/arrays/integer.py +++ b/pandas/core/arrays/integer.py @@ -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) diff --git a/pandas/tests/arrays/integer/test_function.py b/pandas/tests/arrays/integer/test_function.py index a81434339fdae..8d7f620327f31 100644 --- a/pandas/tests/arrays/integer/test_function.py +++ b/pandas/tests/arrays/integer/test_function.py @@ -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) + 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)