Repository: pandas-dev/pandas

Issue:
Excel Module Cleanups
As called out by @gfyoung in review there are some easy opportunities to clean up and simplify the existing Excel IO modules. These are mostly minor loop refactors and docstring updates

https://github.com/pandas-dev/pandas/pull/25153#pullrequestreview-200888051




Discussion:

Resolving patch:
diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py
--- a/pandas/io/excel/_base.py
+++ b/pandas/io/excel/_base.py
@@ -590,9 +590,8 @@ def __new__(cls, path, engine=None, **kwargs):
                     if engine == 'auto':
                         engine = _get_default_writer(ext)
                 except KeyError:
-                    error = ValueError("No engine for filetype: '{ext}'"
-                                       .format(ext=ext))
-                    raise error
+                    raise ValueError("No engine for filetype: '{ext}'"
+                                     .format(ext=ext))
             cls = get_writer(engine)
 
         return object.__new__(cls)
diff --git a/pandas/io/excel/_util.py b/pandas/io/excel/_util.py
--- a/pandas/io/excel/_util.py
+++ b/pandas/io/excel/_util.py
@@ -5,32 +5,39 @@
 
 from pandas.core.dtypes.common import is_integer, is_list_like
 
-from pandas.core import config
-
-_writer_extensions = ["xlsx", "xls", "xlsm"]
-
-
 _writers = {}
 
 
 def register_writer(klass):
-    """Adds engine to the excel writer registry. You must use this method to
-    integrate with ``to_excel``. Also adds config options for any new
-    ``supported_extensions`` defined on the writer."""
+    """
+    Add engine to the excel writer registry.io.excel.
+
+    You must use this method to integrate with ``to_excel``.
+
+    Parameters
+    ----------
+    klass : ExcelWriter
+    """
     if not callable(klass):
         raise ValueError("Can only register callables as engines")
     engine_name = klass.engine
     _writers[engine_name] = klass
-    for ext in klass.supported_extensions:
-        if ext.startswith('.'):
-            ext = ext[1:]
-        if ext not in _writer_extensions:
-            config.register_option("io.excel.{ext}.writer".format(ext=ext),
-                                   engine_name, validator=str)
-            _writer_extensions.append(ext)
 
 
 def _get_default_writer(ext):
+    """
+    Return the default writer for the given extension.
+
+    Parameters
+    ----------
+    ext : str
+        The excel file extension for which to get the default engine.
+
+    Returns
+    -------
+    str
+        The default engine for the extension.
+    """
     _default_writers = {'xlsx': 'openpyxl', 'xlsm': 'openpyxl', 'xls': 'xlwt'}
     try:
         import xlsxwriter  # noqa
@@ -230,8 +237,6 @@ def _fill_mi_header(row, control_row):
 
     return _maybe_convert_to_string(row), control_row
 
-# fill blank if index_col not None
-
 
 def _pop_header_name(row, index_col):
     """


Test patch:
diff --git a/pandas/tests/io/test_excel.py b/pandas/tests/io/test_excel.py
--- a/pandas/tests/io/test_excel.py
+++ b/pandas/tests/io/test_excel.py
@@ -2359,7 +2359,7 @@ def test_register_writer(self):
         class DummyClass(ExcelWriter):
             called_save = False
             called_write_cells = False
-            supported_extensions = ['test', 'xlsx', 'xls']
+            supported_extensions = ['xlsx', 'xls']
             engine = 'dummy'
 
             def save(self):
@@ -2377,12 +2377,9 @@ def check_called(func):
 
         with pd.option_context('io.excel.xlsx.writer', 'dummy'):
             register_writer(DummyClass)
-            writer = ExcelWriter('something.test')
+            writer = ExcelWriter('something.xlsx')
             assert isinstance(writer, DummyClass)
             df = tm.makeCustomDataframe(1, 1)
-
-            func = lambda: df.to_excel('something.test')
-            check_called(func)
             check_called(lambda: df.to_excel('something.xlsx'))
             check_called(
                 lambda: df.to_excel(