Skip to content

Commit b9848a6

Browse files
Chang Shewesm
Chang She
authored andcommitted
BUG: DatetimeIndex localizes twice if input is localized DatetimeIndex #1838
1 parent 8fc8d6f commit b9848a6

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pandas/tseries/index.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,13 @@ def __new__(cls, data=None,
242242
else:
243243
if tz is not None:
244244
tz = tools._maybe_get_tz(tz)
245-
# Convert local to UTC
246-
ints = subarr.view('i8')
247245

248-
subarr = lib.tz_localize_to_utc(ints, tz)
246+
if (not isinstance(data, DatetimeIndex) or
247+
getattr(data, 'tz', None) is None):
248+
# Convert tz-naive to UTC
249+
ints = subarr.view('i8')
250+
subarr = lib.tz_localize_to_utc(ints, tz)
251+
249252
subarr = subarr.view(_NS_DTYPE)
250253

251254
subarr = subarr.view(cls)

pandas/tseries/tests/test_timezones.py

+6
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,12 @@ def test_timestamp_equality_different_timezones(self):
656656
self.assert_((utc_range == berlin_range).all())
657657
self.assert_((berlin_range == eastern_range).all())
658658

659+
def test_datetimeindex_tz(self):
660+
rng = date_range('03/12/2012 00:00', periods=10, freq='W-FRI',
661+
tz='US/Eastern')
662+
rng2 = DatetimeIndex(data=rng, tz='US/Eastern')
663+
self.assert_(rng.equals(rng2))
664+
659665
if __name__ == '__main__':
660666
nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],
661667
exit=False)

0 commit comments

Comments
 (0)