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
Show file tree
Hide file tree
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
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
8000
Diff view
Prev Previous commit
Next Next commit
test fix up
  • Loading branch information
attack68 committed Aug 9, 2022
commit d64406551afa9a3ba271f214f2fe186c2f5e9d6d
14 changes: 14 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3227,6 +3227,7 @@ def to_latex(
def to_latex(
self,
buf: FilePath | WriteBuffer[str] | None = None,
*,
columns: Sequence[Hashable] | None = None,
col_space: ColspaceArgType | None = None,
header: bool_t | Sequence[str] = True,
Expand Down Expand Up @@ -3270,6 +3271,9 @@ def to_latex(
The subset of columns to write. Writes all columns by default.
col_space : int, optional
The minimum width of each column.

.. deprecated:: 1.5.0
Whitespace does not affect a rendered LaTeX file and is ignored.
header : bool or list of str, default True
Write out the column names. If a list of strings is given,
it is assumed to be aliases for the column names.
Expand Down Expand Up @@ -3366,6 +3370,13 @@ def to_latex(
\bottomrule
\end{{tabular}}
"""
msg = (
"`col_space` is deprecated. Whitespace in LaTeX does not impact "
"the rendered version, and this argument is ignored."
)
if col_space is not None:
warnings.warn(msg, DeprecationWarning, stacklevel=find_stack_level())

# Get defaults from the pandas config
if self.ndim == 1:
self = self.to_frame()
Expand All @@ -3382,6 +3393,9 @@ def to_latex(

if column_format is not None and not isinstance(column_format, str):
raise ValueError("`column_format` must be str or unicode")
length = len(self.columns) if columns is None else len(columns)
if isinstance(header, (list, tuple)) and len(header) != length:
raise ValueError(f"Writing {length} cols but got {len(header)} aliases")

# Refactor formatters/float_format/decimal/na_rep/escape to Styler structure
base_format_ = {
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/io/formats/test_to_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def test_to_latex_empty_longtable(self):
\midrule
\endhead
\midrule
\multicolumn{1}{r}{Continued on next page} \\
\multicolumn{0}{r}{Continued on next page} \\
\midrule
\endfoot
\bottomrule
Expand Down Expand Up @@ -377,7 +377,7 @@ def test_to_latex_number_of_items_in_header_missmatch_raises(
):
# GH 7124
df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
msg = "``aliases`` must be of length equal to the number of visible labels"
msg = f"Writing 2 cols but got {num_aliases} aliases"
with pytest.raises(ValueError, match=msg):
df.to_latex(header=header)

Expand Down Expand Up @@ -1175,7 +1175,7 @@ def test_to_latex_index_has_name_tabular(self):
def test_to_latex_groupby_tabular(self):
# GH 10660
df = DataFrame({"a": [0, 0, 1, 1], "b": list("abab"), "c": [1, 2, 3, 4]})
result = df.groupby("a").describe().to_latex(format={"precision": 1})
result = df.groupby("a").describe().to_latex(float_format="{:.1f}".format)
expected = _dedent(
r"""
\begin{tabular}{lrrrrrrrr}
Expand Down
0