@@ -421,12 +421,10 @@ def test_repr_truncation_column_size(self):
421421 def test_repr_max_columns_max_rows (self ):
422422 term_width , term_height = get_terminal_size ()
423423 if term_width < 10 or term_height < 10 :
424- pytest .skip (
425- "terminal size too small, {0} x {1}" .format (term_width , term_height )
426- )
424+ pytest .skip (f"terminal size too small, { term_width } x { term_height } " )
427425
428426 def mkframe (n ):
429- index = ["{i:05d}" . format ( i = i ) for i in range (n )]
427+ index = [f "{ i :05d} " for i in range (n )]
430428 return DataFrame (0 , index , index )
431429
432430 df6 = mkframe (6 )
@@ -667,9 +665,9 @@ def test_to_string_with_formatters(self):
667665 )
668666
669667 formatters = [
670- ("int" , lambda x : "0x{x:x}" . format ( x = x ) ),
671- ("float" , lambda x : "[{x: 4.1f}]" . format ( x = x ) ),
672- ("object" , lambda x : "-{x!s}-" . format ( x = x ) ),
668+ ("int" , lambda x : f "0x{ x :x} " ),
669+ ("float" , lambda x : f "[{ x : 4.1f} ]" ),
670+ ("object" , lambda x : f "-{ x !s} -" ),
673671 ]
674672 result = df .to_string (formatters = dict (formatters ))
675673 result2 = df .to_string (formatters = list (zip (* formatters ))[1 ])
@@ -711,7 +709,7 @@ def format_func(x):
711709
712710 def test_to_string_with_formatters_unicode (self ):
713711 df = DataFrame ({"c/\u03c3 " : [1 , 2 , 3 ]})
714- result = df .to_string (formatters = {"c/\u03c3 " : lambda x : "{x}" . format ( x = x ) })
712+ result = df .to_string (formatters = {"c/\u03c3 " : str })
715713 assert result == " c/\u03c3 \n " + "0 1\n 1 2\n 2 3"
716714
717715 def test_east_asian_unicode_false (self ):
@@ -1240,7 +1238,7 @@ def test_wide_repr(self):
12401238 set_option ("display.expand_frame_repr" , False )
12411239 rep_str = repr (df )
12421240
1243- assert "10 rows x {c} columns" . format ( c = max_cols - 1 ) in rep_str
1241+ assert f "10 rows x { max_cols - 1 } columns" in rep_str
12441242 set_option ("display.expand_frame_repr" , True )
12451243 wide_repr = repr (df )
12461244 assert rep_str != wide_repr
@@ -1351,7 +1349,7 @@ def test_long_series(self):
13511349 n = 1000
13521350 s = Series (
13531351 np .random .randint (- 50 , 50 , n ),
1354- index = ["s{x:04d}" . format ( x = x ) for x in range (n )],
1352+ index = [f "s{ x :04d} " for x in range (n )],
13551353 dtype = "int64" ,
13561354 )
13571355
@@ -1477,9 +1475,7 @@ def test_to_string(self):
14771475 expected = ["A" ]
14781476 assert header == expected
14791477
1480- biggie .to_string (
1481- columns = ["B" , "A" ], formatters = {"A" : lambda x : "{x:.1f}" .format (x = x )}
1482- )
1478+ biggie .to_string (columns = ["B" , "A" ], formatters = {"A" : lambda x : f"{ x :.1f} " })
14831479
14841480 biggie .to_string (columns = ["B" , "A" ], float_format = str )
14851481 biggie .to_string (columns = ["B" , "A" ], col_space = 12 , float_format = str )
@@ -1610,7 +1606,7 @@ def test_to_string_small_float_values(self):
16101606
16111607 result = df .to_string ()
16121608 # sadness per above
1613- if "{x:.4g}" . format ( x = 1.7e8 ) == "1.7e+008" :
1609+ if _three_digit_exp () :
16141610 expected = (
16151611 " a\n "
16161612 "0 1.500000e+000\n "
@@ -1922,7 +1918,7 @@ def test_repr_html_long(self):
19221918 long_repr = df ._repr_html_ ()
19231919 assert ".." in long_repr
19241920 assert str (41 + max_rows // 2 ) not in long_repr
1925- assert "{h} rows " . format ( h = h ) in long_repr
1921+ assert f "{ h } rows " in long_repr
19261922 assert "2 columns" in long_repr
19271923
19281924 def test_repr_html_float (self ):
@@ -1939,7 +1935,7 @@ def test_repr_html_float(self):
19391935 ).set_index ("idx" )
19401936 reg_repr = df ._repr_html_ ()
19411937 assert ".." not in reg_repr
1942- assert "<td>{val }</td>" . format ( val = str ( 40 + h )) in reg_repr
1938+ assert f "<td>{ 40 + h } </td>" in reg_repr
19431939
19441940 h = max_rows + 1
19451941 df = DataFrame (
@@ -1951,8 +1947,8 @@ def test_repr_html_float(self):
19511947 ).set_index ("idx" )
19521948 long_repr = df ._repr_html_ ()
19531949 assert ".." in long_repr
1954- assert "<td>{val} </td>" . format ( val = "31" ) not in long_repr
1955- assert "{h} rows " . format ( h = h ) in long_repr
1950+ assert "<td>31 </td>" not in long_repr
1951+ assert f "{ h } rows " in long_repr
19561952 assert "2 columns" in long_repr
19571953
19581954 def test_repr_html_long_multiindex (self ):
@@ -2181,9 +2177,7 @@ def test_to_string(self):
21812177 cp .name = "foo"
21822178 result = cp .to_string (length = True , name = True , dtype = True )
21832179 last_line = result .split ("\n " )[- 1 ].strip ()
2184- assert last_line == (
2185- "Freq: B, Name: foo, Length: {cp}, dtype: float64" .format (cp = len (cp ))
2186- )
2180+ assert last_line == (f"Freq: B, Name: foo, Length: { len (cp )} , dtype: float64" )
21872181
21882182 def test_freq_name_separation (self ):
21892183 s = Series (
@@ -2782,7 +2776,7 @@ def test_to_string_na_rep(self):
27822776
27832777 def test_to_string_float_format (self ):
27842778 s = pd .Series (range (10 ), dtype = "float64" )
2785- res = s .to_string (float_format = lambda x : "{0 :2.1f}". format ( x ) , max_rows = 2 )
2779+ res = s .to_string (float_format = lambda x : f" { x :2.1f} " , max_rows = 2 )
27862780 exp = "0 0.0\n ..\n 9 9.0"
27872781 assert res == exp
27882782
@@ -2807,7 +2801,7 @@ def test_to_string_multindex_header(self):
28072801
28082802
28092803def _three_digit_exp ():
2810- return "{x :.4g}". format ( x = 1.7e8 ) == "1.7e+008"
2804+ return f" { 1.7e8 :.4g} " == "1.7e+008"
28112805
28122806
28132807class TestFloatArrayFormatter :
0 commit comments