You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
date_trunc on time zone aware timestamps is an hour off when a DST change falls inside the bucket #7720
Actual: on the two DST days, the result is not local midnight.
2020-03-28 23:00:00+01:00 # previous day
2020-10-25 01:00:00+02:00
2020-06-01 00:00:00+02:00 # correct, no DST change in the bucket
Expected: local midnight, 2020-03-29 00:00:00+01:00 and 2020-10-25 00:00:00+02:00. That's what Polars returns (dt.truncate("1d")), as does pandas (dt.floor("D")).
The same happens for any bucket that contains a DST change, e.g. date_trunc("7 hours", ...) around a transition. Buckets of up to an hour aren't affected for zones whose transitions fall on whole hours.
Cause: for time-zone-aware input, truncate truncates the naive local time, but then subtracts the same amount as a fixed Duration from the original instant. When the UTC offset changes between the truncated local time and the original, the subtraction overshoots or undershoots by the offset difference. (#7715 keeps this approach, so it doesn't fix this.)
Suggested fix: truncate the naive local time and then localize it (resolve the local result back to an instant in the time zone). For ambiguous or nonexistent results, Polars keeps the input's offset first, then falls back to the offset at the guessed instant.
Activity