Skip to content

Commit 8425e04

Browse files
authored
PERF: halve render time in Styler with itertuples (#39972)
1 parent 161e365 commit 8425e04

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ Performance improvements
269269
- Performance improvement in :meth:`core.window.rolling.RollingGroupby.corr`, :meth:`core.window.expanding.ExpandingGroupby.corr`, :meth:`core.window.expanding.ExpandingGroupby.corr` and :meth:`core.window.expanding.ExpandingGroupby.cov` (:issue:`39591`)
270270
- Performance improvement in :func:`unique` for object data type (:issue:`37615`)
271271
- Performance improvement in :class:`core.window.rolling.ExpandingGroupby` aggregation methods (:issue:`39664`)
272+
- Performance improvement in :class:`Styler` where render times are more than 50% reduced (:issue:`39972` :issue:`39952`)
272273

273274
.. ---------------------------------------------------------------------------
274275

pandas/io/formats/style.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def _translate(self):
499499
head.append(index_header_row)
500500

501501
body = []
502-
for r, idx in enumerate(self.data.index):
502+
for r, row_tup in enumerate(self.data.itertuples()):
503503
row_es = []
504504
for c, value in enumerate(rlabels[r]):
505505
rid = [
@@ -520,10 +520,9 @@ def _translate(self):
520520
es["attributes"] = f'rowspan="{rowspan}"'
521521
row_es.append(es)
522522

523-
for c, col in enumerate(self.data.columns):
523+
for c, value in enumerate(row_tup[1:]):
524524
cs = [DATA_CLASS, f"row{r}", f"col{c}"]
525525
formatter = self._display_funcs[(r, c)]
526-
value = self.data.iloc[r, c]
527526
row_dict = {
528527
"type": "td",
529528
"value": value,

0 commit comments

Comments
 (0)