File tree 2 files changed +14
-1
lines changed 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -1399,7 +1399,7 @@ def first_write(self, v):
1399
1399
if len (fmt ) != ncol :
1400
1400
raise AttributeError ('fmt has wrong shape. %s' % str (fmt ))
1401
1401
format = asstr (delimiter ).join (map (asstr , fmt ))
1402
- elif isinstance (fmt , str ):
1402
+ elif isinstance (fmt , basestring ):
1403
1403
n_fmt_chars = fmt .count ('%' )
1404
1404
error = ValueError ('fmt has wrong number of %% formats: %s' % fmt )
1405
1405
if n_fmt_chars == 1 :
Original file line number Diff line number Diff line change @@ -561,6 +561,19 @@ def test_unicode_stringstream(self):
561
561
s .seek (0 )
562
562
assert_equal (s .read (), utf8 + '\n ' )
563
563
564
+ @pytest .mark .parametrize ("fmt" , [u"%f" , b"%f" ])
565
+ @pytest .mark .parametrize ("iotype" , [StringIO , BytesIO ])
566
+ def test_unicode_and_bytes_fmt (self , fmt , iotype ):
567
+ # string type of fmt should not matter, see also gh-4053
568
+ a = np .array ([1. ])
569
+ s = iotype ()
570
+ np .savetxt (s , a , fmt = fmt )
571
+ s .seek (0 )
572
+ if iotype is StringIO :
573
+ assert_equal (s .read (), u"%f\n " % 1. )
574
+ else :
575
+ assert_equal (s .read (), b"%f\n " % 1. )
576
+
564
577
565
578
class LoadTxtBase (object ):
566
579
def check_compressed (self , fopen , suffixes ):
You can’t perform that action at this time.
0 commit comments