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
2 people authored and andersy005 committed May 10, 2024
1 parent bce79d5 commit 4e31a22
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 4e31a22

Please sign in to comment.