File tree 2 files changed +22
-3
lines changed
2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -383,7 +383,7 @@ def adjoin(space, *lists):
383
383
Glues together two sets of strings using the amount of space requested.
384
384
The idea is to prettify.
385
385
"""
386
- outLines = []
386
+ out_lines = []
387
387
newLists = []
388
388
lengths = [max (map (len , x )) + space for x in lists [:- 1 ]]
389
389
@@ -397,8 +397,16 @@ def adjoin(space, *lists):
397
397
newLists .append (nl )
398
398
toJoin = zip (* newLists )
399
399
for lines in toJoin :
400
- outLines .append ('' .join (lines ))
401
- return '\n ' .join (outLines )
400
+ out_lines .append (_join_unicode (lines ))
401
+ return _join_unicode (out_lines , sep = '\n ' )
402
+
403
+ def _join_unicode (lines , sep = '' ):
404
+ try :
405
+ return sep .join (lines )
406
+ except UnicodeDecodeError :
407
+ sep = unicode (sep )
408
+ return sep .join ([x .decode ('utf-8' ) if isinstance (x , str ) else x
409
+ for x in lines ])
402
410
403
411
def iterpairs (seq ):
404
412
"""
Original file line number Diff line number Diff line change @@ -233,6 +233,17 @@ def test_to_string_float_formatting(self):
233
233
'1 2.512000e-01' )
234
234
assert (df_s == expected )
235
235
236
+ def test_to_string_ascii_error (self ):
237
+ data = [('0 ' ,
238
+ u' .gitignore ' ,
239
+ u' 5 ' ,
240
+ ' \xe2 \x80 \xa2 \xe2 \x80 \xa2 \xe2 \x80 '
241
+ '\xa2 \xe2 \x80 \xa2 \xe2 \x80 \xa2 ' )]
242
+ df = DataFrame (data )
243
+
244
+ # it works!
245
+ repr (df )
246
+
236
247
def test_to_string_int_formatting (self ):
237
248
df = DataFrame ({'x' : [- 15 , 20 , 25 , - 35 ]})
238
249
self .assert_ (issubclass (df ['x' ].dtype .type , np .integer ))
You can’t perform that action at this time.
0 commit comments