Skip to content

Commit 43968df

Browse files
authored
PERF: Styler render improvement by limiting .join() (#39952)
1 parent 479a7f6 commit 43968df

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

pandas/io/formats/style.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def _translate(self):
466466
}
467467
colspan = col_lengths.get((r, c), 0)
468468
if colspan > 1:
469-
es["attributes"] = [f'colspan="{colspan}"']
469+
es["attributes"] = f'colspan="{colspan}"'
470470
row_es.append(es)
471471
head.append(row_es)
472472

@@ -517,7 +517,7 @@ def _translate(self):
517517
}
518518
rowspan = idx_lengths.get((c, r), 0)
519519
if rowspan > 1:
520-
es["attributes"] = [f'rowspan="{rowspan}"']
520+
es["attributes"] = f'rowspan="{rowspan}"'
521521
row_es.append(es)
522522

523523
for c, col in enumerate(self.data.columns):
@@ -529,6 +529,7 @@ def _translate(self):
529529
"value": value,
530530
"display_value": formatter(value),
531531
"is_visible": (c not in hidden_columns),
532+
"attributes": "",
532533
}
533534

534535
# only add an id if the cell has a style

pandas/io/formats/templates/html.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<tr>
4040
{% for c in r %}
4141
{% if c.is_visible != False %}
42-
<{{c.type}} class="{{c.class}}" {{c.attributes|join(" ")}}>{{c.value}}</{{c.type}}>
42+
<{{c.type}} class="{{c.class}}" {{c.attributes}}>{{c.value}}</{{c.type}}>
4343
{% endif %}
4444
{% endfor %}
4545
</tr>
@@ -56,7 +56,7 @@
5656
<tr>
5757
{% for c in r %}
5858
{% if c.is_visible != False %}
59-
<{{c.type}} {% if c.id is defined -%} id="T_{{uuid}}{{c.id}}" {%- endif %} class="{{c.class}}" {{c.attributes|join(" ")}}>{{c.display_value}}</{{c.type}}>
59+
<{{c.type}} {% if c.id is defined -%} id="T_{{uuid}}{{c.id}}" {%- endif %} class="{{c.class}}" {{c.attributes}}>{{c.display_value}}</{{c.type}}>
6060
{% endif %}
6161
{% endfor %}
6262
</tr>

pandas/tests/io/formats/test_style.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ def test_mi_sparse(self):
13231323
"display_value": "a",
13241324
"is_visible": True,
13251325
"type": "th",
1326-
"attributes": ['rowspan="2"'],
1326+
"attributes": 'rowspan="2"',
13271327
"class": "row_heading level0 row0",
13281328
"id": "level0_row0",
13291329
}

0 commit comments

Comments
 (0)