Skip to content
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

DEPR: LatexFormatter in DataFrame.to_latex in favour of Styler #41649

Closed
15 of 17 tasks
attack68 opened this issue May 24, 2021 · 7 comments
Closed
15 of 17 tasks

DEPR: LatexFormatter in DataFrame.to_latex in favour of Styler #41649

attack68 opened this issue May 24, 2021 · 7 comments
Labels
Deprecate Functionality to remove in pandas IO LaTeX to_latex Master Tracker High level tracker for similar issues Styler conditional formatting using DataFrame.style

Comments

@attack68
Copy link
Contributor

attack68 commented May 24, 2021

The tracker of items needed to do before deprecating DataFrame.to_latex().

Removed Keyword Args

col_space: removed since Styler.to_latex() does not necessarily produce display values of equal length, (this is a console display only arg)
sparsify: replaced by alternative kwargs sparse_index and sparse_columns
multicolumn, multicolumn_format, multirow: replaced by alternative kwargs multirow_align multicol_align
formatters float_format : replaced by the superior df.style.format(...) args

@attack68 attack68 added Deprecate Functionality to remove in pandas Master Tracker High level tracker for similar issues IO LaTeX to_latex Styler conditional formatting using DataFrame.style labels May 24, 2021
@ivanovmg
Copy link
Member

What about backward compatibility?
If I understand correctly we would need to delegate DataFrame.to_latex to Styler.to_latex() and issue a FutureWarning.
Should this be added to a checklist as well?

@attack68
Copy link
Contributor Author

What about backward compatibility?
If I understand correctly we would need to delegate DataFrame.to_latex to Styler.to_latex() and issue a FutureWarning.
Should this be added to a checklist as well?

Don't deprecations by definition warn of failing backwards compatibility in a future version? For 1.x is it enough to just warn that DataFrame methods will not be developed in future and will eventually be removed (or refactored), albeit they remain in place, as is, for those versions?

I'm trying hard to try and avoid the case where the existing keyword signature of DataFrame.to_html and DataFrame.to_latex must be maintained/replicated or squeezed into Stylers format, for the reason that some of them are bad arguments, and subjectively the new format is decoupled (more maintainable) and more flexible, and consistent from format to format (html, excel, latex).

@jreback
Copy link
Contributor

jreback commented May 25, 2021

we can straight depreciate DataFrame.to_latex w/o changing the implementation at all

sure if u can totally do everything in styler.to_latex that would be great but it's likely not a big deal to implement things later / drop features if needed

@rhshadrach
Copy link
Member

@attack68 - similar to to_html, I would be in favor of keeping DataFrame.to_latex as a wrapper around Styler.to_latex. It sounds like the current arguments on DataFrame.to_latex make this difficult / undesirable; is it preferable to deprecate DataFrame.to_latex args in favor of the Styler signature rather than removing DataFrame.to_latex altogether?

@attack68
Copy link
Contributor Author

@rhshadrach as far as I can tell this is the current status:

DataFrame.LatexFormatter has not been updated in quite some time, on the other hand Styler.to_latex has the ability to completely replicate all the options available via LatexFormatter plus a great many features besides.

DataFrame.to_latex, keeping its arguments signature and and its tests, can be effectively recoded to utilise Styler.to_latex, with the exception of one feature: relabelling headers, which came under #45288.

I can see one of 3 possible evolutions for DataFrame.to_latex, in pandas 2.0:

  1. Keep it, and its arguments signature, as is but recode it to use Styler and eliminate the LatexFormatter. The arguments signature will effectively be frozen since it is not consistent with Styler and any further development would have to be specifically linked to Styler which will be pretty horrible to maintain.

  2. Remove all arguments and just output a basic Latex table, effectively Styler.to_latex with no args. Redirect users to use Styler for more control. Easiest to maintain and document.

  3. Provide an api which effectively calls the relevant Styler methods in a chain an outputs the more featured Styler.to_latex. No sure the real benefit of adding this syntactic sugar, Why not just do 2) ?

@rhshadrach
Copy link
Member

No sure the real benefit of adding this syntactic sugar, Why not just do 2) ?

Like most syntactic sugar, it's convenient. I would also hazard not many users are familiar with the Styler. Having a DataFrame method gives it visibility, where we can point to the Styler in the API docs for users that want more features.

I'm +1 on 3.

@attack68 attack68 changed the title DEPR: DataFrame.to_latex in favour of Styler.to_latex DEPR: LatexFormatter in DataFrame.to_latex in favour of Styler Aug 4, 2022
@attack68
Copy link
Contributor Author

closing as completed via #47970

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas IO LaTeX to_latex Master Tracker High level tracker for similar issues Styler conditional formatting using DataFrame.style
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants