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
fix(python!): use time zone from dtype to overwrite output time zone when initialising Series #10689
fix(python!): use time zone from dtype to overwrite output time zone when initialising Series #10689
Conversation
@@ -197,7 +197,7 @@ def test_write_delta(df: pl.DataFrame, tmp_path: Path) -> None: | |||
pl.Series( | |||
"date_ns", | |||
[datetime(2010, 1, 1, 0, 0)], | |||
dtype=pl.Datetime(time_unit="ns", time_zone="ETC"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'ETC' isn't a valid time zone, but this never errored because before it was being ignored
…when initialising Series
09b1c6b
to
231829f
Compare
Yes, we definitely need this one in 0.19! |
@MarcoGorelli does this need to remain in draft? Seems like the right way to go. If a user provides a datetype, we must respect it. |
…hen-initting-series
Thanks - what's slightly bothering me is if someone mixes tz-naive and tz-aware values, e.g.: In [5]: pl.Series([datetime(2020, 1, 1), datetime(2020, 1, 1, tzinfo=ZoneInfo('US/Pacific'))], dtype=pl.Datetime('us', 'Asia/Kathmandu'))
Out[5]:
shape: (2,)
Series: '' [datetime[μs, Asia/Kathmandu]]
[
2020-01-01 00:00:00 +0545
2020-01-01 08:00:00 +0545
] am I'm not sure that the second value would be expected to most users. It's essentially done "convert to UTC, and then replace the time zone with what the user passed". |
Using mixed timezone datetime objects AND setting a time zone on a dtype. Might be even juggling with fire. ;) |
closes #10662
I think this should probably follow what currently happens for
dt.strptime
So, the following two should return the same result:
Unfortunately, to make behaviour consistent, this does involve a breaking change. My fault for not having noticed the inconsistency earlier really - anyway, here it is:
before:
Now: