-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Bad shift_forward around UTC+0 when DST #56017
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
Conversation
pandas/_libs/tslibs/tzconversion.pyx
Outdated
@@ -416,6 +416,9 @@ timedelta-like} | |||
|
|||
else: | |||
delta_idx = bisect_right_i8(info.tdata, new_local, info.ntrans) | |||
if (shift_forward or shift_delta > 0) and \ | |||
info.deltas[delta_idx-1] >= 0: | |||
delta_idx_offset = 1 |
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.
Not sure if it's safe to permanently change this to 1 for future iterations.
Might be safer to do something like
dst_offset = 0 if condition else 1
delta_idx = delta_idx - min(delta_idx_offset + dst_offset, 1)
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.
Right, make sense.
But there is this piece of code just before the loop to precompute delta_idx_offset
. (Search for "Pre-compute delta_idx_offset"). I moved the whole block to here.
I don't know why it was precomputed. Was we assuming that there are just one time zone in the array?
Further more there is a recent PR around that block of code for a segfault problem.
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.
Oh misunderstood what you mean. Corrected.
delta_idx = delta_idx - delta_idx_offset | ||
if (shift_forward or shift_delta > 0) and \ | ||
info.deltas[delta_idx-1] >= 0: | ||
delta_idx = delta_idx - 1 |
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.
Could you write a 1 line comment describing why we need to do this?
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.
added
pandas/_libs/tslibs/tzconversion.pyx
Outdated
|
||
delta_idx = delta_idx - delta_idx_offset | ||
if (shift_forward or shift_delta > 0) and \ | ||
info.deltas[delta_idx-1] >= 0: |
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.
info.deltas[delta_idx-1] >= 0: | |
info.deltas[delta_idx - 1] >= 0: |
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.
updated
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.
Small comments otherwise looks good!
Thanks @quangngd |
* add tests * fix * add whatsnew * refactor * Revert "refactor" This reverts commit 4482dd8. * fix bug * update * more cmt
closes BUG: Bad shift_forward ceiling around DST change #51501
Tests added and passed if fixing a bug or adding a new feature
All code checks passed.
Added an entry in the latest
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.The algo originates from API/ENH: tz_localize handling of nonexistent times: rename keyword + add shift option #22644.
A related bug fix later in BUG/ENH: Handle NonexistentTimeError in date rounding #23406 but failed to take care of edge cases where we move in/out of UTC+0.
More tests added.