From 27133c80b8f4a9f482111581b6f3c787ba9179e8 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Wed, 3 Dec 2014 20:26:34 -0500 Subject: [PATCH] REGR: Regression in DatetimeIndex iteration with a Fixed/Local offset timezone (GH8890) --- doc/source/whatsnew/v0.15.2.txt | 1 + pandas/tseries/tests/test_timeseries.py | 21 +++++++++++++++++++++ pandas/tslib.pyx | 4 +++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.15.2.txt b/doc/source/whatsnew/v0.15.2.txt index 260e4e8a17c7d..4fbf7cbfa7c98 100644 --- a/doc/source/whatsnew/v0.15.2.txt +++ b/doc/source/whatsnew/v0.15.2.txt @@ -118,6 +118,7 @@ Bug Fixes s.loc['c':'a':-1] - Report a ``TypeError`` when invalid/no paramaters are passed in a groupby (:issue:`8015`) +- Regression in DatetimeIndex iteration with a Fixed/Local offset timezone (:issue:`8890`) - Bug in packaging pandas with ``py2app/cx_Freeze`` (:issue:`8602`, :issue:`8831`) - Bug in ``groupby`` signatures that didn't include \*args or \*\*kwargs (:issue:`8733`). - ``io.data.Options`` now raises ``RemoteDataError`` when no expiry dates are available from Yahoo and when it receives no data from Yahoo (:issue:`8761`), (:issue:`8783`). diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index 436f9f3b9c9b3..12e10a71c67b2 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -2313,6 +2313,27 @@ def test_map(self): exp = [f(x) for x in rng] self.assert_numpy_array_equal(result, exp) + + def test_iteration_preserves_tz(self): + + tm._skip_if_no_dateutil() + + # GH 8890 + import dateutil + index = date_range("2012-01-01", periods=3, freq='H', tz='US/Eastern') + + for i, ts in enumerate(index): + result = ts + expected = index[i] + self.assertEqual(result, expected) + + index = date_range("2012-01-01", periods=3, freq='H', tz=dateutil.tz.tzoffset(None, -28800)) + + for i, ts in enumerate(index): + result = ts + expected = index[i] + self.assertEqual(result, expected) + def test_misc_coverage(self): rng = date_range('1/1/2000', periods=5) result = rng.groupby(rng.day) diff --git a/pandas/tslib.pyx b/pandas/tslib.pyx index 8efc174d6890b..02c1ae82a7fca 100644 --- a/pandas/tslib.pyx +++ b/pandas/tslib.pyx @@ -122,7 +122,9 @@ def ints_to_pydatetime(ndarray[int64_t] arr, tz=None, offset=None, box=False): else: pandas_datetime_to_datetimestruct(value, PANDAS_FR_ns, &dts) dt = func_create(value, dts, tz, offset) - result[i] = dt + tz.utcoffset(dt) + if not box: + dt = dt + tz.utcoffset(dt) + result[i] = dt else: trans = _get_transitions(tz) deltas = _get_deltas(tz)