Skip to content

Commit adc0c00

Browse files
committed
PERF: speed up rendering of styler (#19917)
- experimental, 10% further improvement by eliminating get_indexer call see #19917
1 parent 89b2d70 commit adc0c00

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

pandas/io/formats/style.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -561,15 +561,17 @@ def _update_ctx(self, attrs: DataFrame) -> None:
561561
Whitespace shouldn't matter and the final trailing ';' shouldn't
562562
matter.
563563
"""
564-
rows = [(row_label, v) for row_label, v in attrs.iterrows()]
565-
row_idx = self.index.get_indexer([x[0] for x in rows])
566-
for ii, row in enumerate(rows):
567-
i = row_idx[ii]
568-
cols = [(col_label, col) for col_label, col in row[1].items() if col]
569-
col_idx = self.columns.get_indexer([x[0] for x in cols])
570-
for jj, itm in enumerate(cols):
571-
j = col_idx[jj]
572-
for pair in itm[1].rstrip(";").split(";"):
564+
coli = {k: i for i, k in enumerate(self.columns)}
565+
rowi = {k: i for i, k in enumerate(self.index)}
566+
for jj in range(len(attrs.columns)):
567+
cn = attrs.columns[jj]
568+
j = coli[cn]
569+
for rn, c in attrs[[cn]].itertuples():
570+
if not c: continue
571+
c = c.rstrip(";")
572+
if not c: continue
573+
i = rowi[rn]
574+
for pair in c.split(";"):
573575
self.ctx[(i, j)].append(pair)
574576

575577
def _copy(self, deepcopy: bool = False) -> "Styler":

0 commit comments

Comments
 (0)