From 888d68fa832194cfc6dfb9927170bda4f7ccd0ed Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Thu, 18 Dec 2014 06:27:13 -0500 Subject: [PATCH] BUG: Bug in DatetimeIndex iteration, related to (GH8890), fixed in (GH9100) --- doc/source/whatsnew/v0.16.0.txt | 1 + pandas/tseries/tests/test_timeseries.py | 10 ++++++++++ pandas/tslib.pyx | 7 ++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v0.16.0.txt b/doc/source/whatsnew/v0.16.0.txt index 8720774b821a2..8122b60b736c9 100644 --- a/doc/source/whatsnew/v0.16.0.txt +++ b/doc/source/whatsnew/v0.16.0.txt @@ -51,3 +51,4 @@ Bug Fixes - Fixed compatibility issue in ``DatetimeIndex`` affecting architectures where ``numpy.int_`` defaults to ``numpy.int32`` (:issue:`8943`) - Bug in ``MultiIndex.has_duplicates`` when having many levels causes an indexer overflow (:issue:`9075`) +- Bug in DatetimeIndex iteration, related to (:issue:`8890`), fixed in (:issue:`9100`) diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index 9b8200e266e5a..cc81c2d8a8960 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -2332,8 +2332,18 @@ def test_iteration_preserves_tz(self): for i, ts in enumerate(index): result = ts expected = index[i] + self.assertEqual(result._repr_base, expected._repr_base) self.assertEqual(result, expected) + # 9100 + index = pd.DatetimeIndex(['2014-12-01 03:32:39.987000-08:00','2014-12-01 04:12:34.987000-08:00']) + for i, ts in enumerate(index): + result = ts + expected = index[i] + self.assertEqual(result._repr_base, expected._repr_base) + 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 e3e18b912132d..78a3a5d75cfd3 100644 --- a/pandas/tslib.pyx +++ b/pandas/tslib.pyx @@ -128,9 +128,10 @@ def ints_to_pydatetime(ndarray[int64_t] arr, tz=None, offset=None, box=False): result[i] = NaT else: pandas_datetime_to_datetimestruct(value, PANDAS_FR_ns, &dts) - dt = func_create(value, dts, tz, offset) - if not box: - dt = dt + tz.utcoffset(dt) + dt = create_datetime_from_ts(value, dts, tz, offset) + dt = dt + tz.utcoffset(dt) + if box: + dt = Timestamp(dt) result[i] = dt else: trans, deltas, typ = _get_dst_info(tz)