Skip to content

Commit baf672c

Browse files
committed
5. Access .ndim only once
1 parent fbb5ba9 commit baf672c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

xarray/core/missing.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,21 +695,22 @@ def interp_func(var, x, new_x, method, kwargs):
695695
if is_duck_dask_array(var):
696696
import dask.array as da
697697

698-
nconst = var.ndim - len(x)
698+
ndim = var.ndim
699+
nconst = ndim - len(x)
699700

700-
out_ind = list(range(nconst)) + list(range(var.ndim, var.ndim + new_x[0].ndim))
701+
out_ind = list(range(nconst)) + list(range(ndim, ndim + new_x[0].ndim))
701702

702703
# blockwise args format
703704
x_arginds = [[_x, (nconst + index,)] for index, _x in enumerate(x)]
704705
x_arginds = [item for pair in x_arginds for item in pair]
705706
new_x_arginds = [
706-
[_x, [var.ndim + index for index in range(_x.ndim)]] for _x in new_x
707+
[_x, [ndim + index for index in range(_x.ndim)]] for _x in new_x
707708
]
708709
new_x_arginds = [item for pair in new_x_arginds for item in pair]
709710

710711
args = (
711712
var,
712-
range(var.ndim),
713+
range(ndim),
713714
*x_arginds,
714715
*new_x_arginds,
715716
)
@@ -721,7 +722,7 @@ def interp_func(var, x, new_x, method, kwargs):
721722
new_x = rechunked[1 + (len(rechunked) - 1) // 2 :]
722723

723724
new_axes = {
724-
var.ndim + i: new_x[0].chunks[i]
725+
ndim + i: new_x[0].chunks[i]
725726
if new_x[0].chunks is not None
726727
else new_x[0].shape[i]
727728
for i in range(new_x[0].ndim)

0 commit comments

Comments
 (0)