Skip to content
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 segfault with tz_localize_to_utc #55726

Merged
merged 5 commits into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions pandas/_libs/tslibs/tzconversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,16 @@ timedelta-like}
# Shift the delta_idx by if the UTC offset of
# the target tz is greater than 0 and we're moving forward
# or vice versa
first_delta = info.deltas[0]
if (shift_forward or shift_delta > 0) and first_delta > 0:
delta_idx_offset = 1
elif (shift_backward or shift_delta < 0) and first_delta < 0:
delta_idx_offset = 1
else:
delta_idx_offset = 0
# TODO: delta_idx_offset and info.deltas are needed for zoneinfo timezones,
Copy link
Member

Choose a reason for hiding this comment

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

@mroeschke this comment might be relevant for the zoneinfo thing you mentioned earlier

# but are not applicable for all timezones. Setting the former to 0 and
# length checking the latter avoids UB, but this could use a larger refactor
delta_idx_offset = 0
if len(info.deltas):
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved
mroeschke marked this conversation as resolved.
Show resolved Hide resolved
first_delta = info.deltas[0]
if (shift_forward or shift_delta > 0) and first_delta > 0:
delta_idx_offset = 1
elif (shift_backward or shift_delta < 0) and first_delta < 0:
delta_idx_offset = 1

for i in range(n):
val = vals[i]
Expand Down
Loading