Skip to content

Commit 79d7159

Browse files
authored
CLN: reorganise/group variables for readability (#40368)
Co-authored-by: JHM Darbyshire (iMac) <[email protected]>
1 parent c52bf0a commit 79d7159

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

pandas/io/formats/style.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,6 @@ def _translate(self):
351351
Convert the DataFrame in `self.data` and the attrs from `_build_styles`
352352
into a dictionary of {head, body, uuid, cellstyle}.
353353
"""
354-
table_styles = self.table_styles or []
355-
caption = self.caption
356-
ctx = self.ctx
357-
hidden_index = self.hidden_index
358-
hidden_columns = self.hidden_columns
359-
uuid = self.uuid
360354
ROW_HEADING_CLASS = "row_heading"
361355
COL_HEADING_CLASS = "col_heading"
362356
INDEX_NAME_CLASS = "index_name"
@@ -365,12 +359,22 @@ def _translate(self):
365359
BLANK_CLASS = "blank"
366360
BLANK_VALUE = ""
367361

362+
# mapping variables
363+
ctx = self.ctx # td css styles from apply() and applymap()
364+
cell_context = self.cell_context # td css classes from set_td_classes()
365+
cellstyle_map: DefaultDict[Tuple[CSSPair, ...], List[str]] = defaultdict(list)
366+
367+
# copied attributes
368+
table_styles = self.table_styles or []
369+
caption = self.caption
370+
hidden_index = self.hidden_index
371+
hidden_columns = self.hidden_columns
372+
uuid = self.uuid
373+
368374
# for sparsifying a MultiIndex
369375
idx_lengths = _get_level_lengths(self.index)
370376
col_lengths = _get_level_lengths(self.columns, hidden_columns)
371377

372-
cell_context = self.cell_context
373-
374378
n_rlvls = self.data.index.nlevels
375379
n_clvls = self.data.columns.nlevels
376380
rlabels = self.data.index.tolist()
@@ -382,10 +386,7 @@ def _translate(self):
382386
clabels = [[x] for x in clabels]
383387
clabels = list(zip(*clabels))
384388

385-
cellstyle_map: DefaultDict[Tuple[CSSPair, ...], List[str]] = defaultdict(list)
386-
387389
head = []
388-
389390
for r in range(n_clvls):
390391
# Blank for Index columns...
391392
row_es = [

0 commit comments

Comments
 (0)