Skip to content

Commit 389a04b

Browse files
authored
_translate method restructure to simplify. (#40736)
Co-authored-by: JHM Darbyshire (MBP) <[email protected]>
1 parent 52b8459 commit 389a04b

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

pandas/io/formats/style.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,15 @@ def _translate(self):
375375
cellstyle_map: DefaultDict[Tuple[CSSPair, ...], List[str]] = defaultdict(list)
376376

377377
# copied attributes
378-
table_styles = self.table_styles or []
379-
caption = self.caption
380378
hidden_index = self.hidden_index
381379
hidden_columns = self.hidden_columns
382-
uuid = self.uuid
380+
381+
# construct render dict
382+
d = {
383+
"uuid": self.uuid,
384+
"table_styles": _format_table_styles(self.table_styles or []),
385+
"caption": self.caption,
386+
}
383387

384388
# for sparsifying a MultiIndex
385389
idx_lengths = _get_level_lengths(self.index)
@@ -468,6 +472,7 @@ def _translate(self):
468472
)
469473

470474
head.append(index_header_row)
475+
d.update({"head": head})
471476

472477
body = []
473478
for r, row_tup in enumerate(self.data.itertuples()):
@@ -517,11 +522,13 @@ def _translate(self):
517522
if props: # (), [] won't be in cellstyle_map, cellstyle respectively
518523
cellstyle_map[tuple(props)].append(f"row{r}_col{c}")
519524
body.append(row_es)
525+
d.update({"body": body})
520526

521527
cellstyle: List[Dict[str, Union[CSSList, List[str]]]] = [
522528
{"props": list(props), "selectors": selectors}
523529
for props, selectors in cellstyle_map.items()
524530
]
531+
d.update({"cellstyle": cellstyle})
525532

526533
table_attr = self.table_attributes
527534
use_mathjax = get_option("display.html.use_mathjax")
@@ -531,16 +538,8 @@ def _translate(self):
531538
table_attr = table_attr.replace('class="', 'class="tex2jax_ignore ')
532539
else:
533540
table_attr += ' class="tex2jax_ignore"'
541+
d.update({"table_attributes": table_attr})
534542

535-
d = {
536-
"head": head,
537-
"cellstyle": cellstyle,
538-
"body": body,
539-
"uuid": uuid,
540-
"table_styles": _format_table_styles(table_styles),
541-
"caption": caption,
542-
"table_attributes": table_attr,
543-
}
544543
if self.tooltips:
545544
d = self.tooltips._translate(self.data, self.uuid, d)
546545

0 commit comments

Comments
 (0)