Skip to content

BUG: astype from tz-naive to tz-aware uses tz_localize semantics#65187

Draft
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
jbrockmendel:bug-49281
Draft

BUG: astype from tz-naive to tz-aware uses tz_localize semantics#65187
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
jbrockmendel:bug-49281

Conversation

@jbrockmendel
Copy link
Copy Markdown
Member

Summary

  • .astype from tz-naive to tz-aware datetime now uses tz_localize semantics (treat as wall times), consistent with the Series/DatetimeIndex constructors
  • Fixes PyArrow-backed arrays incorrectly treating naive timestamps as UTC when casting to tz-aware (both within pyarrow and cross-family)
  • DatetimeArray.astype no longer raises TypeError for tz-naive to tz-aware; it calls tz_localize instead

closes #49281

Test plan

  • Existing tests updated across 5 test files
  • New tests added for pyarrow within-family and cross-family tz-naive to tz-aware conversion
  • Full test_arrow.py suite passes (25k+ tests)
  • Pre-commit hooks pass

🤖 Generated with Claude Code

…das-dev#49281)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Series(dt64_data, dtype=tzaware) vs Series(dt64_data).astype(tzaware)

1 participant