Skip to content

REF: DataFrame.to_latex directs to Styler.to_latex #41648

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

Closed
wants to merge 121 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
c586522
add future warning
attack68 May 24, 2021
74d7ff2
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 May 26, 2021
ece5987
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 May 29, 2021
4a9b076
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Jun 1, 2021
5a97aad
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Jun 15, 2021
edd91ec
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Jun 20, 2021
8821026
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Jun 29, 2021
e03e014
build format_index mechanics
attack68 Aug 16, 2021
bb9b5b2
Merge remote-tracking branch 'upstream/master' into styler_format_index
attack68 Aug 17, 2021
fb86279
test index formatter display_value, and clearing
attack68 Aug 17, 2021
846e5a2
prelim doc string
attack68 Aug 17, 2021
9e995e1
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Aug 18, 2021
7e9400a
format_index docs
attack68 Aug 18, 2021
9c63ab8
Merge remote-tracking branch 'upstream/master' into styler_format_index
attack68 Aug 19, 2021
87a6c88
refactor for perf
attack68 Aug 19, 2021
9c969ad
add test
attack68 Aug 20, 2021
26f3906
add tests: escape
attack68 Aug 21, 2021
ec40418
add tests: escape na_rep
attack68 Aug 21, 2021
0de5397
add tests: raises
attack68 Aug 21, 2021
6fe8285
test decimal and thousands
attack68 Aug 21, 2021
6b61e31
test precision
attack68 Aug 21, 2021
6eaa933
Merge remote-tracking branch 'upstream/master' into styler_format_index
attack68 Aug 30, 2021
666e460
whats new
attack68 Aug 30, 2021
49bb731
level tests
attack68 Aug 30, 2021
044cd05
user guide
attack68 Aug 30, 2021
8fc497d
typing fix
attack68 Aug 31, 2021
8fb9519
user guide refactor
attack68 Aug 31, 2021
d039105
Merge remote-tracking branch 'upstream/master' into styler_format_index
attack68 Sep 1, 2021
df7548c
input to axis
attack68 Sep 1, 2021
6523f48
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Sep 1, 2021
5091d49
reformating
attack68 Sep 1, 2021
c686adb
add and document arg changes
attack68 Sep 1, 2021
0df2aaf
add and document arg changes
attack68 Sep 1, 2021
6accdfa
test changes
attack68 Sep 1, 2021
3448a9a
test changes
attack68 Sep 1, 2021
ef235e5
refactor to account for precision=0
attack68 Sep 1, 2021
d06128f
refactor to account for precision=0
attack68 Sep 1, 2021
e6b2eef
edits tests to pass
attack68 Sep 1, 2021
5fb997d
edits tests to pass
attack68 Sep 1, 2021
0d91aff
Merge remote-tracking branch 'upstream/master' into styler_format_index
attack68 Sep 2, 2021
e36f198
fix tests
attack68 Sep 2, 2021
4fd6e68
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Sep 2, 2021
5be0006
Merge branch 'styler_format_index' into depr_df_to_latex
attack68 Sep 2, 2021
c966942
fix tests
attack68 Sep 2, 2021
f6ceadb
fix tests
attack68 Sep 2, 2021
949e39d
fix tests
attack68 Sep 2, 2021
a721d6e
fix tests
attack68 Sep 2, 2021
9ec466b
fix tests
attack68 Sep 2, 2021
5652a58
fix tests
attack68 Sep 2, 2021
e7338ab
fix tests
attack68 Sep 2, 2021
1842e18
fix tests
attack68 Sep 2, 2021
120a121
fix tests
attack68 Sep 2, 2021
27a928e
fix tests
attack68 Sep 2, 2021
d7779b6
multirow naive implementation
attack68 Sep 2, 2021
11ac603
multirow naive implementation
attack68 Sep 2, 2021
7920037
multirow naive implementation
attack68 Sep 3, 2021
f74c1a5
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Sep 3, 2021
eee3cd1
remove validation capture
attack68 Sep 3, 2021
0c624a1
Merge branch 'latex_multicol_naive' into depr_df_to_latex
attack68 Sep 3, 2021
5c170fd
Merge branch 'latex_multirow_naive' into depr_df_to_latex
attack68 Sep 3, 2021
0c55981
fix tests
attack68 Sep 3, 2021
241a896
fix tests
attack68 Sep 3, 2021
ad844a9
fix tests
attack68 Sep 3, 2021
8cba047
fix tests
attack68 Sep 3, 2021
7f314a0
fix tests
attack68 Sep 3, 2021
49c929d
fix tests
attack68 Sep 3, 2021
7912127
fix tests
attack68 Sep 3, 2021
6ea94bf
fix tests
attack68 Sep 3, 2021
c4bf504
fix tests
attack68 Sep 3, 2021
1b33ec5
fix tests
attack68 Sep 3, 2021
f7da49e
fix tests
attack68 Sep 3, 2021
2a1b9c2
remove test: caption validation
attack68 Sep 4, 2021
30832ae
siunitx changes: render {} only when needed.
attack68 Sep 4, 2021
13dd5c8
Merge branch 'styler_siunitx_headers_parse' into depr_df_to_latex
attack68 Sep 4, 2021
e07f6d0
revert braces in tests
attack68 Sep 4, 2021
c7396bb
revert braces in tests
attack68 Sep 4, 2021
a191b3d
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Sep 4, 2021
121062f
Merge remote-tracking branch 'upstream/master' into latex_multirow_naive
attack68 Sep 4, 2021
8ea7b0c
Merge remote-tracking branch 'upstream/master' into latex_multicol_naive
attack68 Sep 4, 2021
b87ef09
Merge remote-tracking branch 'upstream/master' into styler_format_index
attack68 Sep 4, 2021
c161df3
fix tests
attack68 Sep 4, 2021
b1d8a27
amend tests for siunitx
attack68 Sep 4, 2021
7e9cc49
Merge branch 'latex_multirow_naive' into depr_df_to_latex
attack68 Sep 4, 2021
2998507
Merge branch 'latex_multicol_naive' into depr_df_to_latex
attack68 Sep 4, 2021
8ac31d6
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Sep 5, 2021
08223d7
fix tests
attack68 Sep 5, 2021
1d038c9
warn deprecated args
attack68 Sep 5, 2021
3ee4012
add note to docstring
attack68 Sep 5, 2021
8b40beb
mypy fixes
attack68 Sep 5, 2021
02f4b16
arg changes
attack68 Sep 5, 2021
9a7a8e4
Merge remote-tracking branch 'upstream/master' into styler_format_index
attack68 Sep 5, 2021
ecd01dd
fix recent merged tests
attack68 Sep 5, 2021
63e18e2
fix recent merged tests
attack68 Sep 5, 2021
a21590b
refactor to_latex
attack68 Sep 5, 2021
13906fe
refactor to_latex encoding
attack68 Sep 5, 2021
b7431be
reorder-args
attack68 Sep 5, 2021
9cd0033
fix escape
attack68 Sep 5, 2021
910bbae
fix docstring tests
attack68 Sep 5, 2021
0b81918
fix docstring tests
attack68 Sep 5, 2021
54b98b7
add jinja2 hard dep
attack68 Sep 5, 2021
0f0eb84
edit docs
attack68 Sep 5, 2021
4c4ba6d
edit docs
attack68 Sep 5, 2021
6ff376d
Merge branch 'jinja2_hard_dependency' into depr_df_to_latex
attack68 Sep 5, 2021
fabddd0
fix tests by avoiding numpy ambiguous
attack68 Sep 6, 2021
bfb74c2
mypy fix
attack68 Sep 6, 2021
37b7112
fix repr tests
attack68 Sep 6, 2021
1bfbe1b
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Sep 6, 2021
d81fd18
fix repr tests
attack68 Sep 6, 2021
9389426
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Sep 7, 2021
1a32d17
Merge remote-tracking branch 'upstream/master' into styler_format_index
attack68 Sep 7, 2021
afa6da3
Merge remote-tracking branch 'upstream/master' into styler_format_index
attack68 Sep 8, 2021
eca71a9
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Sep 8, 2021
b112ac5
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Sep 8, 2021
7e6bf97
Merge remote-tracking branch 'upstream/master' into styler_format_index
attack68 Sep 8, 2021
06ce6bf
add to style.rst
attack68 Sep 8, 2021
b8c225a
Merge remote-tracking branch 'upstream/master' into styler_format_index
attack68 Sep 8, 2021
9562b3d
Merge remote-tracking branch 'upstream/master' into styler_format_index
attack68 Sep 9, 2021
4aa58e8
Merge remote-tracking branch 'upstream/master' into styler_format_index
attack68 Sep 9, 2021
a35f4e6
Merge branch 'styler_format_index' into depr_df_to_latex
attack68 Sep 9, 2021
249022a
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Sep 15, 2021
ed399e7
Merge remote-tracking branch 'upstream/master' into depr_df_to_latex
attack68 Sep 16, 2021
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
add and document arg changes
  • Loading branch information
