-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Changes from 1 commit
c586522
74d7ff2
ece5987
4a9b076
5a97aad
edd91ec
8821026
e03e014
bb9b5b2
fb86279
846e5a2
9e995e1
7e9400a
9c63ab8
87a6c88
9c969ad
26f3906
ec40418
0de5397
6fe8285
6b61e31
6eaa933
666e460
49bb731
044cd05
8fc497d
8fb9519
d039105
df7548c
6523f48
5091d49
c686adb
0df2aaf
6accdfa
3448a9a
ef235e5
d06128f
e6b2eef
5fb997d
0d91aff
e36f198
4fd6e68
5be0006
c966942
f6ceadb
949e39d
a721d6e
9ec466b
5652a58
e7338ab
1842e18
120a121
27a928e
d7779b6
11ac603
7920037
f74c1a5
eee3cd1
0c624a1
5c170fd
0c55981
241a896
ad844a9
8cba047
7f314a0
49c929d
7912127
6ea94bf
c4bf504
1b33ec5
f7da49e
2a1b9c2
30832ae
13dd5c8
e07f6d0
c7396bb
a191b3d
121062f
8ea7b0c
b87ef09
c161df3
b1d8a27
7e9cc49
2998507
8ac31d6
08223d7
1d038c9
3ee4012
8b40beb
02f4b16
9a7a8e4
ecd01dd
63e18e2
a21590b
13906fe
b7431be
9cd0033
910bbae
0b81918
54b98b7
0f0eb84
4c4ba6d
6ff376d
fabddd0
bfb74c2
37b7112
1bfbe1b
d81fd18
9389426
1a32d17
afa6da3
eca71a9
b112ac5
7e6bf97
06ce6bf
b8c225a
9562b3d
4aa58e8
a35f4e6
249022a
ed399e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,7 +99,7 @@ def test_to_latex_tabular_without_index(self): | |
) | ||
def test_to_latex_bad_column_format(self, bad_column_format): | ||
df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]}) | ||
msg = r"column_format must be str or unicode" | ||
msg = r"`column_format` must be a string" | ||
with pytest.raises(ValueError, match=msg): | ||
df.to_latex(column_format=bad_column_format) | ||
|
||
|
@@ -197,72 +197,69 @@ def test_to_latex_midrule_location(self): | |
class TestToLatexLongtable: | ||
def test_to_latex_empty_longtable(self): | ||
df = DataFrame() | ||
result = df.to_latex(longtable=True) | ||
result = df.to_latex(environment="longtable") | ||
Comment on lines
-202
to
+200
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically I could try to work around the existing args feeding the new ones, but for this first review I wanted to get some feedback and the cleanest at the start was to simply raise a warning that it has been replaced. |
||
expected = _dedent( | ||
r""" | ||
\begin{longtable}{l} | ||
\toprule | ||
Empty DataFrame | ||
Columns: Index([], dtype='object') | ||
Index: Index([], dtype='object') \\ | ||
\endfirsthead | ||
\endhead | ||
\multicolumn{1}{r}{Continued on next page} \\ | ||
\endfoot | ||
\endlastfoot | ||
\end{longtable} | ||
""" | ||
) | ||
assert result == expected | ||
|
||
def test_to_latex_longtable_with_index(self): | ||
df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]}) | ||
result = df.to_latex(longtable=True) | ||
result = df.to_latex(environment="longtable", hrules=True) | ||
expected = _dedent( | ||
r""" | ||
\begin{longtable}{lrl} | ||
\toprule | ||
{} & a & b \\ | ||
{} & {a} & {b} \\ | ||
\midrule | ||
\endfirsthead | ||
|
||
\toprule | ||
{} & a & b \\ | ||
{} & {a} & {b} \\ | ||
\midrule | ||
\endhead | ||
\midrule | ||
\multicolumn{3}{r}{{Continued on next page}} \\ | ||
\multicolumn{3}{r}{Continued on next page} \\ | ||
\midrule | ||
\endfoot | ||
|
||
\bottomrule | ||
\endlastfoot | ||
0 & 1 & b1 \\ | ||
1 & 2 & b2 \\ | ||
0 & 1 & b1 \\ | ||
1 & 2 & b2 \\ | ||
\end{longtable} | ||
""" | ||
) | ||
assert result == expected | ||
|
||
def test_to_latex_longtable_without_index(self): | ||
df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]}) | ||
result = df.to_latex(index=False, longtable=True) | ||
result = df.to_latex(index=False, environment="longtable", hrules=True) | ||
expected = _dedent( | ||
r""" | ||
\begin{longtable}{rl} | ||
\toprule | ||
a & b \\ | ||
{a} & {b} \\ | ||
\midrule | ||
\endfirsthead | ||
|
||
\toprule | ||
a & b \\ | ||
{a} & {b} \\ | ||
\midrule | ||
\endhead | ||
\midrule | ||
\multicolumn{2}{r}{{Continued on next page}} \\ | ||
\multicolumn{2}{r}{Continued on next page} \\ | ||
\midrule | ||
\endfoot | ||
|
||
\bottomrule | ||
\endlastfoot | ||
1 & b1 \\ | ||
2 & b2 \\ | ||
1 & b1 \\ | ||
2 & b2 \\ | ||
\end{longtable} | ||
""" | ||
) | ||
|
@@ -277,21 +274,22 @@ def test_to_latex_longtable_without_index(self): | |
], | ||
) | ||
def test_to_latex_longtable_continued_on_next_page(self, df, expected_number): | ||
result = df.to_latex(index=False, longtable=True) | ||
result = df.to_latex(index=False, environment="longtable") | ||
assert fr"\multicolumn{{{expected_number}}}" in result | ||
|
||
|
||
class TestToLatexHeader: | ||
def test_to_latex_no_header_with_index(self): | ||
# GH 7124 | ||
df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]}) | ||
result = df.to_latex(header=False) | ||
result = df.to_latex(header=False, hrules=True) | ||
expected = _dedent( | ||
r""" | ||
\begin{tabular}{lrl} | ||
\toprule | ||
0 & 1 & b1 \\ | ||
1 & 2 & b2 \\ | ||
\midrule | ||
0 & 1 & b1 \\ | ||
1 & 2 & b2 \\ | ||
\bottomrule | ||
\end{tabular} | ||
""" | ||
|
@@ -301,11 +299,12 @@ def test_to_latex_no_header_with_index(self): | |
def test_to_latex_no_header_without_index(self): | ||
# GH 7124 | ||
df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]}) | ||
result = df.to_latex(index=False, header=False) | ||
result = df.to_latex(index=False, header=False, hrules=True) | ||
expected = _dedent( | ||
r""" | ||
\begin{tabular}{rl} | ||
\toprule | ||
\midrule | ||
1 & b1 \\ | ||
2 & b2 \\ | ||
\bottomrule | ||
|
@@ -317,15 +316,15 @@ def test_to_latex_no_header_without_index(self): | |
def test_to_latex_specified_header_with_index(self): | ||
# GH 7124 | ||
df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]}) | ||
result = df.to_latex(header=["AA", "BB"]) | ||
result = df.to_latex(header=["AA", "BB"], hrules=True) | ||
expected = _dedent( | ||
r""" | ||
\begin{tabular}{lrl} | ||
\toprule | ||
{} & AA & BB \\ | ||
{} & {AA} & {BB} \\ | ||
\midrule | ||
0 & 1 & b1 \\ | ||
1 & 2 & b2 \\ | ||
0 & 1 & b1 \\ | ||
1 & 2 & b2 \\ | ||
\bottomrule | ||
\end{tabular} | ||
""" | ||
|
@@ -335,15 +334,15 @@ def test_to_latex_specified_header_with_index(self): | |
def test_to_latex_specified_header_without_index(self): | ||
# GH 7124 | ||
df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]}) | ||
result = df.to_latex(header=["AA", "BB"], index=False) | ||
result = df.to_latex(header=["AA", "BB"], index=False, hrules=True) | ||
expected = _dedent( | ||
r""" | ||
\begin{tabular}{rl} | ||
\toprule | ||
AA & BB \\ | ||
{AA} & {BB} \\ | ||
\midrule | ||
1 & b1 \\ | ||
2 & b2 \\ | ||
1 & b1 \\ | ||
2 & b2 \\ | ||
\bottomrule | ||
\end{tabular} | ||
""" | ||
|
@@ -366,7 +365,7 @@ def test_to_latex_number_of_items_in_header_missmatch_raises( | |
): | ||
# GH 7124 | ||
df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]}) | ||
msg = f"Writing 2 cols but got {num_aliases} aliases" | ||
msg = f"`header` gave {num_aliases} aliases for 2 columns." | ||
with pytest.raises(ValueError, match=msg): | ||
df.to_latex(header=header) | ||
|
||
|
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.
do we need to add all of these options? e.g. since we can already do this with styler