Skip to content

fix: treat explicit tzinfo=None as not provided in ArrowFactory.get()#1270

Open
AKIB473 wants to merge 2 commits intoarrow-py:masterfrom
AKIB473:akib/fix-tzinfo-none-crash
Open

fix: treat explicit tzinfo=None as not provided in ArrowFactory.get()#1270
AKIB473 wants to merge 2 commits intoarrow-py:masterfrom
AKIB473:akib/fix-tzinfo-none-crash

Conversation

@AKIB473
Copy link
Copy Markdown

@AKIB473 AKIB473 commented Apr 15, 2026

Fixes #1259

Problem

arrow.get('2025-01-01', 'YYYY-MM-DD', tzinfo=None) crashed with:

TypeError: Arrow.__init__() missing 1 required positional argument: 'day'

The root cause is in ArrowFactory.get():

# tzinfo kwarg is not provided
if len(kwargs) == 1 and tz is None:
    arg_count = 3

When tzinfo=None is passed explicitly, len(kwargs) == 1 is True and tz is None is also True, so arg_count is set to 3 and 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 tzinfo keyword was provided at all, not to check whether the value is None.

Fix

Change the condition to check key presence:

# tzinfo kwarg is not provided (explicit tzinfo=None is treated as not provided)
if len(kwargs) == 1 and "tzinfo" not in kwargs:
    arg_count = 3

This means tzinfo=None is now treated identically to omitting tzinfo — which is the intuitive behaviour when tzinfo comes from an optional field that can be None.

Tests

Two regression tests added to tests/test_factory.py:

  • test_two_args_str_str_tzinfo_nonearrow.get('2025-01-01', 'YYYY-MM-DD', tzinfo=None) must parse correctly
  • test_no_args_tzinfo_nonearrow.get(tzinfo=None) must return current UTC time

AKIB473 added 2 commits April 15, 2026 08:39
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.
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.

arrow.get() behaviour for tzinfo=None

1 participant