Skip to content

Commit 93ea177

Browse files
authored
fix issues in drop_sel and drop_isel (#4828)
1 parent 7dbbdca commit 93ea177

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

xarray/core/dataset.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -4021,30 +4021,38 @@ def drop_sel(self, labels=None, *, errors="raise", **labels_kwargs):
40214021
40224022
Examples
40234023
--------
4024-
>>> data = np.random.randn(2, 3)
4024+
>>> data = np.arange(6).reshape(2, 3)
40254025
>>> labels = ["a", "b", "c"]
40264026
>>> ds = xr.Dataset({"A": (["x", "y"], data), "y": labels})
4027+
>>> ds
4028+
<xarray.Dataset>
4029+
Dimensions: (x: 2, y: 3)
4030+
Coordinates:
4031+
* y (y) <U1 'a' 'b' 'c'
4032+
Dimensions without coordinates: x
4033+
Data variables:
4034+
A (x, y) int64 0 1 2 3 4 5
40274035
>>> ds.drop_sel(y=["a", "c"])
40284036
<xarray.Dataset>
40294037
Dimensions: (x: 2, y: 1)
40304038
Coordinates:
40314039
* y (y) <U1 'b'
40324040
Dimensions without coordinates: x
40334041
Data variables:
4034-
A (x, y) float64 0.4002 1.868
4042+
A (x, y) int64 1 4
40354043
>>> ds.drop_sel(y="b")
40364044
<xarray.Dataset>
40374045
Dimensions: (x: 2, y: 2)
40384046
Coordinates:
40394047
* y (y) <U1 'a' 'c'
40404048
Dimensions without coordinates: x
40414049
Data variables:
4042-
A (x, y) float64 1.764 0.9787 2.241 -0.9773
4050+
A (x, y) int64 0 2 3 5
40434051
"""
40444052
if errors not in ["raise", "ignore"]:
40454053
raise ValueError('errors must be either "raise" or "ignore"')
40464054

4047-
labels = either_dict_or_kwargs(labels, labels_kwargs, "drop")
4055+
labels = either_dict_or_kwargs(labels, labels_kwargs, "drop_sel")
40484056

40494057
ds = self
40504058
for dim, labels_for_dim in labels.items():
@@ -4110,7 +4118,7 @@ def drop_isel(self, indexers=None, **indexers_kwargs):
41104118
A (x, y) int64 0 2 3 5
41114119
"""
41124120

4113-
indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "drop")
4121+
indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "drop_isel")
41144122

41154123
ds = self
41164124
dimension_index = {}

xarray/tests/test_dataarray.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2329,7 +2329,7 @@ def test_drop_index_labels(self):
23292329

23302330
def test_drop_index_positions(self):
23312331
arr = DataArray(np.random.randn(2, 3), dims=["x", "y"])
2332-
actual = arr.drop_sel(y=[0, 1])
2332+
actual = arr.drop_isel(y=[0, 1])
23332333
expected = arr[:, 2:]
23342334
assert_identical(actual, expected)
23352335

0 commit comments

Comments
 (0)