Skip to content

DEPR: __array_wrap__ #45517

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 1 commit into from
Jan 21, 2022
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ Other Deprecations
- 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`)
- 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`)
- Deprecated :meth:`DataFrame.iteritems`, :meth:`Series.iteritems`, :meth:`HDFStore.iteritems` in favor of :meth:`DataFrame.items`, :meth:`Series.items`, :meth:`HDFStore.items` (:issue:`45321`)
- Deprecated the ``__array_wrap__`` method of DataFrame and Series, rely on standard numpy ufuncs instead (:issue:`45451`)
-


Expand Down
6 changes: 6 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,12 @@ def __array_wrap__(
Series implements __array_ufunc_ so this not called for ufunc on Series.
"""
# Note: at time of dask 2022.01.0, this is still used by dask
warnings.warn(
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm i guess this is internal so DeprecationWarning is ok

"The __array_wrap__ method of DataFrame and Series will be removed in "
"a future version",
DeprecationWarning,
stacklevel=2,
)
res = lib.item_from_zerodim(result)
if is_scalar(res):
# e.g. we get here with np.ptp(series)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/base/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def test_array_wrap_compat():
# (https://github.com/dask/dask/issues/8580).
# This test is a small dummy ensuring coverage
orig = Series([1, 2, 3], dtype="int64", index=["a", "b", "c"])
result = orig.__array_wrap__(np.array([2, 4, 6], dtype="int64"))
with tm.assert_produces_warning(DeprecationWarning):
result = orig.__array_wrap__(np.array([2, 4, 6], dtype="int64"))
expected = orig * 2
tm.assert_series_equal(result, expected)

Expand Down
1 change: 1 addition & 0 deletions pandas/tests/test_downstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def test_dask(df):


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