-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
PERF: only output an html id if a style is applied #23019
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
Conversation
Hello @Moisan! Thanks for submitting the PR.
|
Codecov Report
@@ Coverage Diff @@
## master #23019 +/- ##
==========================================
+ Coverage 92.2% 92.2% +<.01%
==========================================
Files 169 169
Lines 50888 50892 +4
==========================================
+ Hits 46919 46923 +4
Misses 3969 3969
Continue to review full report at Codecov.
|
I think this should be a parameter given to the Styler constructor, not something that happens implicitly. |
pandas/io/formats/style.py
Outdated
@@ -65,6 +65,8 @@ class Styler(object): | |||
a unique identifier to avoid CSS collisions; generated automatically | |||
caption: str, default None | |||
caption to attach to the table | |||
all_ids: bool, default False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps cell_ids
is a bit more descriptive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the default should be True (backwards compatible)
pandas/io/formats/style.py
Outdated
@@ -65,6 +65,8 @@ class Styler(object): | |||
a unique identifier to avoid CSS collisions; generated automatically | |||
caption: str, default None | |||
caption to attach to the table | |||
all_ids: bool, default False | |||
if True, each cell will have an ``id`` attribute in their HTML tag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalize if
.
Could you include the form these take? I believe it's T_<uuid>_row<i>_col<j>
for values in the table.
pandas/io/formats/style.py
Outdated
"display_value": formatter(value), | ||
"is_visible": (c not in hidden_columns)} | ||
# only add an id if the cell has a style | ||
if self.all_ids or \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be if self.cell_ids
I think. We don't want a special case for the number of styles.
pandas/io/formats/templates/html.tpl
Outdated
<tr> | ||
{%- for c in r %} | ||
{%- if c.is_visible != False %} | ||
{%- if c.id: %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not that familiar with jinja, but presumably there's a way to deduplicate this a bit? I worry about these two cases drifting apart in the future.
</tr> | ||
{%- endblock tr %} | ||
{% block before_rows %}{% endblock before_rows %} | ||
{% for r in body %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does removing the opening -
change the whitespace? Or was it redundant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it was redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just removed a backslash.
Ping on green.
@TomAugspurger ping |
* PERF: only output an html id if a style is applied * Add a parameter to Styler constructor * Use cell_ids instead of all_ids and set default to True * remove backslash
git diff upstream/master -u -- "*.py" | flake8 --diff
Greatly reduces the amount of
id
tag in the cells by only assigning one when a style is applied to that cell. If that is the not correct approach for solving #20695, I am open to suggestions.Also I was confused by the
%-
tags to handle the whitespaces. Is there a reason the default options to handle whitespace are not used?