Skip to content

CLN: rename the render process in Styler #41123

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 2 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions asv_bench/benchmarks/io/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ def setup(self, cols, rows):

def time_apply_render(self, cols, rows):
self._style_apply()
self.st.render()
self.st._render_html()

def peakmem_apply_render(self, cols, rows):
self._style_apply()
self.st.render()
self.st._render_html()

def time_classes_render(self, cols, rows):
self._style_classes()
self.st.render()
self.st._render_html()

def peakmem_classes_render(self, cols, rows):
self._style_classes()
self.st.render()
self.st._render_html()

def _style_apply(self):
def _apply_func(s):
Expand Down
41 changes: 40 additions & 1 deletion pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,46 @@ def _repr_html_(self) -> str:
"""
Hooks into Jupyter notebook rich display system.
"""
return self.render()
return self._render_html()

def render(self, **kwargs) -> str:
"""
Render the ``Styler`` including all applied styles to HTML.

Parameters
----------
**kwargs
Any additional keyword arguments are passed
through to ``self.template.render``.
This is useful when you need to provide
additional variables for a custom template.

Returns
-------
rendered : str
The rendered HTML.

Notes
-----
Styler objects have defined the ``_repr_html_`` method
which automatically calls ``self.render()`` when it's the
last item in a Notebook cell. When calling ``Styler.render()``
directly, wrap the result in ``IPython.display.HTML`` to view
the rendered HTML in the notebook.

Pandas uses the following keys in render. Arguments passed
in ``**kwargs`` take precedence, so think carefully if you want
to override them:

* head
* cellstyle
* body
* uuid
* table_styles
* caption
* table_attributes
"""
return self._render_html(**kwargs)

def set_tooltips(
self,
Expand Down
38 changes: 3 additions & 35 deletions pandas/io/formats/style_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,42 +102,10 @@ def __init__(
tuple[int, int], Callable[[Any], str]
] = defaultdict(lambda: partial(_default_formatter, precision=def_precision))

def render(self, **kwargs) -> str:
def _render_html(self, **kwargs) -> str:
"""
Render the ``Styler`` including all applied styles to HTML.

Parameters
----------
**kwargs
Any additional keyword arguments are passed
through to ``self.template.render``.
This is useful when you need to provide
additional variables for a custom template.

Returns
-------
rendered : str
The rendered HTML.

Notes
-----
Styler objects have defined the ``_repr_html_`` method
which automatically calls ``self.render()`` when it's the
last item in a Notebook cell. When calling ``Styler.render()``
directly, wrap the result in ``IPython.display.HTML`` to view
the rendered HTML in the notebook.

Pandas uses the following keys in render. Arguments passed
in ``**kwargs`` take precedence, so think carefully if you want
to override them:

* head
* cellstyle
* body
* uuid
* table_styles
* caption
* table_attributes
Renders the ``Styler`` including all applied styles to HTML.
Generates a dict with necessary kwargs passed to jinja2 template.
"""
self._compute()
# TODO: namespace all the pandas keys
Expand Down