From f10b5eda7b8b6b6bf46ca6d7ddf2769da37d15ba Mon Sep 17 00:00:00 2001 From: pilkibun Date: Mon, 15 Jul 2019 22:56:50 -0500 Subject: [PATCH 1/4] CLN: fix compiler warnings in tzconversion.pyx --- pandas/_libs/tslibs/tzconversion.pyx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/tzconversion.pyx b/pandas/_libs/tslibs/tzconversion.pyx index 26a64c13f6de1..1404bd318e5d4 100644 --- a/pandas/_libs/tslibs/tzconversion.pyx +++ b/pandas/_libs/tslibs/tzconversion.pyx @@ -13,7 +13,7 @@ from dateutil.tz import tzutc import numpy as np cimport numpy as cnp -from numpy cimport ndarray, int64_t, uint8_t, intp_t +from numpy cimport ndarray, int64_t, uint8_t, intp_t, npy_bool cnp.import_array() from pandas._libs.tslibs.ccalendar import DAY_SECONDS, HOUR_SECONDS @@ -65,7 +65,7 @@ timedelta-like} """ cdef: int64_t[:] deltas, idx_shifted, idx_shifted_left, idx_shifted_right - ndarray[uint8_t, cast=True] ambiguous_array, both_nat, both_eq + npy_bool[:] ambiguous_array, both_nat, both_eq Py_ssize_t i, idx, pos, ntrans, n = len(vals) Py_ssize_t delta_idx_offset, delta_idx, pos_left, pos_right int64_t *tdata @@ -81,6 +81,8 @@ timedelta-like} list trans_grp str stamp + dst_hours = np.empty(0, dtype=np.int64) # silence false-positive compiler warning + # Vectorized version of DstTzInfo.localize if is_utc(tz) or tz is None: return vals @@ -167,7 +169,8 @@ timedelta-like} # where result_a != result_b and neither of them are NAT) both_nat = np.logical_and(result_a != NPY_NAT, result_b != NPY_NAT) both_eq = result_a == result_b - trans_idx = np.squeeze(np.nonzero(np.logical_and(both_nat, ~both_eq))) + trans_idx = np.squeeze(np.nonzero(np.logical_and(both_nat, + np.logical_not(both_eq)))) if trans_idx.size == 1: stamp = _render_tstamp(vals[trans_idx]) raise pytz.AmbiguousTimeError( From c769ebc46280c3c8498ed09bbd20e81acf4add7f Mon Sep 17 00:00:00 2001 From: pilkibun Date: Tue, 16 Jul 2019 00:03:16 -0500 Subject: [PATCH 2/4] initialize ambiguous_array with zero-len array as well --- pandas/_libs/tslibs/tzconversion.pyx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/tzconversion.pyx b/pandas/_libs/tslibs/tzconversion.pyx index 1404bd318e5d4..231a3542fb87f 100644 --- a/pandas/_libs/tslibs/tzconversion.pyx +++ b/pandas/_libs/tslibs/tzconversion.pyx @@ -65,7 +65,7 @@ timedelta-like} """ cdef: int64_t[:] deltas, idx_shifted, idx_shifted_left, idx_shifted_right - npy_bool[:] ambiguous_array, both_nat, both_eq + ndarray[uint8_t, cast=True] ambiguous_array, both_nat, both_eq Py_ssize_t i, idx, pos, ntrans, n = len(vals) Py_ssize_t delta_idx_offset, delta_idx, pos_left, pos_right int64_t *tdata @@ -81,8 +81,6 @@ timedelta-like} list trans_grp str stamp - dst_hours = np.empty(0, dtype=np.int64) # silence false-positive compiler warning - # Vectorized version of DstTzInfo.localize if is_utc(tz) or tz is None: return vals @@ -98,6 +96,8 @@ timedelta-like} result[i] = _tz_convert_tzlocal_utc(v, tz, to_utc=True) return result + # silence false-positive compiler warning + ambiguous_array = np.empty(0, dtype=bool) if isinstance(ambiguous, str): if ambiguous == 'infer': infer_dst = True @@ -161,6 +161,8 @@ timedelta-like} if v_right + deltas[pos_right] == val: result_b[i] = v_right + # silence false-positive compiler warning + dst_hours = np.empty(0, dtype=np.int64) if infer_dst: dst_hours = np.empty(n, dtype=np.int64) dst_hours[:] = NPY_NAT From 67ded9347b200afd601ede8be4b73fc286516507 Mon Sep 17 00:00:00 2001 From: pilkibun Date: Tue, 16 Jul 2019 00:18:55 -0500 Subject: [PATCH 3/4] Undo --- pandas/_libs/tslibs/tzconversion.pyx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/tzconversion.pyx b/pandas/_libs/tslibs/tzconversion.pyx index 231a3542fb87f..254e7463579be 100644 --- a/pandas/_libs/tslibs/tzconversion.pyx +++ b/pandas/_libs/tslibs/tzconversion.pyx @@ -171,8 +171,7 @@ timedelta-like} # where result_a != result_b and neither of them are NAT) both_nat = np.logical_and(result_a != NPY_NAT, result_b != NPY_NAT) both_eq = result_a == result_b - trans_idx = np.squeeze(np.nonzero(np.logical_and(both_nat, - np.logical_not(both_eq)))) + trans_idx = np.squeeze(np.nonzero(np.logical_and(both_nat, ~both_eq))) if trans_idx.size == 1: stamp = _render_tstamp(vals[trans_idx]) raise pytz.AmbiguousTimeError( From d62021c5049a33e534c85bba87f88a23dcde3fdb Mon Sep 17 00:00:00 2001 From: pilkibun Date: Tue, 16 Jul 2019 00:21:25 -0500 Subject: [PATCH 4/4] Undo --- pandas/_libs/tslibs/tzconversion.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/tzconversion.pyx b/pandas/_libs/tslibs/tzconversion.pyx index 254e7463579be..dd0c6fc75b06f 100644 --- a/pandas/_libs/tslibs/tzconversion.pyx +++ b/pandas/_libs/tslibs/tzconversion.pyx @@ -13,7 +13,7 @@ from dateutil.tz import tzutc import numpy as np cimport numpy as cnp -from numpy cimport ndarray, int64_t, uint8_t, intp_t, npy_bool +from numpy cimport ndarray, int64_t, uint8_t, intp_t cnp.import_array() from pandas._libs.tslibs.ccalendar import DAY_SECONDS, HOUR_SECONDS