Skip to content

BUG: keep the year of a tz-aware Timestamp outside 1-9999 when converting to datetime64 (GH#71371) - #1877

Open
xirafa wants to merge 3 commits into
mainfrom
ege-arhan/fix-71371-tz-aware-out-of-range-year
Open

xirafa wants to merge 3 commits into
mainfrom
ege-arhan/fix-71371-tz-aware-out-of-range-year

Conversation

@xirafa

@xirafa xirafa commented Nov 17, 2026 •

Copy link
Copy Markdown

Mirror of pandas-dev/pandas#72195. Runs the pandas test suite through dagz.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed storage of timezone-aware timestamps outside years 1–9999 when using resolutions coarser than nanoseconds, preventing incorrect conversion to 1970 or 1972.

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7a85e5bc-9f90-4eef-9ee2-7e7f8da2c0dc
Commits

Reviewing files that changed from the base of the PR and between a62f33c and 8466287.

Files selected for processing: 4

  • doc/source/whatsnew/v3.2.0.rst
  • pandas/_libs/tslibs/conversion.pyx
  • pandas/tests/indexes/datetimes/test_constructors.py
  • pandas/tests/tslibs/test_array_to_datetime.py

No actionable comments were generated in the recent review.

Walkthrough

parse_pydatetime now converts _Timestamp inputs from their stored values at the requested resolution, including timezone-aware timestamps. A regression test covers years 10000 and 10001, and a release note describes the reported incorrect storage.

Changes: Timestamp conversion

Layer / File(s) Summary
Timestamp conversion and regression coverage
pandas/_libs/tslibs/conversion.pyx, pandas/tests/tslibs/test_array_to_datetime.py, doc/source/whatsnew/v3.2.0.rst
parse_pydatetime converts _Timestamp inputs from their stored values at the requested resolution. A parameterized test checks that conversion preserves the microsecond representation and year for UTC-localized timestamps in years 10000 and 10001. The release note describes the reported incorrect storage of out-of-range-year timezone-aware timestamps.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

  • autodag-dev/pandas#1865: Its summary describes a similar fix for preserving the year of out-of-range timezone-aware timestamps during conversion.

Suggested reviewers: jbrockmendel

Merge Risk: Minimal · previous review a62f3

Timezone-aware timestamps with years outside 1–9999 should now keep their correct year when converted at coarser resolutions. The change is small, covered by a regression test, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: preserving the year of a tz-aware Timestamp outside 1-9999 when converting to datetime64. The raw summary describes the same fix in conversion.pyx, where parse_pydatet…
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.
Full details: Title check

Explanation

The title names the main change: preserving the year of a tz-aware Timestamp outside 1-9999 when converting to datetime64. The raw summary describes the same fix in conversion.pyx, where parse_pydatetime handles _Timestamp inputs before the tzinfo check. The objectives and the regression test in test_array_to_datetime.py for years 10000 and 10001 match the title. The title is specific and on topic, and it is longer than ideal at 98 characters.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 97bf45ad-1d13-49f4-a7c6-3f65d021337b
Commits

Reviewing files that changed from the base of the PR and between c0dea6c and a62f33c.

Files selected for processing: 3

  • doc/source/whatsnew/v3.2.0.rst
  • pandas/_libs/tslibs/conversion.pyx
  • pandas/tests/tslibs/test_array_to_datetime.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@xirafa
xirafa force-pushed the main branch 13 times, most recently from 491a8aa to 42cbbed Compare November 18, 2026 19:07
…timeIndex dtypes (GH#71371)

The array_to_datetime fix only covered object-dtype input. With an explicit
datetime64[us, UTC] dtype the values go through
array_to_datetime_with_tz -> convert_datetime_to_tsobject, which rebuilt the
datetimestruct from the py datetime fields, where the year is a placeholder
outside 1-9999.

Use _value (already UTC in the Timestamp's own resolution) for Timestamp
inputs that carry a tz or are naive with no target tz, and derive dts from it.

Adds coverage for pd.Series, Series.astype, DatetimeIndex and pd.array.
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.

2 participants