Skip to content

CLN: create core Styler rendering functions and subclass conditional styling applications #40745

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

Conversation

attack68
Copy link
Contributor

@attack68 attack68 commented Apr 2, 2021

Here is a first draft at splitting up style.py, ahead of adding new LaTeX functionality

Key Points

  • All rendering and formatting methods moved to style_render.py:
class StylerRenderer:
    jinja2_loader
    def render()
    def format()
    def _translate()
    def _compute()

+ their module level helper functions
  • style.py maintains all the conditional application methods and the utility methods and is subclass:
class Styler(StylerRenderer):
    ...

All methods copied, no changes made, other than deprivatizing shared method names.

Technically this now works:

df = pd.DataFrame([['a   b', 'c  v']])
from pandas.io.formats.style_render import StylerRenderer
StylerRenderer(df).format(str.upper).render()

clabels = [[x] for x in clabels]
clabels = list(zip(*clabels))

head = []
Copy link
Contributor

Choose a reason for hiding this comment

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

i would make this a composite method that calls: _translate_head, _translate_body, _translate_footer, but can do in followons

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes is a good idea: but i'm trying hard to adopt your former advice of targeted smaller PRs! :)
(this is also why i submitted that other small PR yesterday because this is ultimately the idea)

Copy link
Contributor

Choose a reason for hiding this comment

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

that's a good idea. its totally ok to take my suggestions as followons. would rather merge things that are partial to make the workflow easier.


return self

def _repr_html_(self) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't these 2 methods be in the subclasses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

arguably yes. they weren't, and then I put them in last. no strong opinion, so i'll make changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are talking about _repr_html_ and to_excel, i assume.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

@jreback jreback added Refactor Internal refactoring of code Code Style Code style, linting, code_checks labels Apr 2, 2021
@jreback
Copy link
Contributor

jreback commented Apr 2, 2021

cool I think need to rebase (do this pretty much every time when you push)

@attack68
Copy link
Contributor Author

@jreback this is green and ready to go if you approve.

@jreback jreback added this to the 1.3 milestone Apr 12, 2021
@jreback jreback merged commit 4aeb8f2 into pandas-dev:master Apr 12, 2021
@jreback
Copy link
Contributor

jreback commented Apr 12, 2021

thanks @attack68

@attack68 attack68 deleted the basic_subclassing_styler branch April 12, 2021 15:00
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants