-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
pandas deprecates the method keyword in Index.get_loc, see pandas-dev/pandas#42269. Therefore we end up with about 5000 warnings in our upstream tests:
FutureWarning: Passing method to Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead
We should fix this before pandas releases because the warning will not be silent (FutureWarning) or ask pandas to give us more time and use a DeprecationWarning at the moment.
We use this here:
Lines 233 to 235 in 4bb9d9c
| indexer = self.index.get_loc( | |
| label_value, method=method, tolerance=tolerance | |
| ) |
Is this only ever called with one item? Then we might be able to use
indexer = self.index.get_indexer(
[label_value], method=method, tolerance=tolerance
).item()
if indexer == -1:
raise KeyError(label_value)Lines 571 to 572 in 3956b73
| imin = index.get_loc(minval, method="nearest") | |
| imax = index.get_loc(maxval, method="nearest") |
This one could be easy to fix (replace with
imin = index.get_indexer([minval], method="nearest").item())
It is also defined in CFTimeIndex, which complicates things:
xarray/xarray/coding/cftimeindex.py
Lines 461 to 466 in eea7673
| def get_loc(self, key, method=None, tolerance=None): | |
| """Adapted from pandas.tseries.index.DatetimeIndex.get_loc""" | |
| if isinstance(key, str): | |
| return self._get_string_slice(key) | |
| else: | |
| return pd.Index.get_loc(self, key, method=method, tolerance=tolerance) |
because get_indexer expects an iterable and thus the if isinstance(key, str) test no longer works.