@@ -157,53 +157,40 @@ def __init__(
157
157
na_rep : Optional [str ] = None ,
158
158
uuid_len : int = 5 ,
159
159
):
160
- self .ctx : DefaultDict [Tuple [int , int ], List [str ]] = defaultdict (list )
161
- self ._todo : List [Tuple [Callable , Tuple , Dict ]] = []
162
-
160
+ # validate ordered args
163
161
if not isinstance (data , (pd .Series , pd .DataFrame )):
164
162
raise TypeError ("``data`` must be a Series or DataFrame" )
165
163
if data .ndim == 1 :
166
164
data = data .to_frame ()
167
165
if not data .index .is_unique or not data .columns .is_unique :
168
166
raise ValueError ("style is not supported for non-unique indices." )
169
-
170
- self .data = data
171
- self .index = data .index
172
- self .columns = data .columns
173
-
167
+ assert isinstance (data , DataFrame )
168
+ self .data : DataFrame = data
169
+ self .index : pd .Index = data .index
170
+ self .columns : pd .Index = data .columns
171
+ if precision is None :
172
+ precision = get_option ("display.precision" )
173
+ self .precision = precision
174
+ self .table_styles = table_styles
174
175
if not isinstance (uuid_len , int ) or not uuid_len >= 0 :
175
176
raise TypeError ("``uuid_len`` must be an integer in range [0, 32]." )
176
177
self .uuid_len = min (32 , uuid_len )
177
178
self .uuid = (uuid or uuid4 ().hex [: self .uuid_len ]) + "_"
178
- self .table_styles = table_styles
179
179
self .caption = caption
180
- if precision is None :
181
- precision = get_option ("display.precision" )
182
- self .precision = precision
183
180
self .table_attributes = table_attributes
184
- self .hidden_index = False
185
- self .hidden_columns : Sequence [int ] = []
186
181
self .cell_ids = cell_ids
187
182
self .na_rep = na_rep
188
183
189
- self .tooltips : Optional [_Tooltips ] = None
190
-
184
+ # assign additional default vars
185
+ self .hidden_index : bool = False
186
+ self .hidden_columns : Sequence [int ] = []
187
+ self .ctx : DefaultDict [Tuple [int , int ], List [str ]] = defaultdict (list )
191
188
self .cell_context : Dict [str , Any ] = {}
192
-
193
- # display_funcs maps (row, col) -> formatting function
194
-
195
- def default_display_func (x ):
196
- if self .na_rep is not None and pd .isna (x ):
197
- return self .na_rep
198
- elif is_float (x ):
199
- display_format = f"{ x :.{self .precision }f} "
200
- return display_format
201
- else :
202
- return x
203
-
204
- self ._display_funcs : DefaultDict [
189
+ self ._todo : List [Tuple [Callable , Tuple , Dict ]] = []
190
+ self .tooltips : Optional [_Tooltips ] = None
191
+ self ._display_funcs : DefaultDict [ # maps (row, col) -> formatting function
205
192
Tuple [int , int ], Callable [[Any ], str ]
206
- ] = defaultdict (lambda : default_display_func )
193
+ ] = defaultdict (lambda : self . _default_display_func )
207
194
208
195
def _repr_html_ (self ) -> str :
209
196
"""
@@ -224,6 +211,15 @@ def _init_tooltips(self):
224
211
if self .tooltips is None :
225
212
self .tooltips = _Tooltips ()
226
213
214
+ def _default_display_func (self , x ):
215
+ if self .na_rep is not None and pd .isna (x ):
216
+ return self .na_rep
217
+ elif is_float (x ):
218
+ display_format = f"{ x :.{self .precision }f} "
219
+ return display_format
220
+ else :
221
+ return x
222
+
227
223
def set_tooltips (self , ttips : DataFrame ) -> Styler :
228
224
"""
229
225
Add string based tooltips that will appear in the `Styler` HTML result. These
0 commit comments