Skip to content
forked from pydata/xarray

Commit

Permalink
MAINT: pandas 1.4: no longer use get_loc with method (pydata#6195)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathause authored Jan 27, 2022
1 parent 10bfa77 commit 4692c59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 8 additions & 3 deletions xarray/core/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,14 @@ def query(self, labels, method=None, tolerance=None):
)
indexer = self.index.get_loc(label_value)
else:
indexer = self.index.get_loc(
label_value, method=method, tolerance=tolerance
)
if method is not None:
indexer = get_indexer_nd(self.index, label, method, tolerance)
if np.any(indexer < 0):
raise KeyError(
f"not all values found in index {coord_name!r}"
)
else:
indexer = self.index.get_loc(label_value)
elif label.dtype.kind == "b":
indexer = label
else:
Expand Down
5 changes: 2 additions & 3 deletions xarray/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,8 @@ def _localize(var, indexes_coords):
minval = np.nanmin(new_x.values)
maxval = np.nanmax(new_x.values)
index = x.to_index()
imin = index.get_loc(minval, method="nearest")
imax = index.get_loc(maxval, method="nearest")

imin = index.get_indexer([minval], method="nearest").item()
imax = index.get_indexer([maxval], method="nearest").item()
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 4692c59

Please sign in to comment.