From 95a0c374637f6b819615543a940be53bfe8a9f36 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 30 Nov 2023 14:54:50 -0800 Subject: [PATCH 1/3] Fully deprecate `.drop` I think it's time... --- doc/whats-new.rst | 4 ++++ xarray/core/dataset.py | 22 ++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 82842430b53..e798371bd16 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -45,6 +45,10 @@ Deprecations currently ``PendingDeprecationWarning``, which are silenced by default. We'll convert these to ``DeprecationWarning`` in a future release. By `Maximilian Roos `_. +- :py:meth:`Dataset.drop` & + :py:meth:`DataArray.drop` are now deprecated, since pending deprecation for + several years. :py:meth:`DataArray.drop_sel` & :py:meth:`DataArray.drop_var` + replace them for labels & variables respectively. Bug fixes ~~~~~~~~~ diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 66c83e95b77..62624fa16a6 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -110,6 +110,7 @@ decode_numpy_dict_values, drop_dims_from_indexers, either_dict_or_kwargs, + emit_user_level_warning, infix_dims, is_dict_like, is_scalar, @@ -5942,10 +5943,9 @@ def drop( raise ValueError('errors must be either "raise" or "ignore"') if is_dict_like(labels) and not isinstance(labels, dict): - warnings.warn( - "dropping coordinates using `drop` is be deprecated; use drop_vars.", - FutureWarning, - stacklevel=2, + emit_user_level_warning( + "dropping coordinates using `drop` is deprecated; use drop_vars.", + DeprecationWarning, ) return self.drop_vars(labels, errors=errors) @@ -5955,10 +5955,9 @@ def drop( labels = either_dict_or_kwargs(labels, labels_kwargs, "drop") if dim is None and (is_scalar(labels) or isinstance(labels, Iterable)): - warnings.warn( - "dropping variables using `drop` will be deprecated; using drop_vars is encouraged.", - PendingDeprecationWarning, - stacklevel=2, + emit_user_level_warning( + "dropping variables using `drop` is deprecated; use drop_vars.", + DeprecationWarning, ) return self.drop_vars(labels, errors=errors) if dim is not None: @@ -5970,10 +5969,9 @@ def drop( ) return self.drop_sel({dim: labels}, errors=errors, **labels_kwargs) - warnings.warn( - "dropping labels using `drop` will be deprecated; using drop_sel is encouraged.", - PendingDeprecationWarning, - stacklevel=2, + emit_user_level_warning( + "dropping labels using `drop` is deprecated; use `drop_sel` instead.", + DeprecationWarning, ) return self.drop_sel(labels, errors=errors) From 10a74a9a022d5a998f28782bd148956dc34c9a48 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 30 Nov 2023 15:09:35 -0800 Subject: [PATCH 2/3] --- xarray/tests/test_dataset.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index a53d81e36af..5428da4e61f 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -2651,19 +2651,19 @@ def test_drop_variables(self) -> None: # deprecated approach with `drop` works (straight copy paste from above) - with pytest.warns(PendingDeprecationWarning): + with pytest.warns(DeprecationWarning): actual = data.drop("not_found_here", errors="ignore") assert_identical(data, actual) - with pytest.warns(PendingDeprecationWarning): + with pytest.warns(DeprecationWarning): actual = data.drop(["not_found_here"], errors="ignore") assert_identical(data, actual) - with pytest.warns(PendingDeprecationWarning): + with pytest.warns(DeprecationWarning): actual = data.drop(["time", "not_found_here"], errors="ignore") assert_identical(expected, actual) - with pytest.warns(PendingDeprecationWarning): + with pytest.warns(DeprecationWarning): actual = data.drop({"time", "not_found_here"}, errors="ignore") assert_identical(expected, actual) From b5c2cdea1cc89e2ffd7008bea6d9806529199226 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 1 Dec 2023 21:01:07 -0800 Subject: [PATCH 3/3] --- xarray/tests/test_dataset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 5428da4e61f..37ddcf2786a 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -2736,9 +2736,9 @@ def test_drop_labels_by_keyword(self) -> None: ds5 = data.drop_sel(x=["a", "b"], y=range(0, 6, 2)) arr = DataArray(range(3), dims=["c"]) - with pytest.warns(FutureWarning): + with pytest.warns(DeprecationWarning): data.drop(arr.coords) - with pytest.warns(FutureWarning): + with pytest.warns(DeprecationWarning): data.drop(arr.xindexes) assert_array_equal(ds1.coords["x"], ["b"])