Skip to content

Preserve four-digit years when parsing week and ordinal dates - #1400

Open
charan-rathore wants to merge 1 commit into
arrow-py:masterfrom
charan-rathore:fix/low-year-date-parsing-20261030
Open

charan-rathore wants to merge 1 commit into
arrow-py:masterfrom
charan-rathore:fix/low-year-date-parsing-20261030

Conversation

@charan-rathore

@charan-rathore charan-rathore commented Oct 30, 2026 •

Copy link
Copy Markdown

Pull Request Checklist

  • Added tests for changed code.
  • All tests pass locally: 1,926 tests, 99.93% coverage (required 99%).
  • All prescribed pre-commit hooks pass, including black, flake8 and mypy.
  • Documentation checks run: doc8 reports zero errors; strict Sphinx HTML build passes. No public API documentation change is needed for this parser correction.
  • Based on current master 2224255.

Description of Changes

Parsing valid ISO week or ordinal dates with a year below 1000 fails after the parser converts the year to an integer and reconstructs an unpadded string for strptime. For example, 0001-W01-1 becomes 1-1-1, and 0001-002 becomes 1-2. Python's strptime requires years below 1000 to be zero-filled to four digits.

Preserve that four-digit year width in the two intermediate strings. The tests cover years 1, 4, 12, 99, 400 and 999, with 1000 and 2024 as controls, both ordinal tokens, and ISO week parsing through the parser and public API. Week-date expectations use datetime.fromisocalendar.

This follows up on #1328, which was closed by its author without merging. Credit to @santhreal for the earlier repair. This change keeps the year-padding correction and adds regression coverage; it excludes the earlier PR's unrelated CI edits. It is separate from #1371's formatter output and #1338's factory tuple/week-53 validation.

Validation on Python 3.12/macOS:

  • Before: 18 new early-year failures and six modern-year controls passing.
  • After: 746 parser tests and the full 1,926-test suite pass; 99.93% coverage.
  • All repository pre-commit hooks, doc8, strict Sphinx HTML build and git diff --check pass.
  • The full tox interpreter/platform matrix was not run.

Prepared with OpenAI Codex assistance through source inspection and local regression testing; this was not encountered in production.

Upstream CI checkpoint

Three matrix jobs failed before running tests: Ubuntu 26.04 could not provide Python 3.8/3.9 through setup-python, and Windows PyPy failed during dependency installation with IncompleteRead download errors while building PyYAML dependencies. Existing #1393 discusses CI compatibility; this parser PR does not change workflows or dependency policy. The remaining completed checks pass, including the coverage check at this checkpoint. These failures are not counted as passing validation.

Copilot AI balanced review requested due to automatic review settings October 30, 2026 05:30

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2224255) to head (9fd3c50).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1400   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         2315      2315           
  Branches       358       358           
=========================================
  Hits          2315      2315           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@agammann agammann 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.

I reviewed the two reconstruction paths at 9fd3c50. Both values are integer years before formatting, and four-digit padding matches strptime requirements for years below 1000 without changing modern years. The new ordinal and ISO-week cases, including modern-year controls, pass locally (24 focused tests on Python 3.14.8). I did not run the full interpreter matrix; GitHub currently shows three setup failures outside the changed parser path.

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.

3 participants