Skip to content

Commit 84293a1

Browse files
committed
5. Access .ndim only once
1 parent 16f5fa1 commit 84293a1

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
@@ -687,21 +687,22 @@ def interp_func(var, x, new_x, method, kwargs):
687687
if is_duck_dask_array(var):
688688
import dask.array as da
689689

690-
nconst = var.ndim - len(x)
690+
ndim = var.ndim
691+
nconst = ndim - len(x)
691692

692-
out_ind = list(range(nconst)) + list(range(var.ndim, var.ndim + new_x[0].ndim))
693+
out_ind = list(range(nconst)) + list(range(ndim, ndim + new_x[0].ndim))
693694

694695
# blockwise args format
695696
x_arginds = [[_x, (nconst + index,)] for index, _x in enumerate(x)]
696697
x_arginds = [item for pair in x_arginds for item in pair]
697698
new_x_arginds = [
698-
[_x, [var.ndim + index for index in range(_x.ndim)]] for _x in new_x
699+
[_x, [ndim + index for index in range(_x.ndim)]] for _x in new_x
699700
]
700701
new_x_arginds = [item for pair in new_x_arginds for item in pair]
701702

702703
args = (
703704
var,
704-
range(var.ndim),
705+
range(ndim),
705706
*x_arginds,
706707
*new_x_arginds,
707708
)
@@ -713,7 +714,7 @@ def interp_func(var, x, new_x, method, kwargs):
713714
new_x = rechunked[1 + (len(rechunked) - 1) // 2 :]
714715

715716
new_axes = {
716-
var.ndim + i: new_x[0].chunks[i]
717+
ndim + i: new_x[0].chunks[i]
717718
if new_x[0].chunks is not None
718719
else new_x[0].shape[i]
719720
for i in range(new_x[0].ndim)

0 commit comments

Comments
 (0)