Skip to content

Commit

Permalink
rename the render process in Styler (pandas-dev#41123)
Browse files Browse the repository at this point in the history
Co-authored-by: JHM Darbyshire (iMac) <[email protected]>
  • Loading branch information
attack68 and attack68 authored Apr 26, 2021
1 parent ee18cb5 commit 8de6276
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 40 deletions.
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

0 comments on commit 8de6276

Please sign in to comment.