Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian authored and hmaarrfk committed Jun 22, 2024
1 parent 372dd9e commit 1f072d6
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2995,19 +2995,20 @@ def isel(
# underlying array's shape and ndim since the dims are already
# cached by the Variable
var_dims = var.dims
# preserve variable order
if name in index_variables:
var = index_variables[name]
# Fastpath, skip all this metadata analysis for variables
# with no dimensions
elif var_dims and (var_indexer_keys := all_keys.intersection(var_dims)):
var_indexers = {k: indexers[k] for k in var_indexer_keys}
var = var.isel(var_indexers)
if drop and var.ndim == 0 and name in coord_names:
coord_names.remove(name)
continue
if var_dims:
# preserve variable order
if name in index_variables:
var = index_variables[name]
elif var_indexer_keys := all_keys.intersection(var_dims):
var_indexers = {k: indexers[k] for k in var_indexer_keys}
var = var.isel(var_indexers)
if drop and var.ndim == 0 and name in coord_names:
coord_names.remove(name)
continue
variables[name] = var
dims.update(zip(var.dims, var.shape))
dims.update(zip(var_dims, var.shape))

return self._construct_direct(
variables=variables,
Expand Down

0 comments on commit 1f072d6

Please sign in to comment.