@@ -404,9 +404,10 @@ def read_excel(
404
404
405
405
class BaseExcelReader (metaclass = abc .ABCMeta ):
406
406
def __init__ (self , filepath_or_buffer , storage_options : StorageOptions = None ):
407
- self .handles = IOHandles (
408
- handle = filepath_or_buffer , compression = {"method" : None }
409
- )
407
+ # First argument can also be bytes, so create a buffer
408
+ if isinstance (filepath_or_buffer , bytes ):
409
+ filepath_or_buffer = BytesIO (filepath_or_buffer )
410
+
410
411
if not isinstance (filepath_or_buffer , (ExcelFile , self ._workbook_class )):
411
412
self .handles = get_handle (
412
413
filepath_or_buffer , "rb" , storage_options = storage_options , is_text = False
@@ -422,8 +423,6 @@ def __init__(self, filepath_or_buffer, storage_options: StorageOptions = None):
422
423
except Exception :
423
424
self .close ()
424
425
raise
425
- elif isinstance (self .handles .handle , bytes ):
426
- self .book = self .load_workbook (BytesIO (self .handles .handle ))
427
426
else :
428
427
raise ValueError (
429
428
"Must explicitly set engine if not passing in buffer or path for io."
@@ -1111,7 +1110,7 @@ class ExcelFile:
1111
1110
1112
1111
Parameters
1113
1112
----------
1114
- path_or_buffer : str, path object (pathlib.Path or py._path.local.LocalPath),
1113
+ path_or_buffer : str, bytes, path object (pathlib.Path or py._path.local.LocalPath),
1115
1114
a file-like object, xlrd workbook or openpyxl workbook.
1116
1115
If a string or path object, expected to be a path to a
1117
1116
.xls, .xlsx, .xlsb, .xlsm, .odf, .ods, or .odt file.
@@ -1170,6 +1169,10 @@ def __init__(
1170
1169
if engine is not None and engine not in self ._engines :
1171
1170
raise ValueError (f"Unknown engine: { engine } " )
1172
1171
1172
+ # First argument can also be bytes, so create a buffer
1173
+ if isinstance (path_or_buffer , bytes ):
1174
+ path_or_buffer = BytesIO (path_or_buffer )
1175
+
1173
1176
# Could be a str, ExcelFile, Book, etc.
1174
1177
self .io = path_or_buffer
1175
1178
# Always a string
0 commit comments