Skip to content

Commit 6df1753

Browse files
committed
Delay excel, probably broken
1 parent 3b3564e commit 6df1753

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

pandas/core/config_init.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,23 @@ def _register_xlsx(engine, other):
458458
others=", '%s'" % other),
459459
validator=str)
460460

461-
try:
462-
# better memory footprint
463-
import xlsxwriter # noqa
464-
_register_xlsx('xlsxwriter', 'openpyxl')
465-
except ImportError:
466-
# fallback
467-
_register_xlsx('openpyxl', 'xlsxwriter')
461+
_excel_registered = False
462+
463+
464+
def _register_excel_engines():
465+
global _excel_registered
466+
467+
if not _excel_registered:
468+
with cf.config_prefix('io.excel'):
469+
try:
470+
# better memory footprint
471+
import xlsxwriter # noqa
472+
_register_xlsx('xlsxwriter', 'openpyxl')
473+
except ImportError:
474+
# fallback
475+
_register_xlsx('openpyxl', 'xlsxwriter')
476+
_excel_registered = True
477+
468478

469479
# Set up the io.parquet specific configuration.
470480
parquet_engine_doc = """

pandas/io/common.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
# gh-12665: Alias for now and remove later.
2020
CParserError = ParserError
2121

22-
23-
try:
24-
from s3fs import S3File
25-
need_text_wrapping = (BytesIO, S3File)
26-
except ImportError:
27-
need_text_wrapping = (BytesIO,)
28-
2922
# common NA values
3023
# no longer excluding inf representations
3124
# '1.#INF','-1.#INF', '1.#INF000000',
@@ -322,6 +315,11 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
322315
handles : list of file-like objects
323316
A list of file-like object that were openned in this function.
324317
"""
318+
try:
319+
from s3fs import S3File
320+
need_text_wrapping = (BytesIO, S3File)
321+
except ImportError:
322+
need_text_wrapping = (BytesIO,)
325323

326324
handles = list()
327325
f = path_or_buf

pandas/io/excel.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import pandas._libs.json as json
2626
from pandas.compat import (map, zip, reduce, range, lrange, u, add_metaclass,
2727
string_types, OrderedDict)
28-
from pandas.core import config
28+
from pandas.core import config, config_init
2929
from pandas.io.formats.printing import pprint_thing
3030
import pandas.compat as compat
3131
import pandas.compat.openpyxl_compat as openpyxl_compat
@@ -690,6 +690,8 @@ class ExcelWriter(object):
690690
# ExcelWriter.
691691
def __new__(cls, path, engine=None, **kwargs):
692692
# only switch class if generic(ExcelWriter)
693+
config_init._register_excel_engines()
694+
693695
if issubclass(cls, ExcelWriter):
694696
if engine is None:
695697
if isinstance(path, string_types):

0 commit comments

Comments
 (0)