fix: treat explicit tzinfo=None as not provided in ArrowFactory.get()#1270
Open
AKIB473 wants to merge 2 commits intoarrow-py:masterfrom
Open
fix: treat explicit tzinfo=None as not provided in ArrowFactory.get()#1270AKIB473 wants to merge 2 commits intoarrow-py:masterfrom
AKIB473 wants to merge 2 commits intoarrow-py:masterfrom
Conversation
When tzinfo=None was passed explicitly, the check
if len(kwargs) == 1 and tz is None:
arg_count = 3
triggered the 3+ arg constructor path even for 2-arg str+format calls,
causing a TypeError. The check intended to detect the absence of a tzinfo
kwarg, not a None value.
Fix: use `'tzinfo' not in kwargs` instead of `tz is None` so that
explicit tzinfo=None is treated identically to omitting tzinfo.
Fixes arrow-py#1259
Covers explicit tzinfo=None with str+format args and with no args. Verifies the fix for issue arrow-py#1259.
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.
Fixes #1259
Problem
arrow.get('2025-01-01', 'YYYY-MM-DD', tzinfo=None)crashed with:The root cause is in
ArrowFactory.get():When
tzinfo=Noneis passed explicitly,len(kwargs) == 1isTrueandtz is Noneis alsoTrue, soarg_countis set to3and the call falls into the 3+ arg constructor path — crashing because'2025-01-01'and'YYYY-MM-DD'are not valid year/month/day integers.The intent of the check was to detect that no
tzinfokeyword was provided at all, not to check whether the value isNone.Fix
Change the condition to check key presence:
This means
tzinfo=Noneis now treated identically to omittingtzinfo— which is the intuitive behaviour whentzinfocomes from an optional field that can beNone.Tests
Two regression tests added to
tests/test_factory.py:test_two_args_str_str_tzinfo_none—arrow.get('2025-01-01', 'YYYY-MM-DD', tzinfo=None)must parse correctlytest_no_args_tzinfo_none—arrow.get(tzinfo=None)must return current UTC time