Skip to content
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

Deprecate certain cftime frequency strings following pandas #8415

Merged
merged 3 commits into from Nov 16, 2023

Conversation

spencerkclark
Copy link
Member

Following several upstream PRs in pandas, this PR deprecates cftime frequency strings "A", "AS", "Q", "M", "H", "T", "S", "L", and "U" in favor of "Y", "YS", "QE", "ME", "h", "min", "s", "ms", and "us". Similarly following pandas, it makes a breaking change to have infer_freq return the latter frequencies instead of the former.

There are a few places in the tests and one place in the code where we need some version-specific logic to retain support for older pandas versions. @aulemahal it would be great if you could take a look to make sure that I handled this breaking change properly / fully in the date_range_like case.

I also took the liberty to transition to using "Y", "YS", "h", "min", "s", "ms", "us", and "ns" within our code, tests, and documentation to reduce the amount of warnings emitted. I have held off on switching to "QE", "ME", and anchored offsets involving "Y" or "YS" in pandas-related code since those are not supported in older versions of pandas.

The deprecation warning looks like this:

>>> xr.cftime_range("2000", periods=5, freq="M")
<stdin>:1: FutureWarning: 'M' is deprecated and will be removed in a future version. Please use 'ME' instead of 'M'.
CFTimeIndex([2000-01-31 00:00:00, 2000-02-29 00:00:00, 2000-03-31 00:00:00,
             2000-04-30 00:00:00, 2000-05-31 00:00:00],
            dtype='object', length=5, calendar='standard', freq='ME')

Specifically the frequency strings "A", "AS", "Q", "M", "H", "T", "S", "L",
"U", and "N" are deprecated in favor of "Y", "YS", "QE", "ME", "h", "min", "s",
"ms", "us", and "ns", respectively.
Co-authored-by: Pascal Bourgault <bourgault.pascal@ouranos.ca>
@dcherian
Copy link
Contributor

@spencerkclark are we good to merge here?

@spencerkclark
Copy link
Member Author

Indeed I do not have anything to add.

Thanks for taking a look earlier @aulemahal — are you on board with the changes I made to date_range_like to maintain compatibility with older versions of pandas, as well as the updates to the date_range_like and convert_calendar tests?

@aulemahal
Copy link
Contributor

I am on board with these changes! Thanks.

@dcherian dcherian merged commit dfe6435 into pydata:main Nov 16, 2023
25 of 28 checks passed
@spencerkclark spencerkclark deleted the update-cftime-frequency-strings branch November 16, 2023 15:37
dcherian added a commit to rabernat/xarray that referenced this pull request Nov 29, 2023
* main:
  [skip-ci] dev whats-new (pydata#8467)
  2023.11.0 Whats-new (pydata#8461)
  migrate the other CI to python 3.11 (pydata#8416)
  preserve vlen string dtypes, allow vlen string fill_values (pydata#7869)
  Pin mypy < 1.7 (pydata#8458)
  Fix typos found by codespell (pydata#8457)
  [skip-ci] Small updates to IO docs. (pydata#8452)
  Deprecate certain cftime frequency strings following pandas (pydata#8415)
  Added driver parameter for h5netcdf (pydata#8360)
  Raise exception in to_dataset if resulting variable is also the name of a coordinate (pydata#8433)
  Automatic region detection and transpose for `to_zarr()` (pydata#8434)
  remove `cdms2` (pydata#8441)
  Remove PseudoNetCDF (pydata#8446)
  Pin pint to >=0.22 (pydata#8445)
  Remove keep_attrs from resample signature (pydata#8444)
  Rename `to_array` to `to_dataarray` (pydata#8438)
  Add missing DataArray.dt.total_seconds() method (pydata#8435)
  Declare Dataset, DataArray, Variable, GroupBy unhashable (pydata#8392)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update cftime frequency strings in line with recent updates in pandas
3 participants