Skip to content

Commit

Permalink
Speed up localize (#8536)
Browse files Browse the repository at this point in the history
Co-authored-by: Mathias Hauser <[email protected]>
  • Loading branch information
Illviljan and mathause authored May 6, 2024
1 parent 50f8726 commit faa6345
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions xarray/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,11 @@ def _localize(var, indexes_coords):
"""
indexes = {}
for dim, [x, new_x] in indexes_coords.items():
minval = np.nanmin(new_x.values)
maxval = np.nanmax(new_x.values)
new_x_loaded = new_x.values
minval = np.nanmin(new_x_loaded)
maxval = np.nanmax(new_x_loaded)
index = x.to_index()
imin = index.get_indexer([minval], method="nearest").item()
imax = index.get_indexer([maxval], method="nearest").item()
imin, imax = index.get_indexer([minval, maxval], method="nearest")
indexes[dim] = slice(max(imin - 2, 0), imax + 2)
indexes_coords[dim] = (x[indexes[dim]], new_x)
return var.isel(**indexes), indexes_coords
Expand Down

0 comments on commit faa6345

Please sign in to comment.