Skip to content

Commit

Permalink
BUG: DatetimeIndex localizes twice if input is localized DatetimeIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
Chang She authored and wesm committed Sep 20, 2012
1 parent 8fc8d6f commit b9848a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,13 @@ def __new__(cls, data=None,
else:
if tz is not None:
tz = tools._maybe_get_tz(tz)
# Convert local to UTC
ints = subarr.view('i8')

subarr = lib.tz_localize_to_utc(ints, tz)
if (not isinstance(data, DatetimeIndex) or
getattr(data, 'tz', None) is None):
# Convert tz-naive to UTC
ints = subarr.view('i8')
subarr = lib.tz_localize_to_utc(ints, tz)

subarr = subarr.view(_NS_DTYPE)

subarr = subarr.view(cls)
Expand Down
6 changes: 6 additions & 0 deletions pandas/tseries/tests/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,12 @@ def test_timestamp_equality_different_timezones(self):
self.assert_((utc_range == berlin_range).all())
self.assert_((berlin_range == eastern_range).all())

def test_datetimeindex_tz(self):
rng = date_range('03/12/2012 00:00', periods=10, freq='W-FRI',
tz='US/Eastern')
rng2 = DatetimeIndex(data=rng, tz='US/Eastern')
self.assert_(rng.equals(rng2))

if __name__ == '__main__':
nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],
exit=False)

0 comments on commit b9848a6

Please sign in to comment.