Skip to content

Commit b016dce

Browse files
committed
Add more comment
1 parent 53dc76e commit b016dce

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

xarray/core/dataset.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2990,8 +2990,18 @@ def isel(
29902990
if name in index_variables:
29912991
var = index_variables[name]
29922992
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
29953005
elif len(var_dims := var.dims):
29963006
# Large datasets with alot of metadata may have many scalars
29973007
# without any relevant dimensions for slicing.

0 commit comments

Comments
 (0)