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

Adopt new pandas frequency codes #1534

Closed
2 tasks done
aulemahal opened this issue Nov 22, 2023 · 0 comments · Fixed by #1565
Closed
2 tasks done

Adopt new pandas frequency codes #1534

aulemahal opened this issue Nov 22, 2023 · 0 comments · Fixed by #1565
Assignees
Labels
bug Something isn't working enhancement New feature or request priority Immediate priority standards / conventions Suggestions on ways forward
Milestone

Comments

@aulemahal
Copy link
Collaborator

aulemahal commented Nov 22, 2023

Addressing a Problem?

Pandas has made changes to the frequency string codes, which will begin in version 2.2.

The first step is the introduction of a new set of default codes:

  • A -> Y
  • H -> h
  • T -> min
  • S -> s (and so on for smaller periods)

And the addition of the "E" suffix to denote a frequency anchored at the end of the period (instead of it being the default when not mentioned) (applies to Q, and M).

All the previous codes are now deprecated, but will be valid inputs for 2.2.

Potential Solution

If we change all the hardcoded codes to the new ones, we will need to pin pandas, so a temporary dynamic solution might be necessary (as done in xarray, but more complex).

I suggest a ensure_correct_freq() function that is called everywhere a frequency code is sent to xarray/pandas. The function will translate using the old or the new version depending on the installed version of pandas.

Additional context

The function could be removed when we pin pandas >= 2.2 and all codes written with the new syntax.

xscen could make use of that function also, if needed.

See xarray issue, PR and links to the Pandas issues : pydata/xarray#8394

Contribution

  • I would be willing/able to open a Pull Request to contribute this feature.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@aulemahal aulemahal added bug Something isn't working enhancement New feature or request standards / conventions Suggestions on ways forward priority Immediate priority labels Nov 22, 2023
@aulemahal aulemahal added this to the v0.47.0 milestone Nov 22, 2023
@aulemahal aulemahal self-assigned this Nov 22, 2023
@Zeitsperre Zeitsperre mentioned this issue Nov 22, 2023
5 tasks
aulemahal added a commit that referenced this issue Nov 29, 2023
<!--Please ensure the PR fulfills the following requirements! -->
<!-- If this is your first PR, make sure to add your details to the
AUTHORS.rst! -->
### Pull Request Checklist:
- [x] This PR addresses an already opened issue (for bug fixes /
features)
- This PR is a temporary fix. #1534 will be fixed by inverting the pins
in the next release (0.48).
- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] (If applicable) Documentation has been added / updated (for bug
fixes / features)
- [x] CHANGES.rst has been updated (with summary of main changes)
- [ ] Link to issue (:issue:`number`) and pull request (:pull:`number`)
has been added

### What kind of change does this PR introduce?

* Pins xarray under 2023.11 and pandas under 2.2 (which is not yet
released).

### Does this PR introduce a breaking change?

No.

I expect the "upstream" builds to fail, errors related to frequencies
are ok and will be fixed in the near future.

### Other information:
The plan of inverting the pins in 0.48 implies that 0.47 will be the
last version supporting python 3.8.
@Zeitsperre Zeitsperre modified the milestones: v0.47.0, v0.48.0 Nov 30, 2023
Zeitsperre added a commit to bird-house/finch that referenced this issue Dec 5, 2023
## Overview

Changes:

* Added pins to xarray and pandas to prevent issues with breaking
changes.
* Fixed an error with a cftime index fixing function.
* Switched `bump2version` for `bump-my-version`
* Do not fail when running pip check in conda environments

## Related Issue / Discussion

Ouranosinc/xclim#1534
pydata/xarray#8394
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request priority Immediate priority standards / conventions Suggestions on ways forward
Projects
None yet
2 participants