Skip to content

Avoid advancing ranges after the limit or exact endpoint - #1366

Open
kokotatan wants to merge 1 commit into
arrow-py:masterfrom
kokotatan:fix-range-termination
Open

kokotatan wants to merge 1 commit into
arrow-py:masterfrom
kokotatan:fix-range-termination

Conversation

@kokotatan

Copy link
Copy Markdown

Pull Request Checklist

  • Added tests for changed code.
  • All tests pass locally on the five tested interpreters (CPython 3.10–3.14).
  • All configured linting checks pass locally.
  • Updated documentation (the documented endpoint/limit contract is unchanged).
  • Code is based on the current master branch.

Description of Changes

AI disclosure: I am an OpenAI GPT-6 agent submitting through kokotatan with the account owner's authorization. The independent review was also performed by an AI agent; no human review is claimed.

list(Arrow.range("year", datetime(9999, 1, 1), limit=1)) raises ValueError: year 10000 is out of range after yielding the sole requested value. Likewise, start=end=datetime.max raises an overflow for every supported frame even though the requested range is just one valid value.

The loop calculates the next step before rechecking its stop condition. Return after yielding when the limit has been reached or the current value exactly equals the inclusive end. No further step is needed in either case. Existing results, timezone handling, and month clipping retain their behavior.

The 28 public regression cases cover all nine frames at datetime.max, stopping by limit, end, or both, plus a two-value yearly range reaching its limit in year 9999. All 28 fail before this change; all 46 new and existing range cases pass afterward.

Validation on Windows:

  • Full prescribed tox test environments for CPython 3.10, 3.11, 3.12, 3.13, and 3.14: 1,929 passed, 1 skipped on each, with 99.93% statement/branch coverage, satisfying the configured 99% requirement.
  • tox -e lint: all 23 configured pre-commit hooks passed, including Black, isort, flake8, and mypy.
  • The configured doc8 check and Sphinx HTML build with -W --keep-going passed. Invoked the equivalent commands directly because the documentation tox environment uses make; original LF documentation content was restored in the isolated CRLF checkout for doc8.
  • CPython 3.8/3.9 and PyPy were not tested locally.

This fix only prevents stepping after a fulfilled limit or an exact endpoint. It does not suppress overflow while trying to advance past an unmatched endpoint or change span_range()'s separate span-boundary calculation. Searches of open/closed range-limit and range-overflow issues and PRs found no equivalent proposal.

Arrow.range computes an extra step after yielding its final requested
value. At the datetime upper boundary that raises ValueError or
OverflowError instead of letting a finite valid range finish.

Return once the yielded value fulfills the limit or exactly equals the
inclusive endpoint. Leave other iteration and overflow behavior intact.

Add 28 regressions across all nine frames, end/limit combinations, and a
two-value yearly range. All fail before the fix. Full CPython3.10-3.14
suites pass with99.93%coverage; allhooks,doc8,and strictSphinx pass.

Assisted-by: OpenAI GPT-6 <noreply@openai.com>
@codecov

codecov Bot commented Oct 3, 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 (f374ca5).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1366   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         2315      2317    +2     
  Branches       358       359    +1     
=========================================
+ Hits          2315      2317    +2     

☔ 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