Skip to content

Commit 077efe7

Browse files
committed
enhancement: Wrapped encoding into kwargs for xlrd lib (closes pandas-dev#23444)
1 parent 2cb6709 commit 077efe7

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

pandas/io/excel.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ def read_excel(io,
303303
skipfooter=0,
304304
convert_float=True,
305305
**kwds):
306-
encoding = kwds.get("encoding")
307306
# Can't use _deprecate_kwarg since sheetname=None has a special meaning
308307
if is_integer(sheet_name) and sheet_name == 0 and 'sheetname' in kwds:
309308
warnings.warn("The `sheetname` keyword is deprecated, use "
@@ -315,7 +314,7 @@ def read_excel(io,
315314
"`sheet`")
316315

317316
if not isinstance(io, ExcelFile):
318-
io = ExcelFile(io, engine=engine, encoding=encoding)
317+
io = ExcelFile(io, engine=engine, **kwds)
319318

320319
return io.parse(
321320
sheet_name=sheet_name,
@@ -356,9 +355,8 @@ class ExcelFile(object):
356355
"""
357356

358357
def __init__(self, io, **kwds):
359-
358+
kwargs = {'encoding_override': kwds.get("encoding")}
360359
err_msg = "Install xlrd >= 0.9.0 for Excel support"
361-
encoding = kwds.get("encoding")
362360
try:
363361
import xlrd
364362
except ImportError:
@@ -400,15 +398,9 @@ def __init__(self, io, **kwds):
400398
pass
401399

402400
data = io.read()
403-
if encoding:
404-
self.book = xlrd.open_workbook(file_contents=data, encoding_override=encoding)
405-
else:
406-
self.book = xlrd.open_workbook(file_contents=data)
401+
self.book = xlrd.open_workbook(file_contents=data, **kwargs)
407402
elif isinstance(self._io, compat.string_types):
408-
if encoding:
409-
self.book = xlrd.open_workbook(self._io, encoding_override=encoding)
410-
else:
411-
self.book = xlrd.open_workbook(self._io)
403+
self.book = xlrd.open_workbook(self._io, **kwargs)
412404
else:
413405
raise ValueError('Must explicitly set engine if not passing in'
414406
' buffer or path for io.')

0 commit comments

Comments
 (0)