Skip to content

Use ISO calendar constructors for week dates - #1401

Open
DU8866-nice wants to merge 4 commits into
arrow-py:masterfrom
DU8866-nice:fix-iso-week-date-conversion
Open

DU8866-nice wants to merge 4 commits into
arrow-py:masterfrom
DU8866-nice:fix-iso-week-date-conversion

Conversation

@DU8866-nice

@DU8866-nice DU8866-nice commented Nov 1, 2026 •

Copy link
Copy Markdown

Description of Changes

ISO week-date conversion has two edge cases:

import arrow
arrow.get((2021, 53, 1))  # Returns 2022-01-03, but ISO year 2021 has only 52 weeks.
arrow.get("0001-W01-1")  # Raises ValueError for a valid week date.

Use date.fromisocalendar() for tuple conversion and datetime.fromisocalendar() in the parser. The tuple path now rejects nonexistent week 53 instead of rolling into the next ISO year. The parser no longer formats an early year without leading zeros before calling strptime. Both constructors are available in Arrow's supported Python range (3.8+); existing utility range-check messages are retained.

Regression tests cover invalid week-53 tuples, early-year parsing and invalid week-53 strings. Existing tests cover valid week 53 and year crossings.

Validation

  • Original full suite: 1901 passed, 1 skipped.
  • New cases against the original implementation: 6 failed, 3 passed.
  • Final full suite, Python 3.13.14 on Windows: 1910 passed, 1 skipped; 99.93% coverage.
  • Black, isort and flake8 pass on the four modified files; mypy passes on both modified source files; git diff --check passes.
  • The remote branch tree exactly matches the locally tested tree.
  • Other Python versions, the full pre-commit hook set and documentation build were not run locally.

Initial remote CI run

Lint and 21 matrix test jobs passed. Three jobs failed before running tests:

  • Ubuntu 26.04 has no Python 3.8/3.9 build available to setup-python (3.8 log, 3.9 log).
  • Windows PyPy failed while downloading build dependencies for PyYAML with Connection broken: IncompleteRead (log).

These are environment/setup failures. The Windows PyPy job needs a retry; the two older CPython Linux jobs need a compatible runner image.

Pull Request Checklist

  • Added tests for changed code.
  • All tests pass locally on Python 3.13.
  • All repository lint hooks pass locally (modified-file checks above were run).
  • Updated documentation (no new API or option).
  • Based on the current master revision at checkout.

AI assistance

Prepared with OpenAI Codex (GPT-6), including source inspection, regression tests, the fix and an independent agent review. The reported results were verified by running the commands; no human code review is claimed.

Parse valid early ISO years without an intermediate strptime conversion. Prepared and verified with OpenAI Codex.
Use date.fromisocalendar while retaining the existing week/day range errors. Prepared and verified with OpenAI Codex.
Regression tests verified to fail on the original implementation. Prepared with OpenAI Codex.
Add explicit expected dates for years 0001, 0099 and 0999, and invalid week-53 strings. Prepared and verified with OpenAI Codex.
@codecov

codecov Bot commented Nov 1, 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 (6f2a929).
✅ All tests successful. No failed tests found.

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

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

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.

1 participant