attack68 committed Sep 1, 2021
commit c686adb0ed7ec1cd642ec5cca2be6e522616ba68
165 changes: 115 additions & 50 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3117,29 +3117,38 @@ def to_latex(
buf=None,
*,
encoding=None,
sparse_index=None,
sparse_columns=None,
header=True,
index=True,
columns=None,
column_format=None,
position=None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to add all of these options? e.g. since we can already do this with styler

position_float=None,
hrules=False,
label=None,
caption=None,
multirow_align="c",
multicol_align="r",
siunitx=False,
environment=None,
formatter=None,
na_rep=None,
precision=None,
decimal=".",
thousands=None,
escape=False,
index_names=True,
bold_rows=False,
column_format=None,
bold_headers=False,
longtable=None,
multicolumn=None,
multicolumn_format=None,
multirow=None,
caption=None,
label=None,
position=None,
index_names=True,
col_space=None,
formatters=None,
float_format=None,
sparsify=None,
bold_rows=False,
):
r"""
Render object to a LaTeX tabular, longtable, or nested table/tabular.
Expand Down Expand Up @@ -3183,7 +3192,71 @@ def to_latex(
Whether to print index labels.
columns : list of label, optional
The subset of columns to write. Writes all columns by default.
column_format : str, optional
The LaTeX column specification placed in location:

\\begin{{tabular}}{{<column_format>}}

Defaults to 'l' for index and
non-numeric data columns, and, for numeric data columns,
to 'r' by default, or 'S' if ``siunitx`` is ``True``.

.. versionchanged:: 1.4.0
position : str, optional
The LaTeX positional argument (e.g. 'h!') for tables, placed in location:

\\begin{{table}}[<position>]

.. versionchanged:: 1.2.0
position_float : {{"centering", "raggedleft", "raggedright"}}, optional
The LaTeX float command placed in location:

\\begin{{table}}[<position>]

\\<position_float>

Cannot be used if ``environment`` is "longtable".

.. versionadded:: 1.4.0
hrules : bool, default False
Set to `True` to add \\toprule, \\midrule and \\bottomrule from the
{{booktabs}} LaTeX package.

.. versionadded:: 1.4.0
label : str, optional
The LaTeX label included as: \\label{{<label>}}.
This is used with \\ref{{<label>}} in the main .tex file.

.. versionadded:: 1.0.0
caption : str, tuple, optional
If string, the LaTeX table caption included as: \\caption{{<caption>}}.
If tuple, i.e ("full caption", "short caption"), the caption included
as: \\caption[<caption[1]>]{{<caption[0]>}}.

.. versionadded:: 1.0.0

.. versionchanged:: 1.2.0
Optionally allow caption to be a tuple ``(full_caption, short_caption)``.
multirow_align : {{"c", "t", "b"}}
If sparsifying hierarchical MultiIndexes whether to align text centrally,
at the top or bottom.

.. versionadded:: 1.4.0
multicol_align : {{"r", "c", "l"}}
If sparsifying hierarchical MultiIndex columns whether to align text at
the left, centrally, or at the right.

.. versionadded:: 1.4.0
siunitx : bool, default False
Set to ``True`` to structure LaTeX compatible with the {{siunitx}} package.

.. versionadded:: 1.4.0
environment : str, optional
If given, the environment that will replace 'table' in ``\\begin{{table}}``.
If 'longtable' is specified then a more suitable template is
rendered.

.. versionadded:: 1.4.0
formatter : str, callable, dict, optional
Object to define how values are displayed. See notes for ``Styler.format``

Expand Down Expand Up @@ -3212,6 +3285,11 @@ def to_latex(
LaTeX-safe sequences.
Escaping is done before ``formatter``.

.. versionchanged:: 1.4.0
bold_headers : bool, default False
Make the row labels bold in the output, using
command ``\\textbf{{<value>}}``

.. versionchanged:: 1.4.0
formatters : list, tuple or dict of one-param. functions, optional

Expand All @@ -3225,61 +3303,33 @@ def to_latex(

.. deprecated:: 1.4.0
Remove the names of indexes before rendering.
bold_rows : bool, default False
Make the row labels bold in the output.
column_format : str, optional
The columns format as specified in `LaTeX table format
<https://en.wikibooks.org/wiki/LaTeX/Tables>`__ e.g. 'rcl' for 3
columns. By default, 'l' will be used for all columns except
columns of numbers, which default to 'r'.
longtable : bool, optional
By default, the value will be read from the pandas config
module. Use a longtable environment instead of tabular. Requires
adding a \usepackage{{longtable}} to your LaTeX preamble.
escape : bool, optional
By default, the value will be read from the pandas config
module. When set to False prevents from escaping latex special
characters in column names.

multicolumn : bool, default True
Use \multicolumn to enhance MultiIndex columns.
The default will be read from the config module.
multicolumn_format : str, default 'l'
The alignment for multicolumns, similar to `column_format`
The default will be read from the config module.
multirow : bool, default False
Use \multirow to enhance MultiIndex rows. Requires adding a
\usepackage{{multirow}} to your LaTeX preamble. Will print
centered labels (instead of top-aligned) across the contained
rows, separating groups via clines. The default will be read
from the pandas config module.
caption : str or tuple, optional
Tuple (full_caption, short_caption),
which results in ``\caption[short_caption]{{full_caption}}``;
if a single string is passed, no short caption will be set.

.. versionadded:: 1.0.0

.. versionchanged:: 1.2.0
Optionally allow caption to be a tuple ``(full_caption, short_caption)``.
label : str, optional
The LaTeX label to be placed inside ``\label{{}}`` in the output.
This is used with ``\ref{{}}`` in the main ``.tex`` file.
..deprecated:: 1.4.0
Use alternative ``sparse_columns`` and ``multicol_align`` arguments.
multicolumn_format : str, default 'l'

.. versionadded:: 1.0.0
position : str, optional
The LaTeX positional argument for tables, to be placed after
``\begin{{}}`` in the output.
..deprecated:: 1.4.0
Use alternative ``sparse_columns`` and ``multicol_align`` arguments.
multirow : bool, default False
..deprecated:: 1.4.0
Use alternative ``sparse_index`` and ``multirow_align`` arguments.
longtable : bool

.. versionadded:: 1.2.0
.. deprecated:: 1.4.0
Use ``environment='longtable'`` instead.
sparsify : bool

.. deprecated:: 1.4.0
Use ``sparse_columns`` and ``sparse_rows``instead.
Use ``sparse_columns`` and ``sparse_rows`` instead.
col_space : int, optional

.. deprecated:: 1.4.0
Adding LaTeX styling commands renders spacing not applicable.
bold_rows : bool, default False

.. deprecated:: 1.4.0
Use ``bold_headers`` instead.

{returns}
See Also
Expand Down Expand Up @@ -3328,10 +3378,25 @@ def to_latex(
if columns:
hidden = [col for col in styler.columns if col not in columns]
styler.hide_columns(hidden)
if bold_headers:
styler.applymap_index(lambda val: "textbf: --rwrap;")
styler.applymap_index(lambda val: "textbf: --rwrap;", axis=1)

return styler.to_latex(
buf=buf,
encoding=encoding,
sparse_index=sparse_index,
sparse_columns=sparse_columns,
column_format=column_format,
position=position,
position_float=position_float,
hrules=hrules,
label=label,
caption=caption,
multirow_align=multirow_align,
multicol_align=multicol_align,
environment=environment,
siunitx=siunitx,
)

@final
Expand Down