Skip to content

Commit faa6345

Browse files
Illviljanmathause
andauthored
Speed up localize (#8536)
Co-authored-by: Mathias Hauser <mathause@users.noreply.github.com>
1 parent 50f8726 commit faa6345

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

xarray/core/missing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,11 @@ def _localize(var, indexes_coords):
553553
"""
554554
indexes = {}
555555
for dim, [x, new_x] in indexes_coords.items():
556-
minval = np.nanmin(new_x.values)
557-
maxval = np.nanmax(new_x.values)
556+
new_x_loaded = new_x.values
557+
minval = np.nanmin(new_x_loaded)
558+
maxval = np.nanmax(new_x_loaded)
558559
index = x.to_index()
559-
imin = index.get_indexer([minval], method="nearest").item()
560-
imax = index.get_indexer([maxval], method="nearest").item()
560+
imin, imax = index.get_indexer([minval, maxval], method="nearest")
561561
indexes[dim] = slice(max(imin - 2, 0), imax + 2)
562562
indexes_coords[dim] = (x[indexes[dim]], new_x)
563563
return var.isel(**indexes), indexes_coords

0 commit comments

Comments
 (0)