Skip to content

Fix polyval returning a sentinel value for NaT in timedelta coordinates - #11478

Merged
dcherian merged 1 commit into
pydata:mainfrom
dchaudhari7177:fix/polyval-timedelta-nat
Jul 29, 2026
Merged

Fix polyval returning a sentinel value for NaT in timedelta coordinates#11478
dcherian merged 1 commit into
pydata:mainfrom
dchaudhari7177:fix/polyval-timedelta-nat

Conversation

@dchaudhari7177

Copy link
Copy Markdown
Contributor

Fixes#11462.

_ensure_numeric (used by polyval and polyfit) converts a timedelta64 coordinate with a plain astype(float). NaT is stored as the int64 minimum, so that cast turned it into a large sentinel (-1.84e19) rather than propagating a missing value.

Fix: mask the NaT positions back to NaN after the cast (.where(x.notnull())), mirroring the datetime_to_numeric path used for the datetime branch. Valid values keep their existing numeric scale, so only the previously-bogus NaT output changes.

MCVE from the issue now returns [1.0, nan, 345601.0] as expected. Added test_polyval_timedelta_nat (fails on main, passes with the fix); the existing polyval tests stay green. Added a whats-new.rst entry.

@welcome

welcomeBot commented Jul 27, 2026

Copy link
Copy Markdown

Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient.
If you have questions, some answers may be found in our contributing guidelines.

@dcherian
dcherian merged commit 0c2d2b4 into pydata:mainJul 29, 2026
42 of 43 checks passed
@welcome

welcomeBot commented Jul 29, 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

sdiebolt pushed a commit to sdiebolt/xarray that referenced this pull request Aug 12, 2026
Sign up for freeto 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.

xr.polyval returns bogus values for NaT in timedelta arrays

2 participants

@dchaudhari7177@dcherian