Skip to content

Commit

Permalink
Backport PR pandas-dev#55726: fix segfault with tz_localize_to_utc
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd authored and meeseeksmachine committed Nov 1, 2023
1 parent 08f2bd4 commit e67e0b4
Showing 1 changed file with 10 additions and 7 deletions.
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,
# 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):
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

0 comments on commit e67e0b4

Please sign in to comment.