Skip to content

Commit b437815

Browse files
committed
Add more comment
1 parent d7fafd7 commit b437815

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
@@ -2988,8 +2988,18 @@ def isel(
29882988
if name in index_variables:
29892989
var = index_variables[name]
29902990
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
29933003
elif len(var_dims := var.dims):
29943004
# Large datasets with alot of metadata may have many scalars
29953005
# without any relevant dimensions for slicing.

0 commit comments

Comments
 (0)