-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(python): support DataFrame
init with Datetime dtypes that specify a timezone
#5174
feat(python): support DataFrame
init with Datetime dtypes that specify a timezone
#5174
Conversation
Hmm.. This has some strange locale issues. :/ On my laptop (in the Netherlands) it fails with: def test_init_with_timezone() -> None:
for tu in DTYPE_TEMPORAL_UNITS | frozenset([None]):
df = pl.DataFrame(
data={
"d1": [datetime(2022, 10, 12, 12, 30)],
"d2": [datetime(2022, 10, 12, 12, 30)],
},
columns=[
("d1", pl.Datetime(tu, "America/New_York")), # type: ignore[arg-type]
("d2", pl.Datetime(tu, "Asia/Tokyo")), # type: ignore[arg-type]
],
)
# note: setting timezone doesn't change the underlying/physical value...
assert (df["d1"].to_physical() == df["d2"].to_physical()).all()
# ...but (as expected) it _does_ change the interpretation of that value
> assert df.rows() == [
(
datetime(2022, 10, 12, 8, 30, tzinfo=ZoneInfo("America/New_York")),
datetime(2022, 10, 12, 21, 30, tzinfo=ZoneInfo("Asia/Tokyo")),
)
]
E AssertionError: assert [(datetime.da...sia/Tokyo')))] == [(datetime.da...sia/Tokyo')))]
E At index 0 diff: (datetime.datetime(2022, 10, 12, 7, 30, tzinfo=zoneinfo.ZoneInfo(key='America/New_York')), datetime.datetime(2022, 10, 12, 20, 30, tzinfo=zoneinfo.ZoneInfo(key='Asia/Tokyo'))) != (datetime.datetime(2022, 10, 12, 8, 30, tzinfo=zoneinfo.ZoneInfo(key='America/New_York')), datetime.datetime(2022, 10, 12, 21, 30, tzinfo=zoneinfo.ZoneInfo(key='Asia/Tokyo')))
E Use -v to get more diff
tests/unit/test_df.py:2414: AssertionError |
@ritchie46 argh... must be some kind of implicit local/UTC shenanigans on load into pyarrow from naive datetime objects - what's your current UTC offset? (+1 or +2?) I'll try and harden the test ASAP. |
I am not entirely sure, but I think UTC +2 |
Cheers; think I have a probable fix... one sec. |
Fingers crossed: #5177 🙏 |
Can now initialize
DataFrame
with timezone-awareDataType
; previously had to post-convert per-column.Example
Before:
After:
Misc: