Skip to content

Commit 8de6276

Browse files
authored
rename the render process in Styler (#41123)
Co-authored-by: JHM Darbyshire (iMac) <[email protected]>
1 parent ee18cb5 commit 8de6276

File tree

3 files changed

+47
-40
lines changed

3 files changed

+47
-40
lines changed

asv_bench/benchmarks/io/style.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ def setup(self, cols, rows):
1717

1818
def time_apply_render(self, cols, rows):
1919
self._style_apply()
20-
self.st.render()
20+
self.st._render_html()
2121

2222
def peakmem_apply_render(self, cols, rows):
2323
self._style_apply()
24-
self.st.render()
24+
self.st._render_html()
2525

2626
def time_classes_render(self, cols, rows):
2727
self._style_classes()
28-
self.st.render()
28+
self.st._render_html()
2929

3030
def peakmem_classes_render(self, cols, rows):
3131
self._style_classes()
32-
self.st.render()
32+
self.st._render_html()
3333

3434
def _style_apply(self):
3535
def _apply_func(s):

pandas/io/formats/style.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,46 @@ def _repr_html_(self) -> str:
200200
"""
201201
Hooks into Jupyter notebook rich display system.
202202
"""
203-
return self.render()
203+
return self._render_html()
204+
205+
def render(self, **kwargs) -> str:
206+
"""
207+
Render the ``Styler`` including all applied styles to HTML.
208+
209+
Parameters
210+
----------
211+
**kwargs
212+
Any additional keyword arguments are passed
213+
through to ``self.template.render``.
214+
This is useful when you need to provide
215+
additional variables for a custom template.
216+
217+
Returns
218+
-------
219+
rendered : str
220+
The rendered HTML.
221+
222+
Notes
223+
-----
224+
Styler objects have defined the ``_repr_html_`` method
225+
which automatically calls ``self.render()`` when it's the
226+
last item in a Notebook cell. When calling ``Styler.render()``
227+
directly, wrap the result in ``IPython.display.HTML`` to view
228+
the rendered HTML in the notebook.
229+
230+
Pandas uses the following keys in render. Arguments passed
231+
in ``**kwargs`` take precedence, so think carefully if you want
232+
to override them:
233+
234+
* head
235+
* cellstyle
236+
* body
237+
* uuid
238+
* table_styles
239+
* caption
240+
* table_attributes
241+
"""
242+
return self._render_html(**kwargs)
204243

205244
def set_tooltips(
206245
self,

pandas/io/formats/style_render.py

+3-35
Original file line numberDiff line numberDiff line change
@@ -102,42 +102,10 @@ def __init__(
102102
tuple[int, int], Callable[[Any], str]
103103
] = defaultdict(lambda: partial(_default_formatter, precision=def_precision))
104104

105-
def render(self, **kwargs) -> str:
105+
def _render_html(self, **kwargs) -> str:
106106
"""
107-
Render the ``Styler`` including all applied styles to HTML.
108-
109-
Parameters
110-
----------
111-
**kwargs
112-
Any additional keyword arguments are passed
113-
through to ``self.template.render``.
114-
This is useful when you need to provide
115-
additional variables for a custom template.
116-
117-
Returns
118-
-------
119-
rendered : str
120-
The rendered HTML.
121-
122-
Notes
123-
-----
124-
Styler objects have defined the ``_repr_html_`` method
125-
which automatically calls ``self.render()`` when it's the
126-
last item in a Notebook cell. When calling ``Styler.render()``
127-
directly, wrap the result in ``IPython.display.HTML`` to view
128-
the rendered HTML in the notebook.
129-
130-
Pandas uses the following keys in render. Arguments passed
131-
in ``**kwargs`` take precedence, so think carefully if you want
132-
to override them:
133-
134-
* head
135-
* cellstyle
136-
* body
137-
* uuid
138-
* table_styles
139-
* caption
140-
* table_attributes
107+
Renders the ``Styler`` including all applied styles to HTML.
108+
Generates a dict with necessary kwargs passed to jinja2 template.
141109
"""
142110
self._compute()
143111
# TODO: namespace all the pandas keys

0 commit comments

Comments
 (0)