Skip to content

Commit 65dde70

Browse files
committed
BUG: don't lose tzinfo when shifting by different frequency close pandas-dev#1683
1 parent 48a3194 commit 65dde70

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

RELEASE.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pandas 0.8.2
6464
- Fix errors with how='median' and generic NumPy resampling in some cases
6565
caused by SeriesBinGrouper (#1648, #1688)
6666
- When grouping by level, exclude unobserved levels (#1697)
67+
- Don't lose tzinfo in DatetimeIndex when shifting by different offset (#1683)
6768

6869
pandas 0.8.1
6970
============

pandas/tseries/index.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,10 @@ def shift(self, n, freq=None):
656656
if freq is not None and freq != self.offset:
657657
if isinstance(freq, basestring):
658658
freq = to_offset(freq)
659-
return Index.shift(self, n, freq)
659+
result = Index.shift(self, n, freq)
660+
result.tz = self.tz
661+
662+
return result
660663

661664
if n == 0:
662665
# immutable so OK
@@ -668,7 +671,7 @@ def shift(self, n, freq=None):
668671
start = self[0] + n * self.offset
669672
end = self[-1] + n * self.offset
670673
return DatetimeIndex(start=start, end=end, freq=self.offset,
671-
name=self.name)
674+
name=self.name, tz=self.tz)
672675

673676
def repeat(self, repeats, axis=None):
674677
"""

pandas/tseries/tests/test_timezones.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,14 @@ def test_tz_convert_unsorted(self):
397397
exp = dr.hour[::-1]
398398
tm.assert_almost_equal(result, exp)
399399

400+
def test_shift_localized(self):
401+
dr = date_range('2011/1/1', '2012/1/1', freq='W-FRI')
402+
dr_tz = dr.tz_localize('US/Eastern')
403+
404+
result = dr_tz.shift(1, '10T')
405+
self.assert_(result.tz == dr_tz.tz)
406+
407+
400408
class TestTimeZones(unittest.TestCase):
401409

402410
def setUp(self):

0 commit comments

Comments
 (0)