Skip to content

Excel Tests Continued Fixture Cleanup #26662

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 7 commits into from
Jun 8, 2019
Merged
Changes from 2 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
28 changes: 12 additions & 16 deletions pandas/tests/io/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ def frame(float_frame):
return float_frame[:10]


@pytest.fixture
def frame2(float_frame):
float_frame = float_frame.copy()
float_frame.columns = ['D', 'C', 'B', 'A']
return float_frame[:10]


@pytest.fixture
def tsframe():
return tm.makeTimeDataFrame()[:5]
Expand All @@ -58,8 +51,9 @@ def ignore_xlrd_time_clock_warning():
yield


@td.skip_if_no('xlrd', '1.0.0')
class ReadingTestsBase:
@td.skip_if_no('xlrd')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that our project-wide minimum ix 1.0.0, so this decorator was being duplicative.

This decorator also won't be there in the long term once we completely couple TestReaders from xlrd, but keeping here for now

@pytest.mark.parametrize("ext", ['.xls', '.xlsx', '.xlsm'])
class TestReaders:
# This is based on ExcelWriterBase

@pytest.fixture(autouse=True, params=['xlrd', None])
Expand Down Expand Up @@ -844,7 +838,7 @@ def test_read_excel_squeeze(self, ext):
tm.assert_series_equal(actual, expected)


@td.skip_if_no('xlrd', '1.0.0')
@td.skip_if_no('xlrd')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment might have been lost on a prior PR but the min xlrd version for pandas is 1.0.0 anyway, so this was duplicative

@pytest.mark.parametrize("ext", ['.xls', '.xlsx', '.xlsm'])
class TestRoundTrip:

Expand Down Expand Up @@ -1045,9 +1039,9 @@ def test_read_excel_parse_dates(self, ext):
tm.assert_frame_equal(df, res)


@td.skip_if_no('xlrd', '1.0.0')
@td.skip_if_no('xlrd')
@pytest.mark.parametrize("ext", ['.xls', '.xlsx', '.xlsm'])
class TestXlrdReader(ReadingTestsBase):
class TestXlrdReader:
"""
This is the base class for the xlrd tests, and 3 different file formats
are supported: xls, xlsx, xlsm
Expand Down Expand Up @@ -1149,9 +1143,11 @@ def test_excel_sheet_by_name_raise(self, *_):
with pytest.raises(xlrd.XLRDError):
pd.read_excel(xl, "0")

def test_excel_writer_context_manager(self, frame, frame2, *_):
def test_excel_writer_context_manager(self, frame, *_):
with ExcelWriter(self.path) as writer:
frame.to_excel(writer, "Data1")
frame2 = frame.copy()
frame2.columns = frame.columns[::-1]
frame2.to_excel(writer, "Data2")

with ExcelFile(self.path) as reader:
Expand Down Expand Up @@ -1318,7 +1314,7 @@ def test_sheets(self, merge_cells, engine, ext, frame, tsframe):
assert 'test1' == reader.sheet_names[0]
assert 'test2' == reader.sheet_names[1]

def test_colaliases(self, merge_cells, engine, ext, frame, frame2):
def test_colaliases(self, merge_cells, engine, ext, frame):
frame = frame.copy()
frame['A'][:5] = nan

Expand All @@ -1329,10 +1325,10 @@ def test_colaliases(self, merge_cells, engine, ext, frame, frame2):

# column aliases
col_aliases = Index(['AA', 'X', 'Y', 'Z'])
frame2.to_excel(self.path, 'test1', header=col_aliases)
frame.to_excel(self.path, 'test1', header=col_aliases)
reader = ExcelFile(self.path)
rs = pd.read_excel(reader, 'test1', index_col=0)
xp = frame2.copy()
xp = frame.copy()
xp.columns = col_aliases
tm.assert_frame_equal(xp, rs)

Expand Down