@@ -54,8 +54,31 @@ def __init__(
54
54
self .border = border
55
55
self .table_id = self .fmt .table_id
56
56
self .render_links = self .fmt .render_links
57
- if isinstance (self .fmt .col_space , int ):
58
- self .fmt .col_space = "{colspace}px" .format (colspace = self .fmt .col_space )
57
+ if isinstance (self .fmt .col_space , dict ):
58
+ self .fmt .col_space = {
59
+ column : self ._convert_to_px (value )
60
+ for column , value in self .fmt .col_space .items ()
61
+ }
62
+ elif isinstance (self .fmt .col_space , list ):
63
+ self .fmt .col_space = dict (
64
+ zip (
65
+ self .frame .columns ,
66
+ [self ._convert_to_px (value ) for value in self .fmt .col_space ],
67
+ )
68
+ )
69
+ elif isinstance (self .fmt .col_space , int ) or isinstance (self .fmt .col_space , str ):
70
+ self .fmt .col_space = {
71
+ column : self ._convert_to_px (self .fmt .col_space )
72
+ for column in self .frame .columns
73
+ }
74
+ else :
75
+ self .fmt .col_space = {}
76
+
77
+ @staticmethod
78
+ def _convert_to_px (value : Union [int , str ]) -> str :
79
+ if isinstance (value , int ):
80
+ return f"{ value } px"
81
+ return value
59
82
60
83
@property
61
84
def show_row_idx_names (self ) -> bool :
@@ -121,9 +144,11 @@ def write_th(
121
144
-------
122
145
A written <th> cell.
123
146
"""
124
- if header and self .fmt .col_space is not None :
147
+ if header and self .fmt .col_space is not None and self . fmt . col_space . get ( s ) :
125
148
tags = tags or ""
126
- tags += 'style="min-width: {colspace};"' .format (colspace = self .fmt .col_space )
149
+ tags += 'style="min-width: {colspace};"' .format (
150
+ colspace = self .fmt .col_space .get (s )
151
+ )
127
152
128
153
self ._write_cell (s , kind = "th" , indent = indent , tags = tags )
129
154
0 commit comments