Skip to content

Fix to_datetime nanosecond inference and DatetimeIndex tz wall-time interpretation - #23141

Merged
rapids-bot[bot] merged 4 commits into
NVIDIA:mainfrom
galipremsagar:datetime_tz_ns_fixes
Jul 7, 2026
Merged

Fix to_datetime nanosecond inference and DatetimeIndex tz wall-time interpretation#23141
rapids-bot[bot] merged 4 commits into
NVIDIA:mainfrom
galipremsagar:datetime_tz_ns_fixes

Conversation

@galipremsagar

Copy link
Copy Markdown
Contributor
  • to_datetime infers nanosecond precision for strings with more than 6 fractional-second digits, matching pandas.
  • DatetimeIndex with a timezone dtype treats timezone-naive strings/datetimes as wall time in the target timezone, while numeric data stays interpreted as UTC epoch values.
  • Removes 13 now-passing entries from the pandas-testing plugin.
  • Split out from Fix factorize, value_counts, and to_datetime pandas compatibility issues #23138.

@galipremsagar
galipremsagar requested a review from a team as a code owner July 7, 2026 07:51
@galipremsagar
galipremsagar requested review from bdice and vyasr July 7, 2026 07:51
@copy-pr-bot

copy-pr-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added Python Affects Python cuDF API. cudf.pandas Issues specific to cudf.pandas labels Jul 7, 2026
@GPUtester GPUtester moved this to In Progress in cuDF Python Jul 7, 2026
@galipremsagar galipremsagar added bug Something isn't working non-breaking Non-breaking change labels Jul 7, 2026
@galipremsagar

Copy link
Copy Markdown
Contributor Author

/okay to test d4e2eba

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Modifies DatetimeIndex construction to interpret timezone-naive strings as wall time when given a tz-aware dtype, updates to_datetime's strptime precision inference based on fractional-second format width, adjusts pandas-testing-plugin xfail expectations accordingly, and adds corresponding tests.

Changes

Datetime precision and timezone handling

Layer / File(s) Summary
Timezone-aware DatetimeIndex dtype casting
python/cudf/cudf/core/index.py
DatetimeIndex.__init__ now casts non-numeric data to a datetime64[unit] dtype then applies tz_localize when given a tz-aware DatetimeTZDtype, instead of a direct astype.
strptime fractional-second precision inference
python/cudf/cudf/core/tools/datetimes.py
_process_col infers nanosecond vs microsecond target_unit by inspecting the %f directive width in format when unit is None; copyright header updated.
Pandas-testing-plugin xfail expectation updates
python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py
Removes/updates expected-failure entries for datetime constructor, tz-order, concat, pivot, unique/factorize, and nanosecond-parsing test cases.
New tests for precision inference and wall-time tz behavior
python/cudf/cudf/tests/general_functions/test_to_datetime.py
Adds tests validating nanosecond/microsecond precision inference and wall-time interpretation for tz-aware DatetimeIndex; copyright header updated.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • rapidsai/cudf#22904: Both PRs modify python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py by pruning/updating stale NODEIDS_THAT_* entries—main PR focuses on datetime/timezone-related xfails, while the retrieved PR removes general stale xfails and adjusts related node IDs.

Suggested labels: improvement, 3 - Ready for Review

Suggested reviewers: TomAugspurger, mroeschke, vyasr

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the two main datetime behavior fixes in the changeset.
Description check ✅ Passed The description directly matches the implemented to_datetime, DatetimeIndex, and test plugin updates.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@python/cudf/cudf/tests/general_functions/test_to_datetime.py`:
- Around line 421-430: The test `test_datetime_index_tz_dtype_wall_time` only
covers string input for `cudf.DatetimeIndex` with `pd.DatetimeTZDtype("s",
"US/Eastern")`; add an integer epoch case in the same test so the numeric
construction path is also verified. Use a numeric timestamp input and assert it
matches the corresponding `pd.DatetimeIndex` result, ensuring `assert_eq` covers
both string and int behavior for this wall-time timezone dtype.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ecaf5e04-21ab-4466-a196-e3306cf814a1

📥 Commits

Reviewing files that changed from the base of the PR and between ba255bb and d4e2eba.

📒 Files selected for processing (4)
  • python/cudf/cudf/core/index.py
  • python/cudf/cudf/core/tools/datetimes.py
  • python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py
  • python/cudf/cudf/tests/general_functions/test_to_datetime.py
💤 Files with no reviewable changes (1)
  • python/cudf/cudf/pandas/scripts/pandas-testing-plugin.py

Comment thread python/cudf/cudf/tests/general_functions/test_to_datetime.py Outdated
@galipremsagar

Copy link
Copy Markdown
Contributor Author

/okay to test f3915e7

@galipremsagar

Copy link
Copy Markdown
Contributor Author

/merge

@galipremsagar galipremsagar added the 5 - Ready to Merge Testing and reviews complete, ready to merge label Jul 7, 2026
@rapids-bot
rapids-bot Bot merged commit 175fb17 into NVIDIA:main Jul 7, 2026
126 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in cuDF Python Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Ready to Merge Testing and reviews complete, ready to merge bug Something isn't working cudf.pandas Issues specific to cudf.pandas non-breaking Non-breaking change Python Affects Python cuDF API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants