-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Remove Unnecessary Subclasses from test_excel #26553
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 all commits
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 |
---|---|---|
|
@@ -2065,11 +2065,10 @@ def test_path_local_path(self, merge_cells, engine, ext): | |
|
||
|
||
@td.skip_if_no('openpyxl') | ||
@pytest.mark.parametrize("merge_cells,ext,engine", [ | ||
(None, '.xlsx', 'openpyxl')]) | ||
class TestOpenpyxlTests(_WriterBase): | ||
@pytest.mark.parametrize("ext", ['.xlsx']) | ||
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. Only one test in each of these classes was actually using the 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.
|
||
class TestOpenpyxlTests: | ||
|
||
def test_to_excel_styleconverter(self, merge_cells, ext, engine): | ||
def test_to_excel_styleconverter(self, ext): | ||
from openpyxl import styles | ||
|
||
hstyle = { | ||
|
@@ -2123,7 +2122,7 @@ def test_to_excel_styleconverter(self, merge_cells, ext, engine): | |
assert kw['number_format'] == number_format | ||
assert kw['protection'] == protection | ||
|
||
def test_write_cells_merge_styled(self, merge_cells, ext, engine): | ||
def test_write_cells_merge_styled(self, ext): | ||
from pandas.io.formats.excel import ExcelCell | ||
|
||
sheet_name = 'merge_styled' | ||
|
@@ -2157,7 +2156,7 @@ def test_write_cells_merge_styled(self, merge_cells, ext, engine): | |
|
||
@pytest.mark.parametrize("mode,expected", [ | ||
('w', ['baz']), ('a', ['foo', 'bar', 'baz'])]) | ||
def test_write_append_mode(self, merge_cells, ext, engine, mode, expected): | ||
def test_write_append_mode(self, ext, mode, expected): | ||
import openpyxl | ||
df = DataFrame([1], columns=['baz']) | ||
|
||
|
@@ -2169,7 +2168,7 @@ def test_write_append_mode(self, merge_cells, ext, engine, mode, expected): | |
wb.worksheets[1]['A1'].value = 'bar' | ||
wb.save(f) | ||
|
||
writer = ExcelWriter(f, engine=engine, mode=mode) | ||
writer = ExcelWriter(f, engine='openpyxl', mode=mode) | ||
df.to_excel(writer, sheet_name='baz', index=False) | ||
writer.save() | ||
|
||
|
@@ -2182,12 +2181,11 @@ def test_write_append_mode(self, merge_cells, ext, engine, mode, expected): | |
|
||
|
||
@td.skip_if_no('xlwt') | ||
@pytest.mark.parametrize("merge_cells,ext,engine", [ | ||
(None, '.xls', 'xlwt')]) | ||
class TestXlwtTests(_WriterBase): | ||
@pytest.mark.parametrize("ext,", ['.xls']) | ||
class TestXlwtTests: | ||
|
||
def test_excel_raise_error_on_multiindex_columns_and_no_index( | ||
self, merge_cells, ext, engine): | ||
self, ext): | ||
# MultiIndex as columns is not yet implemented 9794 | ||
cols = MultiIndex.from_tuples([('site', ''), | ||
('2014', 'height'), | ||
|
@@ -2197,16 +2195,15 @@ def test_excel_raise_error_on_multiindex_columns_and_no_index( | |
with ensure_clean(ext) as path: | ||
df.to_excel(path, index=False) | ||
|
||
def test_excel_multiindex_columns_and_index_true(self, merge_cells, ext, | ||
engine): | ||
def test_excel_multiindex_columns_and_index_true(self, ext): | ||
cols = MultiIndex.from_tuples([('site', ''), | ||
('2014', 'height'), | ||
('2014', 'weight')]) | ||
df = pd.DataFrame(np.random.randn(10, 3), columns=cols) | ||
with ensure_clean(ext) as path: | ||
df.to_excel(path, index=True) | ||
|
||
def test_excel_multiindex_index(self, merge_cells, ext, engine): | ||
def test_excel_multiindex_index(self, ext): | ||
# MultiIndex as index works so assert no error #9794 | ||
cols = MultiIndex.from_tuples([('site', ''), | ||
('2014', 'height'), | ||
|
@@ -2215,7 +2212,7 @@ def test_excel_multiindex_index(self, merge_cells, ext, engine): | |
with ensure_clean(ext) as path: | ||
df.to_excel(path, index=False) | ||
|
||
def test_to_excel_styleconverter(self, merge_cells, ext, engine): | ||
def test_to_excel_styleconverter(self, ext): | ||
import xlwt | ||
|
||
hstyle = {"font": {"bold": True}, | ||
|
@@ -2234,21 +2231,20 @@ def test_to_excel_styleconverter(self, merge_cells, ext, engine): | |
assert xlwt.Alignment.HORZ_CENTER == xls_style.alignment.horz | ||
assert xlwt.Alignment.VERT_TOP == xls_style.alignment.vert | ||
|
||
def test_write_append_mode_raises(self, merge_cells, ext, engine): | ||
def test_write_append_mode_raises(self, ext): | ||
msg = "Append mode is not supported with xlwt!" | ||
|
||
with ensure_clean(ext) as f: | ||
with pytest.raises(ValueError, match=msg): | ||
ExcelWriter(f, engine=engine, mode='a') | ||
ExcelWriter(f, engine='xlwt', mode='a') | ||
|
||
|
||
@td.skip_if_no('xlsxwriter') | ||
@pytest.mark.parametrize("merge_cells,ext,engine", [ | ||
(None, '.xlsx', 'xlsxwriter')]) | ||
class TestXlsxWriterTests(_WriterBase): | ||
@pytest.mark.parametrize("ext", ['.xlsx']) | ||
class TestXlsxWriterTests: | ||
|
||
@td.skip_if_no('openpyxl') | ||
def test_column_format(self, merge_cells, ext, engine): | ||
def test_column_format(self, ext): | ||
# Test that column formats are applied to cells. Test for issue #9167. | ||
# Applicable to xlsxwriter only. | ||
with warnings.catch_warnings(): | ||
|
@@ -2292,12 +2288,12 @@ def test_column_format(self, merge_cells, ext, engine): | |
|
||
assert read_num_format == num_format | ||
|
||
def test_write_append_mode_raises(self, merge_cells, ext, engine): | ||
def test_write_append_mode_raises(self, ext): | ||
msg = "Append mode is not supported with xlsxwriter!" | ||
|
||
with ensure_clean(ext) as f: | ||
with pytest.raises(ValueError, match=msg): | ||
ExcelWriter(f, engine=engine, mode='a') | ||
ExcelWriter(f, engine='xlsxwriter', mode='a') | ||
|
||
|
||
class TestExcelWriterEngineTests: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a user-facing bug but trying to import any of the ExcelWriter subclasses would exhibit rather surprising behavior which causes a test failure when getting rid of the subclassing. For instance:
From the comment directly preceding this it appears this condition was backwards, so changed as such