Skip to content

Commit cd05038

Browse files
committed
test fix up
1 parent 9dcd254 commit cd05038

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

pandas/tests/frame/test_repr_info.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,20 +286,23 @@ def test_repr_column_name_unicode_truncation_bug(self):
286286
with option_context("display.max_columns", 20):
287287
assert "StringCol" in repr(df)
288288

289-
@pytest.mark.filterwarnings("ignore::FutureWarning")
290289
def test_latex_repr(self):
291-
result = r"""\begin{tabular}{llll}
290+
pytest.importorskip("jinja2")
291+
expected = r"""\begin{tabular}{llll}
292292
\toprule
293-
{} & 0 & 1 & 2 \\
293+
& 0 & 1 & 2 \\
294294
\midrule
295-
0 & $\alpha$ & b & c \\
296-
1 & 1 & 2 & 3 \\
295+
0 & $\alpha$ & b & c \\
296+
1 & 1 & 2 & 3 \\
297297
\bottomrule
298298
\end{tabular}
299299
"""
300-
with option_context("display.latex.escape", False, "display.latex.repr", True):
300+
with option_context(
301+
"display.latex.escape", False, "styler.render.repr", "latex"
302+
):
301303
df = DataFrame([[r"$\alpha$", "b", "c"], [1, 2, 3]])
302-
assert result == df._repr_latex_()
304+
result = df._repr_latex_()
305+
assert result == expected
303306

304307
# GH 12182
305308
assert df._repr_latex_() is None

pandas/tests/io/formats/test_format.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3362,7 +3362,6 @@ def test_repr_html_ipython_config(ip):
33623362
assert not result.error_in_exec
33633363

33643364

3365-
@pytest.mark.filterwarnings("ignore:In future versions `DataFrame.to_latex`")
33663365
@pytest.mark.parametrize("method", ["to_string", "to_html", "to_latex"])
33673366
@pytest.mark.parametrize(
33683367
"encoding, data",
@@ -3377,14 +3376,16 @@ def test_filepath_or_buffer_arg(
33773376
filepath_or_buffer_id,
33783377
):
33793378
df = DataFrame([data])
3379+
if method in ["to_latex"]: # uses styler implementation
3380+
pytest.importorskip("jinja2")
33803381

33813382
if filepath_or_buffer_id not in ["string", "pathlike"] and encoding is not None:
33823383
with pytest.raises(
33833384
ValueError, match="buf is not a file name and encoding is specified."
33843385
):
33853386
getattr(df, method)(buf=filepath_or_buffer, encoding=encoding)
33863387
elif encoding == "foo":
3387-
expected_warning = FutureWarning if method == "to_latex" else None
3388+
expected_warning = None
33883389
with tm.assert_produces_warning(expected_warning):
33893390
with pytest.raises(LookupError, match="unknown encoding"):
33903391
getattr(df, method)(buf=filepath_or_buffer, encoding=encoding)
@@ -3397,6 +3398,8 @@ def test_filepath_or_buffer_arg(
33973398
@pytest.mark.filterwarnings("ignore::FutureWarning")
33983399
@pytest.mark.parametrize("method", ["to_string", "to_html", "to_latex"])
33993400
def test_filepath_or_buffer_bad_arg_raises(float_frame, method):
3401+
if method in ["to_latex"]: # uses styler implementation
3402+
pytest.importorskip("jinja2")
34003403
msg = "buf is not a file name and it has no write method"
34013404
with pytest.raises(TypeError, match=msg):
34023405
getattr(float_frame, method)(buf=object())

pandas/tests/io/formats/test_printing.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import numpy as np
2-
import pytest
32

43
import pandas._config.config as cf
54

@@ -120,9 +119,6 @@ def test_ambiguous_width(self):
120119

121120

122121
class TestTableSchemaRepr:
123-
@pytest.mark.filterwarnings(
124-
"ignore:.*signature may therefore change.*:FutureWarning"
125-
)
126122
def test_publishes(self, ip):
127123
ipython = ip.instance(config=ip.config)
128124
df = pd.DataFrame({"A": [1, 2]})
@@ -138,7 +134,7 @@ def test_publishes(self, ip):
138134
formatted = ipython.display_formatter.format(obj)
139135
assert set(formatted[0].keys()) == expected
140136

141-
with_latex = pd.option_context("display.latex.repr", True)
137+
with_latex = pd.option_context("styler.render.repr", "latex")
142138

143139
with opt, with_latex:
144140
formatted = ipython.display_formatter.format(obj)

pandas/tests/io/test_common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ def test_read_fspath_all(self, reader, module, path, datapath):
336336
else:
337337
tm.assert_frame_equal(result, expected)
338338

339-
@pytest.mark.filterwarnings("ignore:In future versions `DataFrame.to_latex`")
340339
@pytest.mark.parametrize(
341340
"writer_name, writer_kwargs, module",
342341
[
@@ -351,6 +350,8 @@ def test_read_fspath_all(self, reader, module, path, datapath):
351350
],
352351
)
353352
def test_write_fspath_all(self, writer_name, writer_kwargs, module):
353+
if writer_name in ["to_latex"]: # uses Styler implementation
354+
pytest.importorskip("jinja2")
354355
p1 = tm.ensure_clean("string")
355356
p2 = tm.ensure_clean("fspath")
356357
df = pd.DataFrame({"A": [1, 2]})

pandas/tests/series/test_repr.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,21 @@ def test_timeseries_repr_object_dtype(self):
206206
ts2 = ts.iloc[np.random.randint(0, len(ts) - 1, 400)]
207207
repr(ts2).splitlines()[-1]
208208

209-
@pytest.mark.filterwarnings("ignore::FutureWarning")
210209
def test_latex_repr(self):
210+
pytest.importorskip("jinja2") # uses Styler implementation
211211
result = r"""\begin{tabular}{ll}
212212
\toprule
213-
{} & 0 \\
213+
& 0 \\
214214
\midrule
215-
0 & $\alpha$ \\
216-
1 & b \\
217-
2 & c \\
215+
0 & $\alpha$ \\
216+
1 & b \\
217+
2 & c \\
218218
\bottomrule
219219
\end{tabular}
220220
"""
221-
with option_context("display.latex.escape", False, "display.latex.repr", True):
221+
with option_context(
222+
"display.latex.escape", False, "styler.render.repr", "latex"
223+
):
222224
s = Series([r"$\alpha$", "b", "c"])
223225
assert result == s._repr_latex_()
224226

0 commit comments

Comments
 (0)