diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 3af6be7a371e7..24412b26b021b 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -591,7 +591,7 @@ class ExcelWriter(metaclass=abc.ABCMeta): def __new__(cls, path, engine=None, **kwargs): # only switch class if generic(ExcelWriter) - if issubclass(cls, ExcelWriter): + if cls is ExcelWriter: if engine is None or (isinstance(engine, str) and engine == 'auto'): if isinstance(path, str): diff --git a/pandas/tests/io/test_excel.py b/pandas/tests/io/test_excel.py index 100de227aa97c..8b871caae58a6 100644 --- a/pandas/tests/io/test_excel.py +++ b/pandas/tests/io/test_excel.py @@ -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']) +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,8 +2195,7 @@ 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')]) @@ -2206,7 +2203,7 @@ def test_excel_multiindex_columns_and_index_true(self, merge_cells, ext, 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: