-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Styler.to_latex(): conditional styling with native latex format #40422
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
Conversation
# Conflicts: # doc/source/whatsnew/v1.3.0.rst
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.
lgtm! Thanks for all the work here @attack68
cc @pandas-dev/pandas-core for any further reviews |
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.
reasonable. pls rebase. can you add some links from io.rst where we show to_latex now to styler / latex section (or add this to the styler section also). can be a followup (pls create an issue).
# Conflicts: # pandas/io/formats/style_render.py
Recent commits updated the @jreback pinging on green |
thanks @attack68 very nice! so basically the followons are
|
sure @attack68 can u add a follow up issue of things that we need to keep before depreciation |
Thanks for the great work, @attack68! I can't wait to use it in my dissertation! |
Enhancing Styler to allow LaTeX Input
also indirectly (by providing an alternative to DataFrame.to_latex):
to_latex
function #38328 (enh: adding highlighting options to to_latex function)This PR leverages the conditional rendering mechanics and unit tests in
Styler
to create a pure LaTeX version, i.e. a Styler that instead of CSS (attribute, value) tuples has LaTeX (command, options) tuples and renders directly to LaTeX with nested cellAn extension to this is provided in another PR which converts an HTML-CSS Styler to a LaTeX Styler, and then renders in LaTeX.
How is this achieved?
Internally:
latex
output.Styler._render_latex()
method is added to invoke the new template.Styler._translate_latex
method is added to make structural changes to the usual render dictd
to make it suitable for latex template.For Users:
Styler.to_latex()
method is introduced to give the user control.Comparison with DataFrame.to_latex()
Input Arguments
buf
,encoding
,position
,caption
,label
,sparsify
,column_format
position_float
,hrules
na_rep
,formatters
,float_format
,escape
,decimal
styler.format(...).to_latex(...)
fully replicates the functionality, and can be intermediately viewed in a Notebook.styler.format(..)...format(..).to_latex(...)
performs better formatting than a singleto_latex(..)
with formatting options could replicate..format
method rather than.to_latex
as downstream.columns
,index
,index_names
,header
,styler.hide_index().hide_columns()
can replicate the first three, the last seemed a bit unnecessary.sparsify {bool}
sparse_index
andsparse_columns
andmulticol_align {str}
andmultirow_align {str}
.sparsify {bool}
,multicolumn {bool}
,multirow {bool}
andmulticolumn_format {str}
bold_rows
(maybebold_labels
), andlongtable
.Performance
Suppose a user will never want to create a LaTeX bigger than (200,20) so we test that size:
df.style.format(":.2f".format).to_latex()61ms(this was improved by #41269)
Styler is broadly unaffected here by adding formatting methods, although
DataFrame.to_latex
is oddly much faster. Anyway the conclusion seems to be for this size frame and smaller performance is broadly the same, if not a bit better in Styler.Docs
Here are the rendered versions of the to_latex documentation
docs_to_latex.zip