Skip to content

Commit a53cfa9

Browse files
committed
BUG: display localtime in DatetimeIndex.__repr__, close #1336
1 parent c878694 commit a53cfa9

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

pandas/core/format.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,11 @@ def get_result(self):
587587
fmt_values = [formatter(x) for x in self.values]
588588
return _make_fixed_width(fmt_values, self.justify)
589589

590-
def _format_datetime64(x):
590+
def _format_datetime64(x, tz=None):
591591
if isnull(x):
592592
return 'NaT'
593593

594-
stamp = lib.Timestamp(x)
594+
stamp = lib.Timestamp(x, tz=tz)
595595
base = stamp.strftime('%Y-%m-%d %H:%M:%S')
596596

597597
fraction = stamp.microsecond * 1000 + stamp.nanosecond

pandas/tseries/index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ def __repr__(self):
421421

422422
summary = str(self.__class__)
423423
if len(self) > 0:
424-
first = _format_datetime64(values[0])
425-
last = _format_datetime64(values[-1])
424+
first = _format_datetime64(values[0], tz=self.tz)
425+
last = _format_datetime64(values[-1], tz=self.tz)
426426
summary += '\n[%s, ..., %s]' % (first, last)
427427
tagline = '\nLength: %d, Freq: %s, Timezone: %s'
428428
summary += tagline % (len(self), freq, self.tz)

pandas/tseries/tests/test_timezones.py

+7
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,13 @@ def test_take_dont_lose_meta(self):
243243
self.assert_(result.tz == rng.tz)
244244
self.assert_(result.freq == rng.freq)
245245

246+
def test_index_with_timezone_repr(self):
247+
rng = date_range('4/13/2010', '5/6/2010')
248+
249+
rng_eastern = rng.tz_convert('US/Eastern')
250+
251+
rng_repr = repr(rng)
252+
self.assert_('2010-04-13 00:00:00' in rng_repr)
246253

247254
class TestTimeZones(unittest.TestCase):
248255

0 commit comments

Comments
 (0)