Skip to content

Commit 2f00913

Browse files
authored
Fully deprecate .drop (#8497)
* Fully deprecate `.drop` I think it's time...
1 parent 5213f0d commit 2f00913

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

doc/whats-new.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ Deprecations
5151
currently ``PendingDeprecationWarning``, which are silenced by default. We'll
5252
convert these to ``DeprecationWarning`` in a future release.
5353
By `Maximilian Roos <https://github.com/max-sixty>`_.
54+
- :py:meth:`Dataset.drop` &
55+
:py:meth:`DataArray.drop` are now deprecated, since pending deprecation for
56+
several years. :py:meth:`DataArray.drop_sel` & :py:meth:`DataArray.drop_var`
57+
replace them for labels & variables respectively.
5458

5559
Bug fixes
5660
~~~~~~~~~

xarray/core/dataset.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
decode_numpy_dict_values,
112112
drop_dims_from_indexers,
113113
either_dict_or_kwargs,
114+
emit_user_level_warning,
114115
infix_dims,
115116
is_dict_like,
116117
is_scalar,
@@ -5944,10 +5945,9 @@ def drop(
59445945
raise ValueError('errors must be either "raise" or "ignore"')
59455946

59465947
if is_dict_like(labels) and not isinstance(labels, dict):
5947-
warnings.warn(
5948-
"dropping coordinates using `drop` is be deprecated; use drop_vars.",
5949-
FutureWarning,
5950-
stacklevel=2,
5948+
emit_user_level_warning(
5949+
"dropping coordinates using `drop` is deprecated; use drop_vars.",
5950+
DeprecationWarning,
59515951
)
59525952
return self.drop_vars(labels, errors=errors)
59535953

@@ -5957,10 +5957,9 @@ def drop(
59575957
labels = either_dict_or_kwargs(labels, labels_kwargs, "drop")
59585958

59595959
if dim is None and (is_scalar(labels) or isinstance(labels, Iterable)):
5960-
warnings.warn(
5961-
"dropping variables using `drop` will be deprecated; using drop_vars is encouraged.",
5962-
PendingDeprecationWarning,
5963-
stacklevel=2,
5960+
emit_user_level_warning(
5961+
"dropping variables using `drop` is deprecated; use drop_vars.",
5962+
DeprecationWarning,
59645963
)
59655964
return self.drop_vars(labels, errors=errors)
59665965
if dim is not None:
@@ -5972,10 +5971,9 @@ def drop(
59725971
)
59735972
return self.drop_sel({dim: labels}, errors=errors, **labels_kwargs)
59745973

5975-
warnings.warn(
5976-
"dropping labels using `drop` will be deprecated; using drop_sel is encouraged.",
5977-
PendingDeprecationWarning,
5978-
stacklevel=2,
5974+
emit_user_level_warning(
5975+
"dropping labels using `drop` is deprecated; use `drop_sel` instead.",
5976+
DeprecationWarning,
59795977
)
59805978
return self.drop_sel(labels, errors=errors)
59815979

xarray/tests/test_dataset.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,19 +2651,19 @@ def test_drop_variables(self) -> None:
26512651

26522652
# deprecated approach with `drop` works (straight copy paste from above)
26532653

2654-
with pytest.warns(PendingDeprecationWarning):
2654+
with pytest.warns(DeprecationWarning):
26552655
actual = data.drop("not_found_here", errors="ignore")
26562656
assert_identical(data, actual)
26572657

2658-
with pytest.warns(PendingDeprecationWarning):
2658+
with pytest.warns(DeprecationWarning):
26592659
actual = data.drop(["not_found_here"], errors="ignore")
26602660
assert_identical(data, actual)
26612661

2662-
with pytest.warns(PendingDeprecationWarning):
2662+
with pytest.warns(DeprecationWarning):
26632663
actual = data.drop(["time", "not_found_here"], errors="ignore")
26642664
assert_identical(expected, actual)
26652665

2666-
with pytest.warns(PendingDeprecationWarning):
2666+
with pytest.warns(DeprecationWarning):
26672667
actual = data.drop({"time", "not_found_here"}, errors="ignore")
26682668
assert_identical(expected, actual)
26692669

@@ -2736,9 +2736,9 @@ def test_drop_labels_by_keyword(self) -> None:
27362736
ds5 = data.drop_sel(x=["a", "b"], y=range(0, 6, 2))
27372737

27382738
arr = DataArray(range(3), dims=["c"])
2739-
with pytest.warns(FutureWarning):
2739+
with pytest.warns(DeprecationWarning):
27402740
data.drop(arr.coords)
2741-
with pytest.warns(FutureWarning):
2741+
with pytest.warns(DeprecationWarning):
27422742
data.drop(arr.xindexes)
27432743

27442744
assert_array_equal(ds1.coords["x"], ["b"])

0 commit comments

Comments
 (0)