Skip to content

Commit 5c6dd43

Browse files
simonjayhawkinsWillAyd
authored andcommitted
TST/CLN: deduplicate fixture from test_to_latex.py (#26603)
1 parent efc2ada commit 5c6dd43

File tree

3 files changed

+42
-45
lines changed

3 files changed

+42
-45
lines changed

pandas/conftest.py

+31
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import pandas.util._test_decorators as td
1313

1414
import pandas as pd
15+
from pandas import DataFrame
16+
import pandas.util.testing as tm
1517

1618
hypothesis.settings.register_profile(
1719
"ci",
@@ -690,3 +692,32 @@ def tick_classes(request):
690692
normalize=st.booleans(),
691693
startingMonth=st.integers(min_value=1, max_value=12)
692694
))
695+
696+
697+
@pytest.fixture
698+
def float_frame():
699+
"""
700+
Fixture for DataFrame of floats with index of unique strings
701+
702+
Columns are ['A', 'B', 'C', 'D'].
703+
704+
A B C D
705+
P7GACiRnxd -0.465578 -0.361863 0.886172 -0.053465
706+
qZKh6afn8n -0.466693 -0.373773 0.266873 1.673901
707+
tkp0r6Qble 0.148691 -0.059051 0.174817 1.598433
708+
wP70WOCtv8 0.133045 -0.581994 -0.992240 0.261651
709+
M2AeYQMnCz -1.207959 -0.185775 0.588206 0.563938
710+
QEPzyGDYDo -0.381843 -0.758281 0.502575 -0.565053
711+
r78Jwns6dn -0.653707 0.883127 0.682199 0.206159
712+
... ... ... ... ...
713+
IHEGx9NO0T -0.277360 0.113021 -1.018314 0.196316
714+
lPMj8K27FA -1.313667 -0.604776 -1.305618 -0.863999
715+
qa66YMWQa5 1.110525 0.475310 -0.747865 0.032121
716+
yOa0ATsmcE -0.431457 0.067094 0.096567 -0.264962
717+
65znX3uRNG 1.528446 0.160416 -0.109635 -0.032987
718+
eCOBvKqf3e 0.235281 1.622222 0.781255 0.392871
719+
xSucinXxuV -1.263557 0.252799 -0.552247 0.400426
720+
721+
[30 rows x 4 columns]
722+
"""
723+
return DataFrame(tm.getSeriesData())

pandas/tests/frame/conftest.py

-29
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,6 @@
55
import pandas.util.testing as tm
66

77

8-
@pytest.fixture
9-
def float_frame():
10-
"""
11-
Fixture for DataFrame of floats with index of unique strings
12-
13-
Columns are ['A', 'B', 'C', 'D'].
14-
15-
A B C D
16-
P7GACiRnxd -0.465578 -0.361863 0.886172 -0.053465
17-
qZKh6afn8n -0.466693 -0.373773 0.266873 1.673901
18-
tkp0r6Qble 0.148691 -0.059051 0.174817 1.598433
19-
wP70WOCtv8 0.133045 -0.581994 -0.992240 0.261651
20-
M2AeYQMnCz -1.207959 -0.185775 0.588206 0.563938
21-
QEPzyGDYDo -0.381843 -0.758281 0.502575 -0.565053
22-
r78Jwns6dn -0.653707 0.883127 0.682199 0.206159
23-
... ... ... ... ...
24-
IHEGx9NO0T -0.277360 0.113021 -1.018314 0.196316
25-
lPMj8K27FA -1.313667 -0.604776 -1.305618 -0.863999
26-
qa66YMWQa5 1.110525 0.475310 -0.747865 0.032121
27-
yOa0ATsmcE -0.431457 0.067094 0.096567 -0.264962
28-
65znX3uRNG 1.528446 0.160416 -0.109635 -0.032987
29-
eCOBvKqf3e 0.235281 1.622222 0.781255 0.392871
30-
xSucinXxuV -1.263557 0.252799 -0.552247 0.400426
31-
32-
[30 rows x 4 columns]
33-
"""
34-
return DataFrame(tm.getSeriesData())
35-
36-
378
@pytest.fixture
389
def float_frame_with_na():
3910
"""

pandas/tests/io/formats/test_to_latex.py

+11-16
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,14 @@
88
from pandas.util import testing as tm
99

1010

11-
@pytest.fixture
12-
def frame():
13-
return DataFrame(tm.getSeriesData())
14-
15-
1611
class TestToLatex:
1712

18-
def test_to_latex_filename(self, frame):
13+
def test_to_latex_filename(self, float_frame):
1914
with tm.ensure_clean('test.tex') as path:
20-
frame.to_latex(path)
15+
float_frame.to_latex(path)
2116

2217
with open(path, 'r') as f:
23-
assert frame.to_latex() == f.read()
18+
assert float_frame.to_latex() == f.read()
2419

2520
# test with utf-8 and encoding option (GH 7061)
2621
df = DataFrame([['au\xdfgangen']])
@@ -35,9 +30,9 @@ def test_to_latex_filename(self, frame):
3530
with codecs.open(path, 'r', encoding='utf-8') as f:
3631
assert df.to_latex() == f.read()
3732

38-
def test_to_latex(self, frame):
33+
def test_to_latex(self, float_frame):
3934
# it works!
40-
frame.to_latex()
35+
float_frame.to_latex()
4136

4237
df = DataFrame({'a': [1, 2], 'b': ['b1', 'b2']})
4338
withindex_result = df.to_latex()
@@ -66,9 +61,9 @@ def test_to_latex(self, frame):
6661

6762
assert withoutindex_result == withoutindex_expected
6863

69-
def test_to_latex_format(self, frame):
64+
def test_to_latex_format(self, float_frame):
7065
# GH Bug #9402
71-
frame.to_latex(column_format='ccc')
66+
float_frame.to_latex(column_format='ccc')
7267

7368
df = DataFrame({'a': [1, 2], 'b': ['b1', 'b2']})
7469
withindex_result = df.to_latex(column_format='ccc')
@@ -389,8 +384,8 @@ def test_to_latex_special_escape(self):
389384
"""
390385
assert escaped_result == escaped_expected
391386

392-
def test_to_latex_longtable(self, frame):
393-
frame.to_latex(longtable=True)
387+
def test_to_latex_longtable(self, float_frame):
388+
float_frame.to_latex(longtable=True)
394389

395390
df = DataFrame({'a': [1, 2], 'b': ['b1', 'b2']})
396391
withindex_result = df.to_latex(longtable=True)
@@ -535,9 +530,9 @@ def test_to_latex_specified_header(self):
535530
with pytest.raises(ValueError):
536531
df.to_latex(header=['A'])
537532

538-
def test_to_latex_decimal(self, frame):
533+
def test_to_latex_decimal(self, float_frame):
539534
# GH 12031
540-
frame.to_latex()
535+
float_frame.to_latex()
541536

542537
df = DataFrame({'a': [1.0, 2.1], 'b': ['b1', 'b2']})
543538
withindex_result = df.to_latex(decimal=',')

0 commit comments

Comments
 (0)