8000 PERF: Styler render improvement by limiting .join() by attack68 · Pull Request #39952 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

PERF: Styler render improvement by limiting .join() #39952

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 3 commits into from
Feb 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
performance improvement by limiting .join()
  • Loading branch information
attack68 committed Feb 21, 2021
commit 0b8ad47989c32fd44c32047f19090ca3f3be2a90
5 changes: 3 additions & 2 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def _translate(self):
}
colspan = col_lengths.get((r, c), 0)
if colspan > 1:
es["attributes"] = [f'colspan="{colspan}"']
es["attributes"] = f'colspan="{colspan}"'
row_es.append(es)
head.append(row_es)

Expand Down Expand Up @@ -517,7 +517,7 @@ def _translate(self):
}
rowspan = idx_lengths.get((c, r), 0)
if rowspan > 1:
es["attributes"] = [f'rowspan="{rowspan}"']
es["attributes"] = f'rowspan="{rowspan}"'
row_es.append(es)

for c, col in enumerate(self.data.columns):
Expand All @@ -529,6 +529,7 @@ def _translate(self):
"value": value,
"display_value": formatter(value),
"is_visible": (c not in hidden_columns),
"attributes": "",
}

# only add an id if the cell has a style
Expand Down
8 changes: 2 additions & 6 deletions pandas/io/formats/templates/html.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<tr>
{% for c in r %}
{% if c.is_visible != False %}
<{{c.type}} class="{{c.class}}" {{c.attributes|join(" ")}}>{{c.value}}</{{c.type}}>
<{{c.type}} class="{{c.class}}" {{c.attributes}}>{{c.value}}</{{c.type}}>
{% endif %}
{% endfor %}
</tr>
Expand All @@ -56,11 +56,7 @@
<tr>
{% for c in r %}
{% if c.is_visible != False %}
{% if c.type == 'th' %}
<th {% if c.id is defined -%} id="T_{{uuid}}{{c.id}}" {%- endif %} class="{{c.class}}" {{c.attributes|join(" ")}}>{{c.display_value}}</th>
{% else %}
<td {% if c.id is defined -%} id="T_{{uuid}}{{c.id}}" {%- endif %} class="{{c.class}}" >{{c.display_value}}</td>
{% endif %}
<{{c.type}} {% if c.id is defined -%} id="T_{{uuid}}{{c.id}}" {%- endif %} class="{{c.class}}" {{c.attributes}}>{{c.display_value}}</{{c.type}}>
{% endif %}
{% endfor %}
</tr>
Expand Down
0