Skip to content

Center datetime coordinates before converting them to float in interpolate_na - #11958

Open
headtr1ck wants to merge 2 commits into
pydata:mainfrom
headtr1ck:interp-index-offset
Open

headtr1ck wants to merge 2 commits into
pydata:mainfrom
headtr1ck:interp-index-offset

Conversation

@headtr1ck

Copy link
Copy Markdown
Collaborator

Description

interpolate_na converted datetime coordinates to float64 nanoseconds since 1970. For present-day timestamps that's about 1.6e18, beyond 2**53, so they lose precision: e.g. timestamps 1 ns apart in 2020 collapse, and [0, nan, 3] on them was interpolated to [0, 3, 3]. This uses the smallest value of the index as offset instead, like pandas now does (pandas-dev/pandas#70989).

  • The 1970 offset was shared with polyfit and curvefit, but they use _ensure_numeric since Add support for coordinate inputs in polyfit. #9369, so get_clean_interp_index is only used for interpolation now.
  • max_gap and limit only use differences of the index, so the shift doesn't affect them.
  • test_interpolate_pd_compat_non_uniform_index fails in the nightly CI since pandas fixed the same precision loss. It now passes against pandas main; for older pandas it gets atol=1e-10, since pandas is then the imprecise side.

Checklist

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 (Claude Opus 5.5)

🤖 Generated with Claude Code

headtr1ck and others added 2 commits November 30, 2026 21:12
…olate_na

Nanosecond timestamps far from 1970 are beyond 2**53 and lose precision in
float64. Use the smallest value of the index as offset instead, like pandas.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant