8000 REF: Use `Styler` implementation for `DataFrame.to_latex` by attack68 · Pull Request #47970 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

REF: Use Styler implementation for DataFrame.to_latex #47970

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 28 commits into from
Jan 19, 2023
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
02d7d0c
Base implementation
attack68 Aug 3, 2022
0c12f3a
Base implementation
attack68 Aug 3, 2022
d644065
test fix up
attack68 Aug 3, 2022
9dcd254
test fix up
attack68 Aug 3, 2022
cd05038
test fix up
attack68 Aug 4, 2022
c625610
doc change
attack68 Aug 4, 2022
493b884
doc change
attack68 Aug 4, 2022
41fa426
doc change
attack68 Aug 4, 2022
2d5c419
mypy fixes
attack68 Aug 5, 2022
c9c61c3
ivanov doc comment
attack68 Aug 9, 2022
ab6d3ec
ivanov doc comment
attack68 Aug 9, 2022
b913583
rhshadrach reduction
attack68 Aug 11, 2022
801bf42
Merge branch 'main' into to_latex_styler_implement
attack68 Nov 18, 2022
c803b73
change text from 1.5.0 to 2.0.0
attack68 Nov 18, 2022
df0b334
remove argument col_space and add whatsnew
attack68 Nov 18, 2022
f4e4bf7
Merge remote-tracking branch 'upstream/main' into to_latex_styler_imp…
attack68 Dec 7, 2022
9774341
mroeschke requests
attack68 Dec 7, 2022
10b5ec9
mroeschke requests
attack68 Dec 7, 2022 8000
2c42a4e
pylint fix
attack68 Dec 8, 2022
3c2f964
Merge remote-tracking branch 'upstream/main' into to_latex_styler_imp…
attack68 Jan 5, 2023
0b4144a
Whats new text improvements and description added
attack68 Jan 5, 2023
fae1b3f
Update doc/source/whatsnew/v2.0.0.rst
attack68 Jan 13, 2023
9c7d780
Update doc/source/whatsnew/v2.0.0.rst
attack68 Jan 13, 2023
c0bdc6a
remove trailing whitespace
attack68 Jan 16, 2023
c740279
remove trailing whitespace
attack68 Jan 16, 2023
9b6bba8
Merge remote-tracking branch 'upstream/main' into to_latex_styler_imp…
attack68 Jan 17, 2023
6b314cd
Whats new linting fixes
attack68 Jan 17, 2023
d6333cb
mroeschke requests
attack68 Jan 18, 2023
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
Prev Previous commit
Next Next commit
Base implementation
  • Loading branch information
attack68 committed Aug 9, 2022
commit 0c12f3ab942811acd1fb43c2e86263db0020f84b
20 changes: 13 additions & 7 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3380,6 +3380,9 @@ def to_latex(
if multirow is None:
multirow = config.get_option("display.latex.multirow")

if column_format is not None and not isinstance(column_format, str):
raise ValueError("`column_format` must be str or unicode")

# Refactor formatters/float_format/decimal/na_rep/escape to Styler structure
base_format_ = {
"na_rep": na_rep,
Expand Down Expand Up @@ -3421,8 +3424,9 @@ def _wrap(x, alt_format_):
formatters = functools.partial(_wrap, alt_format_=lambda v: v)
else:
formatters = None
format_index_ = [index_format_, column_format_]

hide, relabel = [], []
hide, relabel_index = [], []
if columns:
hide.append(
{
Expand All @@ -3433,7 +3437,8 @@ def _wrap(x, alt_format_):
if header is False:
hide.append({"axis": "columns"})
elif isinstance(header, (list, tuple)):
relabel = {"labels": header, "axis": "columns"}
relabel_index = {"labels": header, "axis": "columns"}
format_index_ = [index_format_] # column_format is overwritten

if index is False:
hide.append({"axis": "index"})
Expand Down Expand Up @@ -3462,9 +3467,9 @@ def _wrap(x, alt_format_):
return self._to_latex_via_styler(
buf,
hide=hide,
relabel=relabel,
relabel_index=relabel_index,
format={"formatter": formatters, **base_format_},
format_index=[index_format_, column_format_],
format_index=format_index_,
render_kwargs=render_kwargs,
)

Expand All @@ -3473,7 +3478,7 @@ def _to_latex_via_styler(
buf=None,
*,
hide: dict | list[dict] | None = None,
relabel: dict | list[dict] | None = None,
relabel_index: dict | list[dict] | None = None,
format: dict | list[dict] | None = None,
format_index: dict | list[dict] | None = None,
render_kwargs: dict = {},
Expand All @@ -3484,6 +3489,7 @@ def _to_latex_via_styler(
.. code-block:: python
styler = Styler(DataFrame)
styler.hide(**hide)
styler.relabel_index(**relabel_index)
styler.format(**format)
styler.format_index(**format_index)
styler.to_latex(buf=buf, **render_kwargs)
Expand All @@ -3494,7 +3500,7 @@ def _to_latex_via_styler(
hide : dict, list of dict
Keyword args to pass to the method call of ``Styler.hide``. If a list will
call the method numerous times.
relabel : dict, list of dict
relabel_index : dict, list of dict
Keyword args to pass to the method of ``Styler.relabel_index``. If a list
will call the method numerous times.
format : dict, list of dict
Expand Down Expand Up @@ -3540,7 +3546,7 @@ def _to_latex_via_styler(
self = cast("DataFrame", self)
styler = Styler(self, uuid="")

for kw_name in ["hide", "relabel", "format", "format_index"]:
for kw_name in ["hide", "relabel_index", "format", "format_index"]:
kw = vars()[kw_name]
if isinstance(kw, dict):
getattr(styler, kw_name)(**kw)
Expand Down
0