Skip to content

Commit

Permalink
Address comments of @gfyoung in pandas-dev#25153
Browse files Browse the repository at this point in the history
  • Loading branch information
tdamsma committed Feb 11, 2019
1 parent 3ab9318 commit 7bbe910
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 2 additions & 3 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions pandas/io/excel/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

from pandas.core import config

_writer_extensions = ["xlsx", "xls", "xlsm"]

# the following extensions are already registered in pandas/core/config_init.py
_registered_writer_extensions = ["xlsx", "xls", "xlsm"]


_writers = {}
Expand All @@ -24,13 +26,15 @@ def register_writer(klass):
for ext in klass.supported_extensions:
if ext.startswith('.'):
ext = ext[1:]
if ext not in _writer_extensions:
if ext not in _registered_writer_extensions:
config.register_option("io.excel.{ext}.writer".format(ext=ext),
engine_name, validator=str)
_writer_extensions.append(ext)
_registered_writer_extensions.append(ext)


def _get_default_writer(ext):
"""Return the default writer per extension. This default engine is used
unles another engine is explicitly defined."""
_default_writers = {'xlsx': 'openpyxl', 'xlsm': 'openpyxl', 'xls': 'xlwt'}
try:
import xlsxwriter # noqa
Expand Down Expand Up @@ -230,8 +234,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):
"""
Expand Down

0 comments on commit 7bbe910

Please sign in to comment.