Skip to content

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

Merged
spencerkclark merged 1 commit into
pydata:mainfrom
spencerkclark:disallow-standard-calendar-encoding-prior-to-reform
May 26, 2025
Merged

Disallow standard calendar np.datetime64 encoding prior to reform#10352
spencerkclark merged 1 commit into
pydata:mainfrom
spencerkclark:disallow-standard-calendar-encoding-prior-to-reform

Conversation

@spencerkclark

@spencerkclarkspencerkclark commented May 24, 2025

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor

@spencerkclark +1 to have the user decide.

@spencerkclark

Copy link
Copy Markdown
MemberAuthor

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

@spencerkclark
spencerkclark merged commit 07430e1 into pydata:mainMay 26, 2025
@spencerkclark
spencerkclark deleted the disallow-standard-calendar-encoding-prior-to-reform branch May 26, 2025 12:57
Sign up for freeto 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

@spencerkclark@kmuehlbauer