Skip to content

Commit d69f47b

Browse files
committed
FIX: if first argument in BaseExcelReader.__init__ is bytes, create a buffer
1 parent 4f019ad commit d69f47b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pandas/io/excel/_base.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ def read_excel(
404404

405405
class BaseExcelReader(metaclass=abc.ABCMeta):
406406
def __init__(self, filepath_or_buffer, storage_options: StorageOptions = None):
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)
407410
self.handles = IOHandles(
408411
handle=filepath_or_buffer, compression={"method": None}
409412
)
@@ -422,8 +425,6 @@ def __init__(self, filepath_or_buffer, storage_options: StorageOptions = None):
422425
except Exception:
423426
self.close()
424427
raise
425-
elif isinstance(self.handles.handle, bytes):
426-
self.book = self.load_workbook(BytesIO(self.handles.handle))
427428
else:
428429
raise ValueError(
429430
"Must explicitly set engine if not passing in buffer or path for io."

0 commit comments

Comments
 (0)