You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by jo...@apache.org on 2023/03/14 11:30:52 UTC
[arrow] branch main updated: GH-31548: [Python] Test that zoneinfo timezones are accepted during type inference (#34394)
This is an automated email from the ASF dual-hosted git repository.
jorisvandenbossche pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 591042fcdd GH-31548: [Python] Test that zoneinfo timezones are accepted during type inference (#34394)
591042fcdd is described below
commit 591042fcdd744c2e4cc0cec3d3c0c7fc1baf0ca5
Author: Alenka Frim <Al...@users.noreply.github.com>
AuthorDate: Tue Mar 14 12:30:41 2023 +0100
GH-31548: [Python] Test that zoneinfo timezones are accepted during type 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 <fr...@gmail.com>
Signed-off-by: Joris Van den Bossche <jo...@gmail.com>
---
python/pyarrow/tests/test_convert_builtin.py | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/python/pyarrow/tests/test_convert_builtin.py b/python/pyarrow/tests/test_convert_builtin.py
index 732164f9e1..b4ca93ee25 100644
--- a/python/pyarrow/tests/test_convert_builtin.py
+++ b/python/pyarrow/tests/test_convert_builtin.py
@@ -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")