Skip to content

CLN: minor changes to _translate to simplify and setup for other chgs. #40736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,15 @@ def _translate(self):
cellstyle_map: DefaultDict[Tuple[CSSPair, ...], List[str]] = defaultdict(list)

# copied attributes
table_styles = self.table_styles or []
caption = self.caption
hidden_index = self.hidden_index
hidden_columns = self.hidden_columns
uuid = self.uuid

# construct render dict
d = {
"uuid": self.uuid,
"table_styles": _format_table_styles(self.table_styles or []),
"caption": self.caption,
}

# for sparsifying a MultiIndex
idx_lengths = _get_level_lengths(self.index)
Expand Down Expand Up @@ -468,6 +472,7 @@ def _translate(self):
)

head.append(index_header_row)
d.update({"head": head})

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

cellstyle: List[Dict[str, Union[CSSList, List[str]]]] = [
{"props": list(props), "selectors": selectors}
for props, selectors in cellstyle_map.items()
]
d.update({"cellstyle": cellstyle})

table_attr = self.table_attributes
use_mathjax = get_option("display.html.use_mathjax")
Expand All @@ -531,16 +538,8 @@ def _translate(self):
table_attr = table_attr.replace('class="', 'class="tex2jax_ignore ')
else:
table_attr += ' class="tex2jax_ignore"'
d.update({"table_attributes": table_attr})

d = {
"head": head,
"cellstyle": cellstyle,
"body": body,
"uuid": uuid,
"table_styles": _format_table_styles(table_styles),
"caption": caption,
"table_attributes": table_attr,
}
if self.tooltips:
d = self.tooltips._translate(self.data, self.uuid, d)

Expand Down