-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
timezone info is dropped if a list of dict is passed #7620
Comments
I also just ran into this. As a workaround, it seems you can specify the schema manually:
|
Thank you so much. But the negative side of that workaround is that I have to specify schema for all columns otherwise unspecified columns will be ignored. [edit] use |
+1 This threw me off big time |
It would be great if this could be fixed in v1. Related issues: 6130, 6619, 12151, 12638, 13033, 14211. Here's a test which still fails with import datetime
from zoneinfo import ZoneInfo
import polars as pl
def test_constructor_considers_timezone() -> None:
"""A timezone aware datetime should not become naive when parsed by Polars.
There should be no need to add the timezone to pl.Datetime in the provided schema.
"""
tz = "Europe/Paris"
dt = datetime.datetime(2024, 5, 2, 0, 0, tzinfo=ZoneInfo(tz))
df = pl.DataFrame([{"dt": dt}], schema={"dt": pl.Datetime(time_zone=tz)})
assert df[0, "dt"].tzinfo == dt.tzinfo
assert df[0, "dt"] == dt
df = pl.DataFrame([{"dt": dt}], schema={"dt": pl.Datetime})
assert df[0, "dt"].tzinfo == dt.tzinfo # fails with v1.0.0b1
assert df[0, "dt"] == dt
df = pl.DataFrame([{"dt": dt}], schema={"dt": pl.Datetime(time_zone="*")})
assert df[0, "dt"].tzinfo == dt.tzinfo # raises a PanicException with v1.0.0b1
assert df[0, "dt"] == dt |
Polars version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of Polars.
Issue description
timezone info of datetime object is dropped if data is passed to the DataFrame constructor in a form of
list of dict
.Reproducible example
Expected behavior
The case of
list of dict
also keeps the timezone info asdict of list
case.Installed versions
The text was updated successfully, but these errors were encountered: