diff --git a/pandas/tseries/tests/test_period.py b/pandas/tseries/tests/test_period.py index f34a237b55dd4..10a5e039b9fc6 100644 --- a/pandas/tseries/tests/test_period.py +++ b/pandas/tseries/tests/test_period.py @@ -1298,6 +1298,14 @@ def test_to_timestamp_preserve_name(self): conv = index.to_timestamp('D') self.assertEquals(conv.name, 'foo') + def test_to_timestamp_repr_is_code(self): + zs=[Timestamp('99-04-17 00:00:00',tz='UTC'), + Timestamp('2001-04-17 00:00:00',tz='UTC'), + Timestamp('2001-04-17 00:00:00',tz='America/Los_Angeles'), + Timestamp('2001-04-17 00:00:00',tz=None)] + for z in zs: + self.assertEquals( eval(repr(z)), z) + def test_as_frame_columns(self): rng = period_range('1/1/2000', periods=5) df = DataFrame(randn(10, 5), columns=rng) diff --git a/pandas/tslib.pyx b/pandas/tslib.pyx index 4d15ec8c8ace9..f9c1b2329c16d 100644 --- a/pandas/tslib.pyx +++ b/pandas/tslib.pyx @@ -164,20 +164,25 @@ class Timestamp(_Timestamp): def __repr__(self): result = self._repr_base + zone = None try: result += self.strftime('%z') if self.tzinfo: zone = _get_zone(self.tzinfo) - result += _tz_format(self, zone) except ValueError: year2000 = self.replace(year=2000) result += year2000.strftime('%z') if self.tzinfo: zone = _get_zone(self.tzinfo) - result += _tz_format(year2000, zone) - return '' % result + try: + result += zone.strftime(' %%Z') + except: + pass + zone = "'%s'" % zone if zone else 'None' + + return "Timestamp('%s', tz=%s)" % (result,zone) @property def _repr_base(self):