Skip to content

Commit 461772a

Browse files
DEPR: __array_wrap__ (#45517)
1 parent c556a04 commit 461772a

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ Other Deprecations
145145
- Deprecated behavior of :meth:`SparseArray.astype`, :meth:`Series.astype`, and :meth:`DataFrame.astype` with :class:`SparseDtype` when passing a non-sparse ``dtype``. In a future version, this will cast to that non-sparse dtype instead of wrapping it in a :class:`SparseDtype` (:issue:`34457`)
146146
- Deprecated behavior of :meth:`DatetimeIndex.intersection` and :meth:`DatetimeIndex.symmetric_difference` (``union`` behavior was already deprecated in version 1.3.0) with mixed timezones; in a future version both will be cast to UTC instead of object dtype (:issue:`39328`, :issue:`45357`)
147147
- Deprecated :meth:`DataFrame.iteritems`, :meth:`Series.iteritems`, :meth:`HDFStore.iteritems` in favor of :meth:`DataFrame.items`, :meth:`Series.items`, :meth:`HDFStore.items` (:issue:`45321`)
148+
- Deprecated the ``__array_wrap__`` method of DataFrame and Series, rely on standard numpy ufuncs instead (:issue:`45451`)
148149
-
149150

150151

pandas/core/generic.py

+6
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,12 @@ def __array_wrap__(
20752075
Series implements __array_ufunc_ so this not called for ufunc on Series.
20762076
"""
20772077
# Note: at time of dask 2022.01.0, this is still used by dask
2078+
warnings.warn(
2079+
"The __array_wrap__ method of DataFrame and Series will be removed in "
2080+
"a future version",
2081+
DeprecationWarning,
2082+
stacklevel=2,
2083+
)
20782084
res = lib.item_from_zerodim(result)
20792085
if is_scalar(res):
20802086
# e.g. we get here with np.ptp(series)

pandas/tests/base/test_misc.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def test_array_wrap_compat():
8989
# (https://github.com/dask/dask/issues/8580).
9090
# This test is a small dummy ensuring coverage
9191
orig = Series([1, 2, 3], dtype="int64", index=["a", "b", "c"])
92-
result = orig.__array_wrap__(np.array([2, 4, 6], dtype="int64"))
92+
with tm.assert_produces_warning(DeprecationWarning):
93+
result = orig.__array_wrap__(np.array([2, 4, 6], dtype="int64"))
9394
expected = orig * 2
9495
tm.assert_series_equal(result, expected)
9596

pandas/tests/test_downstream.py

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def test_dask(df):
5656

5757

5858
@pytest.mark.filterwarnings("ignore:.*64Index is deprecated:FutureWarning")
59+
@pytest.mark.filterwarnings("ignore:The __array_wrap__:DeprecationWarning")
5960
def test_dask_ufunc():
6061
# At the time of dask 2022.01.0, dask is still directly using __array_wrap__
6162
# for some ufuncs (https://github.com/dask/dask/issues/8580).

0 commit comments

Comments
 (0)