File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -1298,6 +1298,14 @@ def test_to_timestamp_preserve_name(self):
1298
1298
conv = index .to_timestamp ('D' )
1299
1299
self .assertEquals (conv .name , 'foo' )
1300
1300
1301
+ def test_to_timestamp_repr_is_code (self ):
1302
+ zs = [Timestamp ('99-04-17 00:00:00' ,tz = 'UTC' ),
1303
+ Timestamp ('2001-04-17 00:00:00' ,tz = 'UTC' ),
1304
+ Timestamp ('2001-04-17 00:00:00' ,tz = 'America/Los_Angeles' ),
1305
+ Timestamp ('2001-04-17 00:00:00' ,tz = None )]
1306
+ for z in zs :
1307
+ self .assertEquals ( eval (repr (z )), z )
1308
+
1301
1309
def test_as_frame_columns (self ):
1302
1310
rng = period_range ('1/1/2000' , periods = 5 )
1303
1311
df = DataFrame (randn (10 , 5 ), columns = rng )
Original file line number Diff line number Diff line change @@ -164,20 +164,25 @@ class Timestamp(_Timestamp):
164
164
165
165
def __repr__ (self ):
166
166
result = self ._repr_base
167
+ zone = None
167
168
168
169
try :
169
170
result += self .strftime(' %z ' )
170
171
if self .tzinfo:
171
172
zone = _get_zone(self .tzinfo)
172
- result += _tz_format(self , zone)
173
173
except ValueError :
174
174
year2000 = self .replace(year = 2000 )
175
175
result += year2000.strftime(' %z ' )
176
176
if self .tzinfo:
177
177
zone = _get_zone(self .tzinfo)
178
- result += _tz_format(year2000, zone)
179
178
180
- return ' <Timestamp: %s >' % result
179
+ try :
180
+ result += zone.strftime(' %% Z' )
181
+ except :
182
+ pass
183
+ zone = " '%s '" % zone if zone else ' None'
184
+
185
+ return " Timestamp('%s ', tz=%s )" % (result,zone)
181
186
182
187
@property
183
188
def _repr_base (self ):
You can’t perform that action at this time.
0 commit comments