Skip to content

Commit

Permalink
GH-31548: [Python] Test that zoneinfo timezones are accepted during t…
Browse files Browse the repository at this point in the history
…ype inference (#34394)

### What changes are included in this PR?

Explicit test for timestamp inference when creating `pyarrow.Array` with a datetime that has `zoneinfo` timezone specified.
* Closes: #31548

Authored-by: Alenka Frim <frim.alenka@gmail.com>
Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
  • Loading branch information
AlenkaF committed Mar 14, 2023
1 parent 3a6fc1f commit 591042f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions python/pyarrow/tests/test_convert_builtin.py
Expand Up @@ -1133,6 +1133,33 @@ def test_sequence_timestamp_with_timezone_inference():
assert arr.type == expected_type


def test_sequence_timestamp_with_zoneinfo_timezone_inference():
pytest.importorskip("zoneinfo")
import zoneinfo

data = [
datetime.datetime(2007, 7, 13, 8, 23, 34, 123456), # naive
datetime.datetime(2008, 1, 5, 5, 0, 0, 1000,
tzinfo=datetime.timezone.utc),
None,
datetime.datetime(2006, 1, 13, 12, 34, 56, 432539,
tzinfo=zoneinfo.ZoneInfo(key='US/Eastern')),
datetime.datetime(2010, 8, 13, 5, 0, 0, 437699,
tzinfo=zoneinfo.ZoneInfo(key='Europe/Moscow')),
]
expected = [
pa.timestamp('us', tz=None),
pa.timestamp('us', tz='UTC'),
pa.timestamp('us', tz=None),
pa.timestamp('us', tz='US/Eastern'),
pa.timestamp('us', tz='Europe/Moscow')
]
for dt, expected_type in zip(data, expected):
prepended = [dt] + data
arr = pa.array(prepended)
assert arr.type == expected_type


@pytest.mark.pandas
def test_sequence_timestamp_from_mixed_builtin_and_pandas_datetimes():
pytest.importorskip("pytz")
Expand Down

0 comments on commit 591042f

Please sign in to comment.