-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pandas deprecates Index.get_loc with method #5721
Comments
Thanks for the heads up @mathause. We'll need to think carefully about this with respect to partial datetime string indexing.
In other words -- at least for partial datetime string indexing -- it may not be as simple as swapping in Perhaps @jbrockmendel has thoughts on how we should approach this? |
These lines seem to be the problematic place? Lines 233 to 235 in e26aec9
We might be able to do something like: if method is not None:
indexer = get_indexer_nd(self.index, label, method, tolerance)
else:
indexer = self.index.get_loc(label_value) |
Exactly, yeah, those are the problematic lines. That's an elegant solution. I think it will work with the minor modification to raise a 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) |
The "if method is not None" approach seems reasonable. |
👍 I can take care of it in #5692 or in a separate PR. |
I don't have a strong opinion but would be good to do this before the next release. |
Not sure that #5692 will be ready for the next release so I'll do this in a separate PR. |
pandas deprecates the
method
keyword inIndex.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 aDeprecationWarning
at the moment.We use this here:
xarray/xarray/core/indexes.py
Lines 233 to 235 in 4bb9d9c
Is this only ever called with one item? Then we might be able to use
xarray/xarray/core/missing.py
Lines 571 to 572 in 3956b73
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
because
get_indexer
expects an iterable and thus theif isinstance(key, str)
test no longer works.@benbovy @spencerkclark
The text was updated successfully, but these errors were encountered: