@@ -230,7 +230,7 @@ def format_attr(pair):
230230 # ... except maybe the last for columns.names
231231 name = self .data .columns .names [r ]
232232 cs = [BLANK_CLASS if name is None else INDEX_NAME_CLASS ,
233- "level%s" % r ]
233+ "level{lvl}" . format ( lvl = r ) ]
234234 name = BLANK_VALUE if name is None else name
235235 row_es .append ({"type" : "th" ,
236236 "value" : name ,
@@ -240,7 +240,8 @@ def format_attr(pair):
240240
241241 if clabels :
242242 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 )]
244245 cs .extend (cell_context .get (
245246 "col_headings" , {}).get (r , {}).get (c , []))
246247 es = {
@@ -264,7 +265,7 @@ def format_attr(pair):
264265
265266 for c , name in enumerate (self .data .index .names ):
266267 cs = [INDEX_NAME_CLASS ,
267- "level%s" % c ]
268+ "level{lvl}" . format ( lvl = c ) ]
268269 name = '' if name is None else name
269270 index_header_row .append ({"type" : "th" , "value" : name ,
270271 "class" : " " .join (cs )})
@@ -281,7 +282,8 @@ def format_attr(pair):
281282 for r , idx in enumerate (self .data .index ):
282283 row_es = []
283284 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 )]
285287 es = {
286288 "type" : "th" ,
287289 "is_visible" : _is_visible (r , c , idx_lengths ),
@@ -298,7 +300,8 @@ def format_attr(pair):
298300 row_es .append (es )
299301
300302 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 )]
302305 cs .extend (cell_context .get ("data" , {}).get (r , {}).get (c , []))
303306 formatter = self ._display_funcs [(r , c )]
304307 value = self .data .iloc [r , c ]
@@ -317,7 +320,8 @@ def format_attr(pair):
317320 else :
318321 props .append (['' , '' ])
319322 cellstyle .append ({'props' : props ,
320- 'selector' : "row%s_col%s" % (r , c )})
323+ 'selector' : "row{row}_col{col}"
324+ .format (row = r , col = c )})
321325 body .append (row_es )
322326
323327 return dict (head = head , cellstyle = cellstyle , body = body , uuid = uuid ,
@@ -512,22 +516,23 @@ def _apply(self, func, axis=0, subset=None, **kwargs):
512516 result = func (data , ** kwargs )
513517 if not isinstance (result , pd .DataFrame ):
514518 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 ))
517522 if not (result .index .equals (data .index ) and
518523 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 ))
521526 raise ValueError (msg )
522527
523528 result_shape = result .shape
524529 expected_shape = self .data .loc [subset ].shape
525530 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 ))
531536 raise ValueError (msg )
532537 self ._update_ctx (result )
533538 return self
@@ -771,7 +776,8 @@ def set_table_styles(self, table_styles):
771776
772777 @staticmethod
773778 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 '' )
775781
776782 def highlight_null (self , null_color = 'red' ):
777783 """
@@ -839,7 +845,8 @@ def _background_gradient(s, cmap='PuBu', low=0, high=0):
839845 # https://github.com/matplotlib/matplotlib/issues/5427
840846 normed = norm (s .values )
841847 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 ]
843850
844851 def set_properties (self , subset = None , ** kwargs ):
845852 """
@@ -1182,6 +1189,6 @@ def _maybe_wrap_formatter(formatter):
11821189 elif callable (formatter ):
11831190 return formatter
11841191 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 ) )
11871194 raise TypeError (msg )
0 commit comments