Skip to content

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

Merged
merged 8 commits into from
Nov 21, 2023
Merged

Conversation

quangngd
Copy link
Contributor

@quangngd quangngd commented Nov 17, 2023

@@ -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
Copy link
Member

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)

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@mroeschke mroeschke added the Timezones Timezone data dtype label Nov 17, 2023
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
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added


delta_idx = delta_idx - delta_idx_offset
if (shift_forward or shift_delta > 0) and \
info.deltas[delta_idx-1] >= 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
info.deltas[delta_idx-1] >= 0:
info.deltas[delta_idx - 1] >= 0:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Member

@mroeschke mroeschke left a 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!

@mroeschke mroeschke added this to the 2.2 milestone Nov 21, 2023
@mroeschke mroeschke merged commit df6a323 into pandas-dev:main Nov 21, 2023
@mroeschke
Copy link
Member

Thanks @quangngd

phofl pushed a commit to phofl/pandas that referenced this pull request Nov 21, 2023
* add tests

* fix

* add whatsnew

* refactor

* Revert "refactor"

This reverts commit 4482dd8.

* fix bug

* update

* more cmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Bad shift_forward ceiling around DST change
2 participants