From ed20d1a46a16afe191115041dd3401f15130c94d Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Wed, 26 Jan 2022 14:30:53 +0100 Subject: [PATCH] MAINT: pd: no longer use get_loc with method --- xarray/core/indexes.py | 11 ++++++++--- xarray/core/missing.py | 5 ++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/xarray/core/indexes.py b/xarray/core/indexes.py index 844751f24bb..b66fbdf6504 100644 --- a/xarray/core/indexes.py +++ b/xarray/core/indexes.py @@ -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: diff --git a/xarray/core/missing.py b/xarray/core/missing.py index 2525272f719..f3bb5351db5 100644 --- a/xarray/core/missing.py +++ b/xarray/core/missing.py @@ -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