Skip to content

Commit d644065

Browse files
committed
test fix up
1 parent 0c12f3a commit d644065

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

pandas/core/generic.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,6 +3227,7 @@ def to_latex(
32273227
def to_latex(
32283228
self,
32293229
buf: FilePath | WriteBuffer[str] | None = None,
3230+
*,
32303231
columns: Sequence[Hashable] | None = None,
32313232
col_space: ColspaceArgType | None = None,
32323233
header: bool_t | Sequence[str] = True,
@@ -3270,6 +3271,9 @@ def to_latex(
32703271
The subset of columns to write. Writes all columns by default.
32713272
col_space : int, optional
32723273
The minimum width of each column.
3274+
3275+
.. deprecated:: 1.5.0
3276+
Whitespace does not affect a rendered LaTeX file and is ignored.
32733277
header : bool or list of str, default True
32743278
Write out the column names. If a list of strings is given,
32753279
it is assumed to be aliases for the column names.
@@ -3366,6 +3370,13 @@ def to_latex(
33663370
\bottomrule
33673371
\end{{tabular}}
33683372
"""
3373+
msg = (
3374+
"`col_space` is deprecated. Whitespace in LaTeX does not impact "
3375+
"the rendered version, and this argument is ignored."
3376+
)
3377+
if col_space is not None:
3378+
warnings.warn(msg, DeprecationWarning, stacklevel=find_stack_level())
3379+
33693380
# Get defaults from the pandas config
33703381
if self.ndim == 1:
33713382
self = self.to_frame()
@@ -3382,6 +3393,9 @@ def to_latex(
33823393

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

33863400
# Refactor formatters/float_format/decimal/na_rep/escape to Styler structure
33873401
base_format_ = {

pandas/tests/io/formats/test_to_latex.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def test_to_latex_empty_longtable(self):
213213
\midrule
214214
\endhead
215215
\midrule
216-
\multicolumn{1}{r}{Continued on next page} \\
216+
\multicolumn{0}{r}{Continued on next page} \\
217217
\midrule
218218
\endfoot
219219
\bottomrule
@@ -377,7 +377,7 @@ def test_to_latex_number_of_items_in_header_missmatch_raises(
377377
):
378378
# GH 7124
379379
df = DataFrame({"a": [1, 2], "b": ["b1", "b2"]})
380-
msg = "``aliases`` must be of length equal to the number of visible labels"
380+
msg = f"Writing 2 cols but got {num_aliases} aliases"
381381
with pytest.raises(ValueError, match=msg):
382382
df.to_latex(header=header)
383383

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

0 commit comments

Comments
 (0)