fix: handle tzinfo=None kwarg in factory.get() without crashing#1263
Closed
frankgoldfish wants to merge 1 commit intoarrow-py:masterfrom
Closed
fix: handle tzinfo=None kwarg in factory.get() without crashing#1263frankgoldfish wants to merge 1 commit intoarrow-py:masterfrom
frankgoldfish wants to merge 1 commit intoarrow-py:masterfrom
Conversation
When tzinfo=None is explicitly passed as a keyword argument to arrow.get(), the factory previously fell through to a branch expecting positional year/month/day args, raising TypeError. The check 'len(kwargs) == 1 and tz is None' incorrectly treated explicit tzinfo=None as equivalent to no tzinfo being passed at all. Fix: check 'tzinfo not in kwargs' instead of 'tz is None', so that explicitly passing tzinfo=None is handled as a valid tzinfo value (treated as UTC, same as omitting it), rather than triggering the wrong branch. Fixes #1259
Author
|
Closing this PR — found that PR #1260 already addresses this issue. Apologies for the duplicate. |
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.
Summary
Fixes #1259.
When
tzinfo=Noneis explicitly passed as a keyword argument toarrow.get(), the factory crashed with:Root Cause
In
arrow/factory.py, the check:incorrectly treats
tzinfo=None(explicitly passed) as equivalent to "no tzinfo was passed at all", which forcesarg_count = 3and routes into the positional year/month/day constructor branch — even though no year/month/day args were given.Fix
Change
tz is Noneto"tzinfo" not in kwargs:This correctly distinguishes between:
tzinfokwarg absent → old behavior preservedtzinfo=Noneexplicitly passed → treated as a valid tzinfo value (defaults to UTC)Reproduction
Real-world pattern:
tzinfo=account.timezonewhereaccount.timezoneis an optional field that may beNone.Tests
Added
test_tzinfo_none_kwargsregression test intests/test_factory.py. All 49 tests pass.