-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 3 commits
952ce86
620fa19
417fc30
a5d2616
7fc3f76
fd00e51
fd697ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
|
@@ -58,11 +51,16 @@ def ignore_xlrd_time_clock_warning(): | |
yield | ||
|
||
|
||
@td.skip_if_no('xlrd', '1.0.0') | ||
class ReadingTestsBase: | ||
# This is based on ExcelWriterBase | ||
|
||
@pytest.fixture(autouse=True, params=['xlrd', None]) | ||
@pytest.mark.parametrize("ext", ['.xls', '.xlsx', '.xlsm']) | ||
class TestReaders: | ||
|
||
@pytest.fixture(autouse=True, params=[ | ||
# Add any engines to test here | ||
pytest.param('xlrd', marks=pytest.mark.skipif( | ||
simonjayhawkins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
not td.safe_import("xlrd"), reason="no xlrd")), | ||
pytest.param(None, marks=pytest.mark.skipif( | ||
not td.safe_import("xlrd"), reason="no xlrd")), | ||
]) | ||
def cd_and_set_engine(self, request, datapath, monkeypatch): | ||
""" | ||
Change directory and set engine for read_excel calls. | ||
|
@@ -80,7 +78,6 @@ def df_ref(self): | |
parse_dates=True, engine='python') | ||
return df_ref | ||
|
||
@td.skip_if_no("xlrd", "1.0.1") # see gh-22682 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These didn't really solve the issue they were supposed to so removed to make things cleaner. Again I think the real issue occurs when defusedxml is installed in the right environment, but will have to delve further into which environments that is exactly (orthogonal to this PR) |
||
def test_usecols_int(self, ext, df_ref): | ||
df_ref = df_ref.reindex(columns=["A", "B", "C"]) | ||
|
||
|
@@ -102,7 +99,6 @@ def test_usecols_int(self, ext, df_ref): | |
tm.assert_frame_equal(df1, df_ref, check_names=False) | ||
tm.assert_frame_equal(df2, df_ref, check_names=False) | ||
|
||
@td.skip_if_no('xlrd', '1.0.1') # GH-22682 | ||
def test_usecols_list(self, ext, df_ref): | ||
|
||
df_ref = df_ref.reindex(columns=['B', 'C']) | ||
|
@@ -115,7 +111,6 @@ def test_usecols_list(self, ext, df_ref): | |
tm.assert_frame_equal(df1, df_ref, check_names=False) | ||
tm.assert_frame_equal(df2, df_ref, check_names=False) | ||
|
||
@td.skip_if_no('xlrd', '1.0.1') # GH-22682 | ||
def test_usecols_str(self, ext, df_ref): | ||
|
||
df1 = df_ref.reindex(columns=['A', 'B', 'C']) | ||
|
@@ -270,7 +265,6 @@ def test_excel_passes_na(self, ext): | |
columns=['Test']) | ||
tm.assert_frame_equal(parsed, expected) | ||
|
||
@td.skip_if_no('xlrd', '1.0.1') # GH-22682 | ||
@pytest.mark.parametrize('arg', ['sheet', 'sheetname', 'parse_cols']) | ||
def test_unexpected_kwargs_raises(self, ext, arg): | ||
# gh-17964 | ||
|
@@ -281,7 +275,6 @@ def test_unexpected_kwargs_raises(self, ext, arg): | |
with pytest.raises(TypeError, match=msg): | ||
pd.read_excel(excel, **kwarg) | ||
|
||
@td.skip_if_no('xlrd', '1.0.1') # GH-22682 | ||
def test_excel_table_sheet_by_index(self, ext, df_ref): | ||
|
||
excel = ExcelFile('test1' + ext) | ||
|
@@ -499,7 +492,6 @@ def test_date_conversion_overflow(self, ext): | |
result = pd.read_excel('testdateoverflow' + ext) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
@td.skip_if_no("xlrd", "1.0.1") # see gh-22682 | ||
def test_sheet_name_and_sheetname(self, ext, df_ref): | ||
# gh-10559: Minor improvement: Change "sheet_name" to "sheetname" | ||
# gh-10969: DOC: Consistent var names (sheetname vs sheet_name) | ||
|
@@ -844,7 +836,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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
||
|
@@ -1045,9 +1037,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: | ||
simonjayhawkins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
This is the base class for the xlrd tests, and 3 different file formats | ||
are supported: xls, xlsx, xlsm | ||
|
@@ -1149,9 +1141,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: | ||
|
@@ -1318,7 +1312,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 | ||
|
||
|
@@ -1329,10 +1323,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) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.