Skip to content

TST/CLN: deduplicate fixture from test_to_latex.py #26603

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

Merged
merged 2 commits into from
Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import pandas.util._test_decorators as td

import pandas as pd
from pandas import DataFrame
import pandas.util.testing as tm

hypothesis.settings.register_profile(
"ci",
Expand Down Expand Up @@ -690,3 +692,32 @@ def tick_classes(request):
normalize=st.booleans(),
startingMonth=st.integers(min_value=1, max_value=12)
))


@pytest.fixture
def float_frame():
"""
Fixture for DataFrame of floats with index of unique strings
Columns are ['A', 'B', 'C', 'D'].
A B C D
P7GACiRnxd -0.465578 -0.361863 0.886172 -0.053465
qZKh6afn8n -0.466693 -0.373773 0.266873 1.673901
tkp0r6Qble 0.148691 -0.059051 0.174817 1.598433
wP70WOCtv8 0.133045 -0.581994 -0.992240 0.261651
M2AeYQMnCz -1.207959 -0.185775 0.588206 0.563938
QEPzyGDYDo -0.381843 -0.758281 0.502575 -0.565053
r78Jwns6dn -0.653707 0.883127 0.682199 0.206159
... ... ... ... ...
IHEGx9NO0T -0.277360 0.113021 -1.018314 0.196316
lPMj8K27FA -1.313667 -0.604776 -1.305618 -0.863999
qa66YMWQa5 1.110525 0.475310 -0.747865 0.032121
yOa0ATsmcE -0.431457 0.067094 0.096567 -0.264962
65znX3uRNG 1.528446 0.160416 -0.109635 -0.032987
eCOBvKqf3e 0.235281 1.622222 0.781255 0.392871
xSucinXxuV -1.263557 0.252799 -0.552247 0.400426
[30 rows x 4 columns]
"""
return DataFrame(tm.getSeriesData())
29 changes: 0 additions & 29 deletions pandas/tests/frame/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,6 @@
import pandas.util.testing as tm


@pytest.fixture
def float_frame():
"""
Fixture for DataFrame of floats with index of unique strings
Columns are ['A', 'B', 'C', 'D'].
A B C D
P7GACiRnxd -0.465578 -0.361863 0.886172 -0.053465
qZKh6afn8n -0.466693 -0.373773 0.266873 1.673901
tkp0r6Qble 0.148691 -0.059051 0.174817 1.598433
wP70WOCtv8 0.133045 -0.581994 -0.992240 0.261651
M2AeYQMnCz -1.207959 -0.185775 0.588206 0.563938
QEPzyGDYDo -0.381843 -0.758281 0.502575 -0.565053
r78Jwns6dn -0.653707 0.883127 0.682199 0.206159
... ... ... ... ...
IHEGx9NO0T -0.277360 0.113021 -1.018314 0.196316
lPMj8K27FA -1.313667 -0.604776 -1.305618 -0.863999
qa66YMWQa5 1.110525 0.475310 -0.747865 0.032121
yOa0ATsmcE -0.431457 0.067094 0.096567 -0.264962
65znX3uRNG 1.528446 0.160416 -0.109635 -0.032987
eCOBvKqf3e 0.235281 1.622222 0.781255 0.392871
xSucinXxuV -1.263557 0.252799 -0.552247 0.400426
[30 rows x 4 columns]
"""
return DataFrame(tm.getSeriesData())


@pytest.fixture
def float_frame_with_na():
"""
Expand Down
27 changes: 11 additions & 16 deletions pandas/tests/io/formats/test_to_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@
from pandas.util import testing as tm


@pytest.fixture
def frame():
return DataFrame(tm.getSeriesData())


class TestToLatex:

def test_to_latex_filename(self, frame):
def test_to_latex_filename(self, float_frame):
with tm.ensure_clean('test.tex') as path:
frame.to_latex(path)
float_frame.to_latex(path)

with open(path, 'r') as f:
assert frame.to_latex() == f.read()
assert float_frame.to_latex() == f.read()

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

def test_to_latex(self, frame):
def test_to_latex(self, float_frame):
# it works!
frame.to_latex()
float_frame.to_latex()

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

assert withoutindex_result == withoutindex_expected

def test_to_latex_format(self, frame):
def test_to_latex_format(self, float_frame):
# GH Bug #9402
frame.to_latex(column_format='ccc')
float_frame.to_latex(column_format='ccc')

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

def test_to_latex_longtable(self, frame):
frame.to_latex(longtable=True)
def test_to_latex_longtable(self, float_frame):
float_frame.to_latex(longtable=True)

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

def test_to_latex_decimal(self, frame):
def test_to_latex_decimal(self, float_frame):
# GH 12031
frame.to_latex()
float_frame.to_latex()

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