Skip to content

Commit 293fa1f

Browse files
owena11shoyer
andauthored
Validation for DataArray indexing
Add additional validation for `drop_sel` such that when selecting with a DataArray the dimensions must be named consistently between the DataArray and the dimension you're dropping the selection from. This matches the behaviour with `sel`. Co-authored-by: Stephan Hoyer <shoyer@google.com>
1 parent 22aadff commit 293fa1f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

xarray/core/dataset.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6082,6 +6082,12 @@ def drop_sel(
60826082
# DataArrays are a special case where the underlying libraries don't provide
60836083
# a good conversition.
60846084
if isinstance(labels_for_dim, DataArray):
6085+
if labels_for_dim.dims not in ((), (dim,)):
6086+
raise ValueError(
6087+
"cannot use drop_sel() with DataArray values with "
6088+
"along dimensions other than the dimensions being "
6089+
f"indexed along: {labels_for_dim}"
6090+
)
60856091
labels_for_dim = np.asarray(labels_for_dim)
60866092
try:
60876093
index = self.get_index(dim)

0 commit comments

Comments
 (0)