@@ -230,7 +230,7 @@ def format_attr(pair):
230
230
# ... except maybe the last for columns.names
231
231
name = self .data .columns .names [r ]
232
232
cs = [BLANK_CLASS if name is None else INDEX_NAME_CLASS ,
233
- "level%s" % r ]
233
+ "level{lvl}" . format ( lvl = r ) ]
234
234
name = BLANK_VALUE if name is None else name
235
235
row_es .append ({"type" : "th" ,
236
236
"value" : name ,
@@ -240,7 +240,8 @@ def format_attr(pair):
240
240
241
241
if clabels :
242
242
for c , value in enumerate (clabels [r ]):
243
- cs = [COL_HEADING_CLASS , "level%s" % r , "col%s" % c ]
243
+ cs = [COL_HEADING_CLASS , "level{lvl}" .format (lvl = r ),
244
+ "col{col}" .format (col = c )]
244
245
cs .extend (cell_context .get (
245
246
"col_headings" , {}).get (r , {}).get (c , []))
246
247
es = {
@@ -264,7 +265,7 @@ def format_attr(pair):
264
265
265
266
for c , name in enumerate (self .data .index .names ):
266
267
cs = [INDEX_NAME_CLASS ,
267
- "level%s" % c ]
268
+ "level{lvl}" . format ( lvl = c ) ]
268
269
name = '' if name is None else name
269
270
index_header_row .append ({"type" : "th" , "value" : name ,
270
271
"class" : " " .join (cs )})
@@ -281,7 +282,8 @@ def format_attr(pair):
281
282
for r , idx in enumerate (self .data .index ):
282
283
row_es = []
283
284
for c , value in enumerate (rlabels [r ]):
284
- rid = [ROW_HEADING_CLASS , "level%s" % c , "row%s" % r ]
285
+ rid = [ROW_HEADING_CLASS , "level{lvl}" .format (lvl = c ),
286
+ "row{row}" .format (row = r )]
285
287
es = {
286
288
"type" : "th" ,
287
289
"is_visible" : _is_visible (r , c , idx_lengths ),
@@ -298,7 +300,8 @@ def format_attr(pair):
298
300
row_es .append (es )
299
301
300
302
for c , col in enumerate (self .data .columns ):
301
- cs = [DATA_CLASS , "row%s" % r , "col%s" % c ]
303
+ cs = [DATA_CLASS , "row{row}" .format (row = r ),
304
+ "col{col}" .format (col = c )]
302
305
cs .extend (cell_context .get ("data" , {}).get (r , {}).get (c , []))
303
306
formatter = self ._display_funcs [(r , c )]
304
307
value = self .data .iloc [r , c ]
@@ -317,7 +320,8 @@ def format_attr(pair):
317
320
else :
318
321
props .append (['' , '' ])
319
322
cellstyle .append ({'props' : props ,
320
- 'selector' : "row%s_col%s" % (r , c )})
323
+ 'selector' : "row{row}_col{col}"
324
+ .format (row = r , col = c )})
321
325
body .append (row_es )
322
326
323
327
return dict (head = head , cellstyle = cellstyle , body = body , uuid = uuid ,
@@ -512,22 +516,23 @@ def _apply(self, func, axis=0, subset=None, **kwargs):
512
516
result = func (data , ** kwargs )
513
517
if not isinstance (result , pd .DataFrame ):
514
518
raise TypeError (
515
- "Function {!r} must return a DataFrame when "
516
- "passed to `Styler.apply` with axis=None" .format (func ))
519
+ "Function {func!r} must return a DataFrame when "
520
+ "passed to `Styler.apply` with axis=None"
521
+ .format (func = func ))
517
522
if not (result .index .equals (data .index ) and
518
523
result .columns .equals (data .columns )):
519
- msg = ('Result of {!r} must have identical index and columns '
520
- 'as the input' .format (func ))
524
+ msg = ('Result of {func !r} must have identical index and '
525
+ 'columns as the input' .format (func = func ))
521
526
raise ValueError (msg )
522
527
523
528
result_shape = result .shape
524
529
expected_shape = self .data .loc [subset ].shape
525
530
if result_shape != expected_shape :
526
- msg = ("Function {!r} returned the wrong shape.\n "
527
- "Result has shape: {}\n "
528
- "Expected shape: {}" .format (func ,
529
- result .shape ,
530
- expected_shape ))
531
+ msg = ("Function {func !r} returned the wrong shape.\n "
532
+ "Result has shape: {res }\n "
533
+ "Expected shape: {expect }" .format (func = func ,
534
+ res = result .shape ,
535
+ expect = expected_shape ))
531
536
raise ValueError (msg )
532
537
self ._update_ctx (result )
533
538
return self
@@ -771,7 +776,8 @@ def set_table_styles(self, table_styles):
771
776
772
777
@staticmethod
773
778
def _highlight_null (v , null_color ):
774
- return 'background-color: %s' % null_color if pd .isna (v ) else ''
779
+ return ('background-color: {color}' .format (color = null_color )
780
+ if pd .isna (v ) else '' )
775
781
776
782
def highlight_null (self , null_color = 'red' ):
777
783
"""
@@ -839,7 +845,8 @@ def _background_gradient(s, cmap='PuBu', low=0, high=0):
839
845
# https://github.com/matplotlib/matplotlib/issues/5427
840
846
normed = norm (s .values )
841
847
c = [colors .rgb2hex (x ) for x in plt .cm .get_cmap (cmap )(normed )]
842
- return ['background-color: %s' % color for color in c ]
848
+ return ['background-color: {color}' .format (color = color )
849
+ for color in c ]
843
850
844
851
def set_properties (self , subset = None , ** kwargs ):
845
852
"""
@@ -1182,6 +1189,6 @@ def _maybe_wrap_formatter(formatter):
1182
1189
elif callable (formatter ):
1183
1190
return formatter
1184
1191
else :
1185
- msg = "Expected a template string or callable, got {} instead" . format (
1186
- formatter )
1192
+ msg = ( "Expected a template string or callable, got {formatter} "
1193
+ "instead" . format ( formatter = formatter ) )
1187
1194
raise TypeError (msg )
0 commit comments