Skip to content

Commit 930471d

Browse files
committed
MAINT: Address reviewer comments
* Move whatsnew to 0.21.1.txt * Empty tests for empty DataFrame in to_latex
1 parent 60a4fc8 commit 930471d

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

doc/source/whatsnew/v0.21.0.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,6 @@ I/O
10891089
- Bug in :meth:`DataFrame.to_html` in which there was no validation of the ``justify`` parameter (:issue:`17527`)
10901090
- Bug in :func:`HDFStore.select` when reading a contiguous mixed-data table featuring VLArray (:issue:`17021`)
10911091
- Bug in :func:`to_json` where several conditions (including objects with unprintable symbols, objects with deep recursion, overlong labels) caused segfaults instead of raising the appropriate exception (:issue:`14256`)
1092-
- Bug in :meth:`DataFrame.to_latex` with ``longtable=True`` where a latex multicolumn always spanned over three columns (:issue:`17959`)
10931092

10941093
Plotting
10951094
^^^^^^^^

doc/source/whatsnew/v0.21.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ I/O
127127
- Bug in :func:`pandas.io.json.json_normalize` to avoid modification of ``meta`` (:issue:`18610`)
128128
- Bug in :func:`to_latex` where repeated multi-index values were not printed even though a higher level index differed from the previous row (:issue:`14484`)
129129
- Bug when reading NaN-only categorical columns in :class:`HDFStore` (:issue:`18413`)
130+
- Bug in :meth:`DataFrame.to_latex` with ``longtable=True`` where a latex multicolumn always spanned over three columns (:issue:`17959`)
130131

131132
Plotting
132133
^^^^^^^^

pandas/tests/io/formats/test_to_latex.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,29 @@ def test_to_latex_format(self, frame):
9191

9292
assert withindex_result == withindex_expected
9393

94+
def test_to_latex_empty(self):
95+
df = DataFrame()
96+
result = df.to_latex()
97+
expected = r"""\begin{tabular}{l}
98+
\toprule
99+
Empty DataFrame
100+
Columns: Index([], dtype='object')
101+
Index: Index([], dtype='object') \\
102+
\bottomrule
103+
\end{tabular}
104+
"""
105+
assert result == expected
106+
107+
result = df.to_latex(longtable=True)
108+
expected = r"""\begin{longtable}{l}
109+
\toprule
110+
Empty DataFrame
111+
Columns: Index([], dtype='object')
112+
Index: Index([], dtype='object') \\
113+
\end{longtable}
114+
"""
115+
assert result == expected
116+
94117
def test_to_latex_with_formatters(self):
95118
df = DataFrame({'int': [1, 2, 3],
96119
'float': [1.0, 2.0, 3.0],
@@ -367,7 +390,7 @@ def test_to_latex_longtable(self, frame):
367390
\midrule
368391
\endhead
369392
\midrule
370-
\multicolumn{2}{r}{{Continued on next page}} \\
393+
\multicolumn{3}{r}{{Continued on next page}} \\
371394
\midrule
372395
\endfoot
373396
@@ -377,7 +400,7 @@ def test_to_latex_longtable(self, frame):
377400
1 & 2 & b2 \\
378401
\end{longtable}
379402
"""
380-
403+
open("expected.txt", "w").write(withindex_result)
381404
assert withindex_result == withindex_expected
382405

383406
withoutindex_result = df.to_latex(index=False, longtable=True)
@@ -387,7 +410,7 @@ def test_to_latex_longtable(self, frame):
387410
\midrule
388411
\endhead
389412
\midrule
390-
\multicolumn{3}{r}{{Continued on next page}} \\
413+
\multicolumn{2}{r}{{Continued on next page}} \\
391414
\midrule
392415
\endfoot
393416

0 commit comments

Comments
 (0)