Skip to content

Commit bf91684

Browse files
Backport PR #55726 on branch 2.1.x (fix segfault with tz_localize_to_utc) (#55796)
Backport PR #55726: fix segfault with tz_localize_to_utc Co-authored-by: William Ayd <[email protected]>
1 parent 08f2bd4 commit bf91684

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pandas/_libs/tslibs/tzconversion.pyx

+10-7
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,16 @@ timedelta-like}
332332
# Shift the delta_idx by if the UTC offset of
333333
# the target tz is greater than 0 and we're moving forward
334334
# or vice versa
335-
first_delta = info.deltas[0]
336-
if (shift_forward or shift_delta > 0) and first_delta > 0:
337-
delta_idx_offset = 1
338-
elif (shift_backward or shift_delta < 0) and first_delta < 0:
339-
delta_idx_offset = 1
340-
else:
341-
delta_idx_offset = 0
335+
# TODO: delta_idx_offset and info.deltas are needed for zoneinfo timezones,
336+
# but are not applicable for all timezones. Setting the former to 0 and
337+
# length checking the latter avoids UB, but this could use a larger refactor
338+
delta_idx_offset = 0
339+
if len(info.deltas):
340+
first_delta = info.deltas[0]
341+
if (shift_forward or shift_delta > 0) and first_delta > 0:
342+
delta_idx_offset = 1
343+
elif (shift_backward or shift_delta < 0) and first_delta < 0:
344+
delta_idx_offset = 1
342345

343346
for i in range(n):
344347
val = vals[i]

0 commit comments

Comments
 (0)