File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -2988,8 +2988,18 @@ def isel(
2988
2988
if name in index_variables :
2989
2989
var = index_variables [name ]
2990
2990
dims .update (zip (var .dims , var .shape ))
2991
- # Fastpath, skip all of this for variables with no dimensions
2992
- # Keep the result cached for future dictionary update
2991
+ # Fastpath, skip all this metadata analysis for variables
2992
+ # with no dimensions
2993
+ # Keep the result of var.dims cached for future accesss to it
2994
+ #
2995
+ # Optimization Note from hmaarrfk - 2024/06
2996
+ # https://github.com/pydata/xarray/pull/9003#discussion_r1592767493
2997
+ # It was found that accessing var.dims is faster than
2998
+ # using var.shape or var.ndim since resolving both is typically
2999
+ # left to the underlying array that each Xarray structure wraps.
3000
+ # By using var.dims, we can avoid the cost of resolving the
3001
+ # underlying array's shape and ndim since the dims are already
3002
+ # cached by the Variable
2993
3003
elif len (var_dims := var .dims ):
2994
3004
# Large datasets with alot of metadata may have many scalars
2995
3005
# without any relevant dimensions for slicing.
You can’t perform that action at this time.
0 commit comments