-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
REF: type change escape
in Styler.format
to str to allow "html" and "latex"
#41619
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can u move this to the to_html or to_latex method instead?
no, because it's mixed in as part of the formatting routine, and the idea is that DataFrames should be formatted before calling
if escape is added to the render method then what about expanding the keyword inputs to:
? |
yeah the last is fine i guess but is there a way to just escape things that work in both html and latex? |
not currently because of operation order. the format method is ignorant of how the styler will ultimately be rendered, and it yields a one-arg-callable for each data element decoupled from render method. if it becomes dependent it introduces operation order complexity and possible performance degradation. (and of course html and latex have different escaped chars) will propose the former alternative and can review again. |
escape
escape_html
in Styler.format
escape
in Styler.format
to str to allow "html" and "latex"
@jreback it turns out some of the escaped characters overlap so it is impossible to escape 'html' and 'latex' simultaneously. I've edited this PR to allow |
@@ -1187,3 +1207,38 @@ def _parse_latex_options_strip(value: str | int | float, arg: str) -> str: | |||
For example: 'red /* --wrap */ ' --> 'red' | |||
""" | |||
return str(value).replace(arg, "").replace("/*", "").replace("*/", "").strip() | |||
|
|||
|
|||
def _escape_latex(s): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is eacape_html?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imported from markupsafe which is a jinja2 dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a very simple function, can write here instead of having dependency to markupsafe if preferred?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh its fine, just not completely obvious where it is (but its already there so its fine)
@@ -1187,3 +1207,38 @@ def _parse_latex_options_strip(value: str | int | float, arg: str) -> str: | |||
For example: 'red /* --wrap */ ' --> 'red' | |||
""" | |||
return str(value).replace(arg, "").replace("/*", "").replace("*/", "").strip() | |||
|
|||
|
|||
def _escape_latex(s): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh its fine, just not completely obvious where it is (but its already there so its fine)
Change is made ahead of 1.3.0 to pre-empt the addition of
escape_latex
and to avoid name ambiguity.This is not user facing since the
escape
kwarg was added for 1.3.0 only recently.Alternative
If instead of having separate
escape_html
andescape_latex
kwargs we could haveescape={None, 'html', 'latex'}
since it is likely they will be used exclusively??