Skip to content

Commit 5e553ce

Browse files
jbrockmendeljreback
authored andcommitted
Assert at least one tz arg is always UTC (#18228)
closes #17734
1 parent cd80f08 commit 5e553ce

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pandas/_libs/tslibs/conversion.pyx

+6-3
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
401401
"""
402402
Convert the val (in i8) from timezone1 to timezone2
403403
404-
This is a single timezone versoin of tz_convert
404+
This is a single timezone version of tz_convert
405405
406406
Parameters
407407
----------
@@ -422,6 +422,9 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
422422
pandas_datetimestruct dts
423423
datetime dt
424424

425+
# See GH#17734 We should always be converting either from UTC or to UTC
426+
assert (is_utc(tz1) or tz1 == 'UTC') or (is_utc(tz2) or tz2 == 'UTC')
427+
425428
if val == NPY_NAT:
426429
return val
427430

@@ -444,8 +447,8 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2):
444447

445448
if get_timezone(tz2) == 'UTC':
446449
return utc_date
447-
if is_tzlocal(tz2):
448-
dt64_to_dtstruct(val, &dts)
450+
elif is_tzlocal(tz2):
451+
dt64_to_dtstruct(utc_date, &dts)
449452
dt = datetime(dts.year, dts.month, dts.day, dts.hour,
450453
dts.min, dts.sec, dts.us, tz2)
451454
delta = int(get_utcoffset(tz2, dt).total_seconds()) * 1000000000

0 commit comments

Comments
 (0)