Repository navigation
Conversation
Arrow.span_range()'s docstring documents end as optional and states that
calling with "limit alone" returns at most `limit` timespans from start,
which is how Arrow.range() behaves, but the parameter was mandatory and was
converted unconditionally, so both documented forms raised:
span_range("month", start, limit=3)
-> TypeError: missing 1 required positional argument: 'end'
span_range("month", start, None, limit=3)
-> AttributeError: 'NoneType' object has no attribute 'year'
(arrow/arrow.py:706 -> fromdatetime())
Make end default to None, convert it only when it was provided, and guard the
exact=True truncation comparisons against a missing end. None is still
forwarded to Arrow.range(), which raises ValueError("One of 'end' or 'limit'
is required.") when neither end nor limit is given.
Affected calls all raised before, so no working call changes behaviour.
Adds regression tests in tests/test_arrow.py::TestArrowSpanRange covering
limit-only usage for month and quarter frames (with tz), exact=True, and the
ValueError when both end and limit are omitted.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1396 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 2315 2315
Branches 358 358
=========================================
Hits 2315 2315 ☔ View full report in Codecov by Harness. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Checklist
toxormake testto find out!).tox -e lintormake lintto find out!).masterbranch.Description of Changes
Arrow.span_range()documents thatendis optional and thatlimitmay be passed on its own:but both documented forms raise:
The second one fails at
arrow/arrow.py:706(end = cls.fromdatetime(end, tzinfo)), even thoughendis forwarded toArrow.range(), which already implements the documented rule (_get_iteration_params()treatsend=NoneasArrow.maxand raisesValueError("One of 'end' or 'limit' is required.")when both are omitted).This makes
enddefault toNoneand only converts/compares against it when it was actually provided, so the documented limit-only call returns timespans:No existing call changes behaviour — every input affected by this patch raised before — and calling with neither
endnorlimitnow raises the sameValueErrorasArrow.range()instead ofAttributeError.Tests added in
tests/test_arrow.py::TestArrowSpanRange:test_limit_without_end,test_limit_without_end_quarter_and_tz(frame +tz),test_limit_without_end_exact(exact=True),test_limit_or_end_is_required(ValueError). All four fail onmaster(TypeError/AttributeError) and pass with the fix; the full suite is green (1905 passed, coverage 99.93%) andblack/flake8/isort/mypy(pre-commit pins) are clean.Prepared with AI assistance; every line was verified by running the cases above.