@@ -313,7 +313,7 @@ def test_repr_max_columns_max_rows(self):
313
313
"{0} x {1}" .format (term_width , term_height ))
314
314
315
315
def mkframe (n ):
316
- index = ['% 05d' % i for i in range (n )]
316
+ index = ['{i: 05d}' . format ( i = i ) for i in range (n )]
317
317
return DataFrame (0 , index , index )
318
318
319
319
df6 = mkframe (6 )
@@ -465,9 +465,9 @@ def test_to_string_with_formatters(self):
465
465
'object' : [(1 , 2 ), True , False ]},
466
466
columns = ['int' , 'float' , 'object' ])
467
467
468
- formatters = [('int' , lambda x : '0x%x' % x ),
469
- ('float' , lambda x : '[% 4.1f]' % x ),
470
- ('object' , lambda x : '-%s-' % str ( x ))]
468
+ formatters = [('int' , lambda x : '0x{x:x}' . format ( x = x ) ),
469
+ ('float' , lambda x : '[{x: 4.1f}]' . format ( x = x ) ),
470
+ ('object' , lambda x : '-{x!s}-' . format ( x = x ))]
471
471
result = df .to_string (formatters = dict (formatters ))
472
472
result2 = df .to_string (formatters = lzip (* formatters )[1 ])
473
473
assert result == (' int float object\n '
@@ -500,7 +500,8 @@ def format_func(x):
500
500
501
501
def test_to_string_with_formatters_unicode (self ):
502
502
df = DataFrame ({u ('c/\u03c3 ' ): [1 , 2 , 3 ]})
503
- result = df .to_string (formatters = {u ('c/\u03c3 ' ): lambda x : '%s' % x })
503
+ result = df .to_string (
504
+ formatters = {u ('c/\u03c3 ' ): lambda x : '{x}' .format (x = x )})
504
505
assert result == u (' c/\u03c3 \n ' ) + '0 1\n 1 2\n 2 3'
505
506
506
507
def test_east_asian_unicode_frame (self ):
@@ -944,7 +945,7 @@ def test_wide_repr(self):
944
945
set_option ('display.expand_frame_repr' , False )
945
946
rep_str = repr (df )
946
947
947
- assert "10 rows x %d columns" % ( max_cols - 1 ) in rep_str
948
+ assert "10 rows x {c} columns" . format ( c = max_cols - 1 ) in rep_str
948
949
set_option ('display.expand_frame_repr' , True )
949
950
wide_repr = repr (df )
950
951
assert rep_str != wide_repr
@@ -1056,7 +1057,7 @@ def test_long_series(self):
1056
1057
n = 1000
1057
1058
s = Series (
1058
1059
np .random .randint (- 50 , 50 , n ),
1059
- index = ['s% 04d' % x for x in range (n )], dtype = 'int64' )
1060
+ index = ['s{x: 04d}' . format ( x = x ) for x in range (n )], dtype = 'int64' )
1060
1061
1061
1062
import re
1062
1063
str_rep = str (s )
@@ -1174,7 +1175,7 @@ def test_to_string(self):
1174
1175
assert header == expected
1175
1176
1176
1177
biggie .to_string (columns = ['B' , 'A' ],
1177
- formatters = {'A' : lambda x : '% .1f' % x })
1178
+ formatters = {'A' : lambda x : '{x: .1f}' . format ( x = x ) })
1178
1179
1179
1180
biggie .to_string (columns = ['B' , 'A' ], float_format = str )
1180
1181
biggie .to_string (columns = ['B' , 'A' ], col_space = 12 , float_format = str )
@@ -1269,7 +1270,7 @@ def test_to_string_small_float_values(self):
1269
1270
1270
1271
result = df .to_string ()
1271
1272
# sadness per above
1272
- if '% .4g' % 1.7e8 == '1.7e+008' :
1273
+ if '{x: .4g}' . format ( x = 1.7e8 ) == '1.7e+008' :
1273
1274
expected = (' a\n '
1274
1275
'0 1.500000e+000\n '
1275
1276
'1 1.000000e-017\n '
@@ -1456,7 +1457,7 @@ def test_repr_html_long(self):
1456
1457
long_repr = df ._repr_html_ ()
1457
1458
assert '..' in long_repr
1458
1459
assert str (41 + max_rows // 2 ) not in long_repr
1459
- assert u ('%d rows ' ) % h in long_repr
1460
+ assert u ('{h} rows ' ). format ( h = h ) in long_repr
1460
1461
assert u ('2 columns' ) in long_repr
1461
1462
1462
1463
def test_repr_html_float (self ):
@@ -1478,7 +1479,7 @@ def test_repr_html_float(self):
1478
1479
long_repr = df ._repr_html_ ()
1479
1480
assert '..' in long_repr
1480
1481
assert '31' not in long_repr
1481
- assert u ('%d rows ' ) % h in long_repr
1482
+ assert u ('{h} rows ' ). format ( h = h ) in long_repr
1482
1483
assert u ('2 columns' ) in long_repr
1483
1484
1484
1485
def test_repr_html_long_multiindex (self ):
@@ -1673,7 +1674,7 @@ def test_to_string(self):
1673
1674
result = cp .to_string (length = True , name = True , dtype = True )
1674
1675
last_line = result .split ('\n ' )[- 1 ].strip ()
1675
1676
assert last_line == ("Freq: B, Name: foo, "
1676
- "Length: %d , dtype: float64" % len (cp ))
1677
+ "Length: {cp} , dtype: float64" . format ( cp = len (cp ) ))
1677
1678
1678
1679
def test_freq_name_separation (self ):
1679
1680
s = Series (np .random .randn (10 ),
@@ -2176,7 +2177,7 @@ def test_to_string_header(self):
2176
2177
2177
2178
2178
2179
def _three_digit_exp ():
2179
- return '% .4g' % 1.7e8 == '1.7e+008'
2180
+ return '{x: .4g}' . format ( x = 1.7e8 ) == '1.7e+008'
2180
2181
2181
2182
2182
2183
class TestFloatArrayFormatter (object ):
0 commit comments