@@ -3227,7 +3227,6 @@ def to_latex(
3227
3227
def to_latex (
3228
3228
self ,
3229
3229
buf : FilePath | WriteBuffer [str ] | None = None ,
3230
- * ,
3231
3230
columns : Sequence [Hashable ] | None = None ,
3232
3231
col_space : ColspaceArgType | None = None ,
3233
3232
header : bool_t | Sequence [str ] = True ,
@@ -3460,7 +3459,7 @@ def to_latex(
3460
3459
column_format_ : dict [str , Any ] = {"axis" : 1 , ** base_format_ }
3461
3460
3462
3461
if isinstance (float_format , str ):
3463
- float_format_ = lambda x : float_format % x
3462
+ float_format_ : Callable | None = lambda x : float_format % x
3464
3463
else :
3465
3464
float_format_ = float_format
3466
3465
@@ -3470,8 +3469,9 @@ def _wrap(x, alt_format_):
3470
3469
else :
3471
3470
return alt_format_ (x )
3472
3471
3472
+ formatters_ : list | tuple | dict | Callable | None = None
3473
3473
if isinstance (formatters , list ):
3474
- formatters = {
3474
+ formatters_ = {
3475
3475
c : functools .partial (_wrap , alt_format_ = formatters [i ])
3476
3476
for i , c in enumerate (self .columns )
3477
3477
}
@@ -3483,36 +3483,36 @@ def _wrap(x, alt_format_):
3483
3483
if column_formatter is not None :
3484
3484
column_format_ .update ({"formatter" : column_formatter })
3485
3485
3486
+ formatters_ = formatters
3486
3487
float_columns = self .select_dtypes (include = "float" ).columns
3487
3488
for col in [c for c in float_columns if c not in formatters .keys ()]:
3488
- formatters .update ({col : float_format_ })
3489
+ formatters_ .update ({col : float_format_ })
3489
3490
elif formatters is None and float_format is not None :
3490
- formatters = functools .partial (_wrap , alt_format_ = lambda v : v )
3491
- else :
3492
- formatters = None
3491
+ formatters_ = functools .partial (_wrap , alt_format_ = lambda v : v )
3493
3492
format_index_ = [index_format_ , column_format_ ]
3494
3493
3495
3494
# Deal with hiding indexes and relabelling column names
3496
- hide , relabel_index = [], []
3495
+ hide_ : list [dict ] = []
3496
+ relabel_index_ : list [dict ] = []
3497
3497
if columns :
3498
- hide .append (
3498
+ hide_ .append (
3499
3499
{
3500
3500
"subset" : [c for c in self .columns if c not in columns ],
3501
3501
"axis" : "columns" ,
3502
3502
}
3503
3503
)
3504
3504
if header is False :
3505
- hide .append ({"axis" : "columns" })
3505
+ hide_ .append ({"axis" : "columns" })
3506
3506
elif isinstance (header , (list , tuple )):
3507
- relabel_index = {"labels" : header , "axis" : "columns" }
3507
+ relabel_index_ . append ( {"labels" : header , "axis" : "columns" })
3508
3508
format_index_ = [index_format_ ] # column_format is overwritten
3509
3509
3510
3510
if index is False :
3511
- hide .append ({"axis" : "index" })
3511
+ hide_ .append ({"axis" : "index" })
3512
3512
if index_names is False :
3513
- hide .append ({"names" : True , "axis" : "index" })
3513
+ hide_ .append ({"names" : True , "axis" : "index" })
3514
3514
3515
- render_kwargs = {
3515
+ render_kwargs_ = {
3516
3516
"hrules" : True ,
3517
3517
"sparse_index" : sparsify ,
3518
3518
"sparse_columns" : sparsify ,
@@ -3533,11 +3533,11 @@ def _wrap(x, alt_format_):
3533
3533
3534
3534
return self ._to_latex_via_styler (
3535
3535
buf ,
3536
- hide = hide ,
3537
- relabel_index = relabel_index ,
3538
- format = {"formatter" : formatters , ** base_format_ },
3536
+ hide = hide_ ,
3537
+ relabel_index = relabel_index_ ,
3538
+ format = {"formatter" : formatters_ , ** base_format_ },
3539
3539
format_index = format_index_ ,
3540
- render_kwargs = render_kwargs ,
3540
+ render_kwargs = render_kwargs_ ,
3541
3541
)
3542
3542
3543
3543
def _to_latex_via_styler (
0 commit comments