Skip to content

Navigation Menu

Sign in
Sign up

GH-38444: [Python] Handle out-of-range date scalar repr - #51290

Open
emecii wants to merge 1 commit into
apache:main from
emecii:fix/python-date-scalar-repr
Open

GH-38444: [Python] Handle out-of-range date scalar repr #51290
emecii wants to merge 1 commit into
apache:main from
emecii:fix/python-date-scalar-repr

Conversation

@emecii

@emecii emecii commented Sep 10, 2026
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Contributor

Rationale for this change

Valid Date32 and Date64 values can fall outside Python's datetime.date range. Their scalar str and repr paths currently call as_py() and raise OverflowError, even though Arrow can format the values safely.

What changes are included in this PR?

Date32Scalar and Date64Scalar now preserve their existing formatting for Python-representable dates and fall back to the Arrow C++ scalar representation only when conversion raises OverflowError. The as_py() behavior is unchanged.

Boundary regressions cover the minimum and maximum storage values for both date types, plus an in-range leap-day case.

Are these changes tested?

Yes.

  • Rebuilt the PyArrow extension against the matching Arrow C++ source revision.
  • python -m pytest python/pyarrow/tests/test_scalars.py -q: 144 passed, 45 skipped.
  • File-scoped pre-commit hooks passed, including Python format, Python lint, and Cython lint.

Are there any user-facing changes?

Date32 and Date64 scalars outside Python's calendar range now render as <value out of range: ...> instead of raising from str() or repr(). This is not a breaking API change.

Closes #38444.

AI assistance

This PR was prepared with OpenAI Codex assistance for investigation, implementation, and test execution. The change is limited to the date scalar formatting paths and their regression tests.

Copy link
Copy Markdown

⚠️ GitHub issue #38444 has been automatically assigned in GitHub to PR creator.

Copy link
Copy Markdown
Member

Date32 and Date64 scalars outside Python's calendar range now render as <value out of range: ...> instead of raising from str() or repr(). This is not a breaking API change.

Why does this still result in "value out of range" ? You mention that "Arrow can format the values safely", but so the C++ formatter will still give that out of range text instead of a formatted date?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@AlenkaF AlenkaF Awaiting requested review from AlenkaF AlenkaF is a code owner
@raulcd raulcd Awaiting requested review from raulcd raulcd is a code owner
@rok rok Awaiting requested review from rok rok is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Python] Repr of Date scalars and arrays error if they are outside range of stdlib datetime.date

AltStyle によって変換されたページ (->オリジナル) /