Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion doc/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ index labels along a dimension dropped:
.. ipython:: python
:okwarning:

ds.drop(['IN', 'IL'], dim='space')
ds.drop(space=['IN', 'IL'])

``drop`` is both a ``Dataset`` and ``DataArray`` method.

Expand Down
4 changes: 3 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ Enhancements
By `David Brochart <https://github.com/davidbrochart>`_.

- :py:meth:`~xarray.Dataset.drop` now supports keyword arguments; dropping index
labels by specifying both ``dim`` and ``labels`` is deprecated (:issue:`2910`).
labels by using both ``dim`` and ``labels`` or using a
:py:class:`~xarray.core.coordinates.DataArrayCoordinates` object are
deprecated (:issue:`2910`).
By `Gregory Gundersen <https://github.com/gwgundersen/>`_.

- Added examples of :py:meth:`Dataset.set_index` and
Expand Down
10 changes: 8 additions & 2 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3548,8 +3548,7 @@ def drop( # noqa: F811
if errors not in ["raise", "ignore"]:
raise ValueError('errors must be either "raise" or "ignore"')

labels_are_coords = isinstance(labels, DataArrayCoordinates)
if labels_kwargs or (utils.is_dict_like(labels) and not labels_are_coords):
if labels_kwargs or isinstance(labels, dict):
labels_kwargs = utils.either_dict_or_kwargs(labels, labels_kwargs, "drop")
if dim is not None:
raise ValueError("cannot specify dim and dict-like arguments.")
Expand All @@ -3558,6 +3557,13 @@ def drop( # noqa: F811
ds = ds._drop_labels(labels, dim, errors=errors)
return ds
elif dim is None:
if isinstance(labels, DataArrayCoordinates):
warnings.warn(
"dropping coordinates using a DataArrayCoordinates object "
"is deprecated; use drop_vars or a list of coordinates",
DeprecationWarning,
stacklevel=2,
)
if isinstance(labels, str) or not isinstance(labels, Iterable):
labels = {labels}
else:
Expand Down