Skip to content

Disallow standard calendar np.datetime64 encoding prior to reform #10352

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

Conversation

spencerkclark
Copy link
Member

@spencerkclark spencerkclark commented May 24, 2025

In #9618 we allowed encoding np.datetime64 values prior to 1582-10-15 using a "standard" or "gregorian" calendar through cftime. While technically possible, this implicitly introduces a calendar change, and means the values can no longer be round tripped as np.datetime64—xarray will choose cftime.DatetimeGregorian instances when decoding instead. I am not sure how often this will come up and the behavior may not be the user's intent.

This PR switches to raising a ValueError in this circumstance, and recommends encoding with a "proleptic_gregorian" calendar instead (the calendar that xarray automatically chooses for np.datetime64 values if provided no user input).

cc: @kmuehlbauer (this is one possible way to address the issue in #8324)

  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst

@kmuehlbauer
Copy link
Contributor

@spencerkclark +1 to have the user decide.

@spencerkclark
Copy link
Member Author

Sounds good—thanks @kmuehlbauer—I'll merge this in so we can move forward with #8324.

@spencerkclark spencerkclark merged commit 07430e1 into pydata:main May 26, 2025
32 checks passed
@spencerkclark spencerkclark deleted the disallow-standard-calendar-encoding-prior-to-reform branch May 26, 2025 12:57
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.

2 participants