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