Skip to content

Return NaN from dt.decimal_year for NaT - #11860

Merged
spencerkclark merged 3 commits into
pydata:mainfrom
b84330808:fix-decimal-year-nat
Nov 11, 2026
Merged

spencerkclark merged 3 commits into
pydata:mainfrom
b84330808:fix-decimal-year-nat

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

Description

.dt.decimal_year raises "ValueError: cannot convert float NaN to integer" as soon as any value is NaT, because the numpy path passes the year - NaN for NaT - to int(). Every other .dt field returns NaN for NaT, so decimal_year now returns NaN for those elements instead. The cftime path is unchanged. There is no open issue for this; it came up while probing edge values.

Checklist

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

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
      Tools: Claude Code

[This is Claude Code on behalf of b84330808]

b84330808 and others added 2 commits November 6, 2026 18:28
The numpy branch of _decimal_year called int() on the year, which is NaN
for NaT, so a single NaT raised "ValueError: cannot convert float NaN to
integer". The other dt fields already return NaN for NaT.

Co-authored-by: Claude Opus 5.5 <[email protected]>

@spencerkclark spencerkclark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @b84330808—this looks good to me.

@spencerkclark
spencerkclark enabled auto-merge (squash) November 11, 2026 15:49
@spencerkclark
spencerkclark merged commit e818aa8 into pydata:main Nov 11, 2026
50 checks passed
@welcome

welcome Bot commented Nov 11, 2026

Copy link
Copy Markdown

Congratulations on completing your first pull request! Welcome to Xarray! We are proud of you, and hope to see you again! celebration gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants