From a242bd7a8fc7cb56439144c4da46050c0a75ec16 Mon Sep 17 00:00:00 2001 From: Bas Schoenmaeckers Date: Wed, 22 Jan 2025 18:14:34 +0100 Subject: [PATCH] Add testcase for #20766 --- .../unit/constructors/test_constructors.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/py-polars/tests/unit/constructors/test_constructors.py b/py-polars/tests/unit/constructors/test_constructors.py index 48e1db4bc09..6c0605cf239 100644 --- a/py-polars/tests/unit/constructors/test_constructors.py +++ b/py-polars/tests/unit/constructors/test_constructors.py @@ -1797,6 +1797,35 @@ def test_init_list_of_dicts_with_timezone(tz: Any) -> None: assert df.schema == {"dt": pl.Datetime("us", time_zone=tz)} +@pytest.mark.parametrize( + "tz", + [ + None, + ZoneInfo("Asia/Tokyo"), + ZoneInfo("Europe/Amsterdam"), + ZoneInfo("UTC"), + timezone.utc, + ], +) +def test_init_list_of_nested_dicts_with_timezone(tz: Any) -> None: + dt = datetime(2021, 1, 1, 0, 0, 0, 0, tzinfo=tz) + data = [ + { + "timestamp": { + "content": datetime( + 2021, 1, 1, 0, 0, tzinfo=tz + ) + } + } + ] + + df = pl.DataFrame(data).unnest("timestamp") + expected = pl.DataFrame({"content": [dt]}) + assert_frame_equal(df, expected) + + assert df.schema == {"content": pl.Datetime("us", time_zone=tz)} + + def test_init_from_subclassed_types() -> None: # more detailed test of one custom subclass... import codecs