Skip to content

Commit f7945a3

Browse files
dcherianhmaarrfk
authored andcommitted
cleanup
1 parent 5bcf40c commit f7945a3

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

xarray/core/dataset.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,14 +2986,6 @@ def isel(
29862986
all_keys = set(indexers.keys())
29872987

29882988
for name, var in self._variables.items():
2989-
# preserve variable order
2990-
if name in index_variables:
2991-
var = index_variables[name]
2992-
dims.update(zip(var.dims, var.shape))
2993-
# Fastpath, skip all this metadata analysis for variables
2994-
# with no dimensions
2995-
# Keep the result of var.dims cached for future accesss to it
2996-
#
29972989
# Optimization Note from hmaarrfk - 2024/06
29982990
# https://github.com/pydata/xarray/pull/9003#discussion_r1592767493
29992991
# It was found that accessing var.dims is faster than
@@ -3002,21 +2994,24 @@ def isel(
30022994
# By using var.dims, we can avoid the cost of resolving the
30032995
# underlying array's shape and ndim since the dims are already
30042996
# cached by the Variable
3005-
elif len(var_dims := var.dims):
3006-
# Large datasets with alot of metadata may have many scalars
3007-
# without any relevant dimensions for slicing.
3008-
# Pick those out quickly and avoid paying the cost below
3009-
# of resolving the var_indexers variables
3010-
if var_indexer_keys := all_keys.intersection(var_dims):
2997+
var_dims = var.dims
2998+
# Fastpath, skip all this metadata analysis for variables
2999+
# with no dimensions
3000+
if var_dims:
3001+
# preserve variable order
3002+
if name in index_variables:
3003+
var = index_variables[name]
3004+
elif var_indexer_keys := all_keys.intersection(var_dims):
30113005
var_indexers = {k: indexers[k] for k in var_indexer_keys}
30123006
var = var.isel(var_indexers)
30133007
if drop and var.ndim == 0 and name in coord_names:
30143008
coord_names.remove(name)
30153009
continue
30163010
# Update our reference to `var_dims` after the call to isel
3011+
# to reflect any dropped dimensions
30173012
var_dims = var.dims
3018-
dims.update(zip(var_dims, var.shape))
30193013
variables[name] = var
3014+
dims.update(zip(var_dims, var.shape))
30203015

30213016
return self._construct_direct(
30223017
variables=variables,

0 commit comments

Comments
 (0)