From 81f8a33d57ddc0324c88b9c02ba4c9a8d335e5a0 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 11 Nov 2017 08:36:21 -0800 Subject: [PATCH 1/6] Assert at least one tz arg is always UTC closes #17734 --- pandas/_libs/tslibs/conversion.pyx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index 61efc865112a9..9f10cf21a8a64 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -422,6 +422,9 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2): pandas_datetimestruct dts datetime dt + assert is_utc(tz1) or is_utc(tz2) + # See GH#17734 + if val == NPY_NAT: return val @@ -445,7 +448,7 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2): if get_timezone(tz2) == 'UTC': return utc_date if is_tzlocal(tz2): - dt64_to_dtstruct(val, &dts) + dt64_to_dtstruct(utc_date, &dts) dt = datetime(dts.year, dts.month, dts.day, dts.hour, dts.min, dts.sec, dts.us, tz2) delta = int(get_utcoffset(tz2, dt).total_seconds()) * 1000000000 @@ -487,6 +490,9 @@ def tz_convert(ndarray[int64_t] vals, object tz1, object tz2): pandas_datetimestruct dts datetime dt + assert is_utc(tz1) or is_utc(tz2) + # See GH#17734 + if len(vals) == 0: return np.array([], dtype=np.int64) From 65f001d93045f12c1d1accc8975d20447b5bfdf6 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 11 Nov 2017 09:52:56 -0800 Subject: [PATCH 2/6] update asserts --- pandas/_libs/tslibs/conversion.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index 9f10cf21a8a64..380dafab7f46b 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -422,7 +422,7 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2): pandas_datetimestruct dts datetime dt - assert is_utc(tz1) or is_utc(tz2) + assert (is_utc(tz1) or tz1 == 'UTC') or (is_utc(tz2) or tz2 == 'UTC') # See GH#17734 if val == NPY_NAT: @@ -490,7 +490,7 @@ def tz_convert(ndarray[int64_t] vals, object tz1, object tz2): pandas_datetimestruct dts datetime dt - assert is_utc(tz1) or is_utc(tz2) + assert (is_utc(tz1) or tz1 == 'UTC') or (is_utc(tz2) or tz2 == 'UTC') # See GH#17734 if len(vals) == 0: From 563510c003e1a392a3c052a284bc5a5da785a638 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 11 Nov 2017 11:19:19 -0800 Subject: [PATCH 3/6] edit comment per reviewer suggestion --- pandas/_libs/tslibs/conversion.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index 380dafab7f46b..276c8c4d25da7 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -422,8 +422,8 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2): pandas_datetimestruct dts datetime dt + # See GH#17734 We should always be converting either from UTC or to UTC assert (is_utc(tz1) or tz1 == 'UTC') or (is_utc(tz2) or tz2 == 'UTC') - # See GH#17734 if val == NPY_NAT: return val @@ -490,8 +490,8 @@ def tz_convert(ndarray[int64_t] vals, object tz1, object tz2): pandas_datetimestruct dts datetime dt + # See GH#17734 We should always be converting either from UTC or to UTC assert (is_utc(tz1) or tz1 == 'UTC') or (is_utc(tz2) or tz2 == 'UTC') - # See GH#17734 if len(vals) == 0: return np.array([], dtype=np.int64) From 359aeff34ae5da87066bcea09a09b8433366f39b Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 11 Nov 2017 13:08:03 -0800 Subject: [PATCH 4/6] only assert for tz_convert_single --- pandas/_libs/tslibs/conversion.pyx | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index 276c8c4d25da7..6ced57354bb41 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -490,9 +490,6 @@ def tz_convert(ndarray[int64_t] vals, object tz1, object tz2): pandas_datetimestruct dts datetime dt - # See GH#17734 We should always be converting either from UTC or to UTC - assert (is_utc(tz1) or tz1 == 'UTC') or (is_utc(tz2) or tz2 == 'UTC') - if len(vals) == 0: return np.array([], dtype=np.int64) From 17dd7aba40a8d952aadeb95adde65928759d8bc4 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sat, 11 Nov 2017 13:38:06 -0800 Subject: [PATCH 5/6] typo fix --- pandas/_libs/tslibs/conversion.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index 6ced57354bb41..540f1ae9c4a2c 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -401,7 +401,7 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2): """ Convert the val (in i8) from timezone1 to timezone2 - This is a single timezone versoin of tz_convert + This is a single timezone version of tz_convert Parameters ---------- From 754dd7bcc2883e582162c75e1b1794d1b125be50 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Sun, 12 Nov 2017 09:52:25 -0800 Subject: [PATCH 6/6] edit per reviewer request --- pandas/_libs/tslibs/conversion.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index 540f1ae9c4a2c..3775ab3417b63 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -447,7 +447,7 @@ cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2): if get_timezone(tz2) == 'UTC': return utc_date - if is_tzlocal(tz2): + elif is_tzlocal(tz2): dt64_to_dtstruct(utc_date, &dts) dt = datetime(dts.year, dts.month, dts.day, dts.hour, dts.min, dts.sec, dts.us, tz2)