Skip to content

CLN: change jinja2 template name to template_html #40901

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 13, 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
2 changes: 1 addition & 1 deletion doc/source/reference/style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Styler properties
:toctree: api/

Styler.env
Styler.template
Styler.template_html
Styler.loader

Style application
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/style.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@
" Styler.loader, # the default\n",
" ])\n",
" )\n",
" template = env.get_template(\"myhtml.tpl\")"
" template_html = env.get_template(\"myhtml.tpl\")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ def from_custom_template(cls, searchpath, name):
# error: Invalid base class "cls"
class MyStyler(cls): # type:ignore[valid-type,misc]
env = jinja2.Environment(loader=loader)
template = env.get_template(name)
template_html = env.get_template(name)

return MyStyler

Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/style_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class StylerRenderer:

loader = jinja2.PackageLoader("pandas", "io/formats/templates")
env = jinja2.Environment(loader=loader, trim_blocks=True)
template = env.get_template("html.tpl")
template_html = env.get_template("html.tpl")

def __init__(
self,
Expand Down Expand Up @@ -143,7 +143,7 @@ def render(self, **kwargs) -> str:
# TODO: namespace all the pandas keys
d = self._translate()
d.update(kwargs)
return self.template.render(**d)
return self.template_html.render(**d)

def _compute(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/formats/style/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ def test_block_names():
"tr",
"after_rows",
}
result = set(Styler.template.blocks)
result = set(Styler.template_html.blocks)
assert result == expected


Expand All @@ -1386,6 +1386,6 @@ def test_from_custom_template(tmpdir):
result = Styler.from_custom_template(str(tmpdir.join("templates")), "myhtml.tpl")
assert issubclass(result, Styler)
assert result.env is not Styler.env
assert result.template is not Styler.template
assert result.template_html is not Styler.template_html
styler = result(DataFrame({"A": [1, 2]}))
assert styler.render()