Fix arrow.get() crash when tzinfo kwarg is explicitly None - #1339
Open
mayuriphad wants to merge 1 commit into
Open
Fix arrow.get() crash when tzinfo kwarg is explicitly None#1339mayuriphad wants to merge 1 commit into
mayuriphad wants to merge 1 commit into
Conversation
The kwarg-count check in ArrowFactory.get() used 'tz is None' to detect that only the tzinfo kwarg was passed, so it could fall back to the 3+ positional-argument constructor path. This meant an explicitly passed tzinfo=None (as opposed to omitting the kwarg entirely) was misidentified, and arrow.get(<str>, <fmt>, tzinfo=None) incorrectly routed to self.type(*args, **kwargs), raising a confusing TypeError about a missing 'day' argument instead of parsing the string as expected. Check for the key's presence instead of its value. Fixes arrow-py#1259
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1339 +/- ##
=========================================
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 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.
ArrowFactory.get()decides whether kwargs should be routed to the directArrow(...)constructor (the 3+ positional args path) based on whether the only kwarg present istzinfo. It did this by checkingtz is None, which cannot distinguish between "tzinfowas not passed at all" and "tzinfo=Nonewas passed explicitly". As a result:was routed to
self.type(*args, **kwargs)(the constructor path meant for calls likearrow.get(2013, 5, 5, 12, 30, 45)), which raised:This is a real-world footgun for callers that pass an optional, possibly-
None, timezone straight through as a kwarg (e.g.arrow.get(value, fmt, tzinfo=account.timezone)whereaccount.timezonecan beNone).Fix
Check for the key's presence rather than its value:
Now
tzinfo=Nonebehaves the same as omittingtzinfoentirely (defaults to UTC), while an explicit non-tzinfosingle kwarg still correctly routes to the constructor path, andtzinfo=<value>still works as before.Test plan
test_kwarg_tzinfo_none_with_string_and_formattotests/test_factory.py, assertingarrow.get(str, fmt, tzinfo=None)produces the same result asarrow.get(str, fmt)(UTC).python -m pytest tests/test_factory.py -q→ 49 passed, 1 skipped.TypeError, and after the fixarrow.get('2025-01-01', 'YYYY-MM-DD', tzinfo=None),tzinfo='US/Pacific', and omitted-tzinfoall behave correctly.python -m black --check arrow/factory.py tests/test_factory.py→ clean.