From 317946c8034875826b5f9f86e85c8ce28d6a64a4 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 9 Jan 2023 17:23:12 -0800 Subject: [PATCH 1/3] DEPR: Remove DeprecationWarnings --- pandas/core/generic.py | 37 ------------------------------- pandas/core/indexes/base.py | 16 ------------- pandas/tests/base/test_misc.py | 11 --------- pandas/tests/indexes/test_base.py | 8 ------- pandas/tests/test_downstream.py | 4 ---- 5 files changed, 76 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 561422c868e91..92c07cc9858f2 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2009,43 +2009,6 @@ def empty(self) -> bool_t: def __array__(self, dtype: npt.DTypeLike | None = None) -> np.ndarray: return np.asarray(self._values, dtype=dtype) - def __array_wrap__( - self, - result: np.ndarray, - context: tuple[Callable, tuple[Any, ...], int] | None = None, - ): - """ - Gets called after a ufunc and other functions. - - Parameters - ---------- - result: np.ndarray - The result of the ufunc or other function called on the NumPy array - returned by __array__ - context: tuple of (func, tuple, int) - This parameter is returned by ufuncs as a 3-element tuple: (name of the - ufunc, arguments of the ufunc, domain of the ufunc), but is not set by - other numpy functions.q - - Notes - ----- - 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( - "The __array_wrap__ method of DataFrame and Series will be removed in " - "a future version", - DeprecationWarning, - stacklevel=find_stack_level(), - ) - res = lib.item_from_zerodim(result) - if is_scalar(res): - # e.g. we get here with np.ptp(series) - # ptp also requires the item_from_zerodim - return res - d = self._construct_axes_dict(self._AXIS_ORDERS, copy=False) - return self._constructor(res, **d).__finalize__(self, method="__array_wrap__") - @final def __array_ufunc__( self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 775d137523d2b..926880efa5ca7 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -698,22 +698,6 @@ def _format_duplicate_message(self) -> DataFrame: # -------------------------------------------------------------------- # Index Internals Methods - @final - def _get_attributes_dict(self) -> dict[str_t, Any]: - """ - Return an attributes dict for my class. - - Temporarily added back for compatibility issue in dask, see - https://github.com/pandas-dev/pandas/pull/43895 - """ - warnings.warn( - "The Index._get_attributes_dict method is deprecated, and will be " - "removed in a future version", - DeprecationWarning, - stacklevel=find_stack_level(), - ) - return {k: getattr(self, k, None) for k in self._attributes} - def _shallow_copy(self: _IndexT, values, name: Hashable = no_default) -> _IndexT: """ Create a new Index with the same class as the caller, don't copy the diff --git a/pandas/tests/base/test_misc.py b/pandas/tests/base/test_misc.py index a55c013a7340d..4df55aefdcb06 100644 --- a/pandas/tests/base/test_misc.py +++ b/pandas/tests/base/test_misc.py @@ -84,17 +84,6 @@ def test_ndarray_compat_properties(index_or_series_obj): assert Series([1]).item() == 1 -def test_array_wrap_compat(): - # Note: at time of dask 2022.01.0, this is still used by eg dask - # (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"]) - 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) - - @pytest.mark.skipif(PYPY, reason="not relevant for PyPy") def test_memory_usage(index_or_series_obj): obj = index_or_series_obj diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 969c6059b8d31..cf3a9fcc8c7a3 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -1605,14 +1605,6 @@ def test_construct_from_memoryview(klass, extra_kwargs): tm.assert_index_equal(result, expected, exact=True) -def test_get_attributes_dict_deprecated(): - # https://github.com/pandas-dev/pandas/pull/44028 - idx = Index([1, 2, 3, 1]) - with tm.assert_produces_warning(DeprecationWarning): - attrs = idx._get_attributes_dict() - assert attrs == {"name": None} - - @pytest.mark.parametrize("op", [operator.lt, operator.gt]) def test_nan_comparison_same_object(op): # GH#47105 diff --git a/pandas/tests/test_downstream.py b/pandas/tests/test_downstream.py index 2287110b63bb6..5192b3d4cabf8 100644 --- a/pandas/tests/test_downstream.py +++ b/pandas/tests/test_downstream.py @@ -58,11 +58,7 @@ def test_dask(df): pd.set_option("compute.use_numexpr", olduse) -@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). - # dask sets "compute.use_numexpr" to False, so catch the current value # and ensure to reset it afterwards to avoid impacting other tests olduse = pd.get_option("compute.use_numexpr") From 4f86ff4b46e8772074c5f48f8a385b01e6945b61 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 9 Jan 2023 17:25:48 -0800 Subject: [PATCH 2/3] Add whatsnew --- doc/source/whatsnew/v2.0.0.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 11fefb08265c3..d534f287a1a3d 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -788,7 +788,8 @@ Removal of prior version deprecations/changes - Removed the deprecated argument ``line_terminator`` from :meth:`DataFrame.to_csv` (:issue:`45302`) - Removed the deprecated argument ``label`` from :func:`lreshape` (:issue:`30219`) - Arguments after ``expr`` in :meth:`DataFrame.eval` and :meth:`DataFrame.query` are keyword-only (:issue:`47587`) -- +- Removed :meth:`Index._get_attributes_dict` (:issue:`?`) +- Removed :meth:`Series.__array_wrap__` (:issue:`?`) .. --------------------------------------------------------------------------- .. _whatsnew_200.performance: From 5e58b94a242846bd77bc2eb00956f476bc6f0c44 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 9 Jan 2023 17:27:46 -0800 Subject: [PATCH 3/3] Add issue nnumber --- doc/source/whatsnew/v2.0.0.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index d534f287a1a3d..83b6cc32c5fbc 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -788,8 +788,8 @@ Removal of prior version deprecations/changes - Removed the deprecated argument ``line_terminator`` from :meth:`DataFrame.to_csv` (:issue:`45302`) - Removed the deprecated argument ``label`` from :func:`lreshape` (:issue:`30219`) - Arguments after ``expr`` in :meth:`DataFrame.eval` and :meth:`DataFrame.query` are keyword-only (:issue:`47587`) -- Removed :meth:`Index._get_attributes_dict` (:issue:`?`) -- Removed :meth:`Series.__array_wrap__` (:issue:`?`) +- Removed :meth:`Index._get_attributes_dict` (:issue:`50648`) +- Removed :meth:`Series.__array_wrap__` (:issue:`50648`) .. --------------------------------------------------------------------------- .. _whatsnew_200.performance: