From 38bed4d7aae27ebb3fdb86674cdde71a9a56c39b Mon Sep 17 00:00:00 2001 From: Ka Wo Chen Date: Thu, 11 Feb 2016 23:03:56 -0500 Subject: [PATCH] BUG: GH12290 where tz_convert used values of uninitialized arrays --- doc/source/whatsnew/v0.18.0.txt | 1 + pandas/tests/series/test_operators.py | 11 +++++++++++ pandas/tslib.pyx | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.18.0.txt b/doc/source/whatsnew/v0.18.0.txt index ae5842b22349a..052e8ba0c2f2a 100644 --- a/doc/source/whatsnew/v0.18.0.txt +++ b/doc/source/whatsnew/v0.18.0.txt @@ -906,6 +906,7 @@ Bug Fixes - Bug in ``NaT`` subtraction from ``Timestamp`` or ``DatetimeIndex`` with timezones (:issue:`11718`) +- Bug in subtraction of ``Series`` of a single tz-aware ``Timestamp`` (:issue:`12290`) - Bug in ``Timedelta.round`` with negative values (:issue:`11690`) - Bug in ``.loc`` against ``CategoricalIndex`` may result in normal ``Index`` (:issue:`11586`) diff --git a/pandas/tests/series/test_operators.py b/pandas/tests/series/test_operators.py index d36cc0c303dfe..cf8a47cc50af4 100644 --- a/pandas/tests/series/test_operators.py +++ b/pandas/tests/series/test_operators.py @@ -660,6 +660,17 @@ def run_ops(ops, get_ser, test_ser): self.assertRaises(TypeError, lambda: td1 - dt1) self.assertRaises(TypeError, lambda: td2 - dt2) + def test_sub_single_tz(self): + # GH12290 + s1 = Series([pd.Timestamp('2016-02-10', tz='America/Sao_Paulo')]) + s2 = Series([pd.Timestamp('2016-02-08', tz='America/Sao_Paulo')]) + result = s1 - s2 + expected = Series([Timedelta('2days')]) + assert_series_equal(result, expected) + result = s2 - s1 + expected = Series([Timedelta('-2days')]) + assert_series_equal(result, expected) + def test_ops_nat(self): # GH 11349 timedelta_series = Series([NaT, Timedelta('1s')]) diff --git a/pandas/tslib.pyx b/pandas/tslib.pyx index fe5d06e520cbf..112a41b72f3ea 100644 --- a/pandas/tslib.pyx +++ b/pandas/tslib.pyx @@ -3530,7 +3530,7 @@ def tz_convert(ndarray[int64_t] vals, object tz1, object tz2): if _get_zone(tz2) == 'UTC': return utc_dates - result = np.empty(n, dtype=np.int64) + result = np.zeros(n, dtype=np.int64) if _is_tzlocal(tz2): for i in range(n): v = utc_dates[i]