-
-
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
COMPAT: Adjust CFTimeIndex.get_loc for pandas 2.0 deprecation enforcement #7361
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking out for this @mroeschke!
I wonder if it's appropriate to simply remove these arguments altogether following pandas? Since we were calling Index.get_loc
under the hood, the deprecation warning would have already been raised for anyone who used them (I suppose except in the case that a string key was provided, where the arguments would be ignored):
>>> import cftime; import xarray as xr
>>> times = xr.cftime_range("2000", periods=3)
>>> times.get_loc(cftime.DatetimeGregorian(2000, 1, 1), method="nearest")
/Users/spencer/software/xarray/xarray/coding/cftimeindex.py:468: FutureWarning: Passing method to CFTimeIndex.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead.
return pd.Index.get_loc(self, key, method=method, tolerance=tolerance)
0
I don't think this would break anything internally (I believe we already use get_indexer
in Dataset.sel
for instance).
Sure, happy to remove this |
Technically I think we would consider My inclination is that it would not require a deprecation cycle, given the warning had already been being raised as in the example above. It's true though that this warning was not being emitted in the case that |
I sometimes do this with a general @aulemahal does |
Hmm, I don't think so! Thanks for the heads up. |
I guess this could be a "Breaking Change" in the next release's What's New. Let me know if that's the direction you're still leaning |
Yes, I think that's what we'll end up going with @mroeschke. Thanks for your patience as we worked it out. |
Great added the whatsnew note and just removed the arguments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks!
Thanks @mroeschke |
* main: (41 commits) v2023.01.0 whats-new (pydata#7440) explain keep_attrs in docstring of apply_ufunc (pydata#7445) Add sentence to open_dataset docstring (pydata#7438) pin scipy version in doc environment (pydata#7436) Improve performance for backend datetime handling (pydata#7374) fix typo (pydata#7433) Add lazy backend ASV test (pydata#7426) Pull Request Labeler - Workaround sync-labels bug (pydata#7431) see also : groupby in resample doc and vice-versa (pydata#7425) Some alignment optimizations (pydata#7382) Make `broadcast` and `concat` work with the Array API (pydata#7387) remove `numbagg` and `numba` from the upstream-dev CI (pydata#7416) [pre-commit.ci] pre-commit autoupdate (pydata#7402) Preserve original dtype when accessing MultiIndex levels (pydata#7393) [pre-commit.ci] pre-commit autoupdate (pydata#7389) [pre-commit.ci] pre-commit autoupdate (pydata#7360) COMPAT: Adjust CFTimeIndex.get_loc for pandas 2.0 deprecation enforcement (pydata#7361) Avoid loading entire dataset by getting the nbytes in an array (pydata#7356) `keep_attrs` for pad (pydata#7267) Bump pypa/gh-action-pypi-publish from 1.5.1 to 1.6.4 (pydata#7375) ...
With the upcoming pandas 2.0 release, we are enforcing a deprecation in
pd.Index.get_loc
to removemethod
andtolerance
. Just in caseget_loc
isn't 100% compatible withget_indexer
, I structured theelif
to useget_loc
as much as possible. Let me know if any other adjustments are needed