Skip to content

fix: support datetime variables in Dataset.interp#11081

Merged
spencerkclark merged 12 commits intopydata:mainfrom
emmanuel-ferdman:main
Mar 17, 2026
Merged

fix: support datetime variables in Dataset.interp#11081
spencerkclark merged 12 commits intopydata:mainfrom
emmanuel-ferdman:main

Conversation

@emmanuel-ferdman
Copy link
Copy Markdown
Contributor

PR Summary

Dataset.interp() silently dropped datetime64 and timedelta64 variables. Now they are interpolated by converting to float64 and back, with NaT handled like NaN.

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Copy link
Copy Markdown
Member

@spencerkclark spencerkclark left a comment

Choose a reason for hiding this comment

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

Thanks @emmanuel-ferdman—this largely looks good.

Could you add "Mm" to the valid dtypes on the DataArray.interp side as well? There is no need now to raise in that circumstance, which is great.

One edge case to consider is what to do in the scenario that extrapolation leads to float values outside the range that can be represented by 64-bit integers. Maybe we punt on that for now though, since it could be messy to handle in a robust way.

Comment thread xarray/core/dataset.py Outdated
Comment thread xarray/tests/test_interp.py Outdated
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
@emmanuel-ferdman
Copy link
Copy Markdown
Contributor Author

@spencerkclark Thanks, updated :) Regarding the offset-based approach, I think we could subtract the minimum datetime before converting to float, which gives nanosecond precision - but it would break dask laziness since we'd need to compute .min().

Copy link
Copy Markdown
Member

@spencerkclark spencerkclark left a comment

Choose a reason for hiding this comment

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

Thanks @emmanuel-ferdman! This looks good from my perspective.

Comment thread doc/whats-new.rst Outdated
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Comment thread doc/whats-new.rst Outdated
@spencerkclark spencerkclark added the plan to merge Final call for comments label Mar 7, 2026
@spencerkclark spencerkclark enabled auto-merge (squash) March 14, 2026 16:27
@spencerkclark spencerkclark merged commit d937ce6 into pydata:main Mar 17, 2026
40 checks passed
@welcome
Copy link
Copy Markdown

welcome Bot commented Mar 17, 2026

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

jsignell pushed a commit to jsignell/xarray that referenced this pull request Apr 15, 2026
`Dataset.interp()` silently dropped `datetime64` and `timedelta64` variables. Now they are interpolated by converting to `float64` and back, with `NaT` handled like `NaN`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plan to merge Final call for comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dataset.interp() silently dropping time-like data arrays

2 participants