Skip to content

CLN: refactor Styler._translate into composite translate functions #40898

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 15 commits into from
Apr 13, 2021

Conversation

attack68
Copy link
Contributor

This composites Styler._translate() into:

def _translate():
    ...
    self._translate_header()
    ...
    self._translate_body()
    ...

where the _translate_header() and _translate_body() methods are given some documentation explaining what they are building. The code is not fundamentally changed, but variable names are renamed to add clarity to match the documentation and loop comprehensions replace for loops where possible.

Some tests are minimally altered since the generic _element method now returns more dict keys for some elements.

@jreback
Copy link
Contributor

jreback commented Apr 12, 2021

is there a _translate_footer() (maybe currently unused)?

@jreback jreback added Styler conditional formatting using DataFrame.style Refactor Internal refactoring of code labels Apr 12, 2021
@attack68
Copy link
Contributor Author

attack68 commented Apr 12, 2021

is there a _translate_footer() (maybe currently unused)?

No because the html element <tfoot> is not used in the jinja2 templates.

It might be useful for easily adding styling of a totals row for example in the future, albeit can be done currently, its just not that easy.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good a question

"class": "blank col0",
"type": "th",
"value": self.blank_value,
"is_visible": True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so these are just additional attributes that currently are defaulted?

Copy link
Contributor Author

@attack68 attack68 Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the new _element function outputs 5 dict keys by default for each cell.

Previously almost all cells needed these 5 and a few only had 3 keys like column header cells. There is no harm adding them, and actually might make future dev easier, for example a hide_headers() method to complement the hide_index method can hook into the is_visible additional key.

@jreback jreback added this to the 1.3 milestone Apr 13, 2021
@jreback jreback merged commit 3eaa712 into pandas-dev:master Apr 13, 2021
@jreback
Copy link
Contributor

jreback commented Apr 13, 2021

thanks @attack68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Internal refactoring of code Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants