@@ -72,6 +72,8 @@ def get_writer(engine_name):
7272class BaseFile (object ):
7373 """ Class for identifying the type of reader
7474 """
75+ # added in order to deal with both Open Document Format and MS Excel
76+ # fil types, see PR #9070
7577
7678 def __init__ (self , engine , extensions , io_class , open_workbook ,
7779 try_engine = False ):
@@ -272,21 +274,22 @@ def __init__(self, io, **kwds):
272274 self .book = io
273275 return
274276
275- if self .engine == xlrd_f .engine :
277+ if self .engine == xlrd_f .engine and isinstance ( io , xlrd_f . io_class ) :
276278 # force import error when necessary
277279 import xlrd
278- self .book = xlrd_f .open_workbook (io )
279- elif self .engine == ezodf_f .engine :
280- # force import error when necessary
281- import ezodf
282- self .book = ezodf_f .open_workbook (io )
283- elif hasattr (io , "read" ):
280+ self .book = io
281+ elif not isinstance (io , xlrd_f .io_class ) and hasattr (io , "read" ):
284282 # N.B. xlrd.Book has a read attribute too
285283 data = io .read ()
286- # this only works with xlrd
287284 import xlrd
288285 self .book = xlrd .open_workbook (file_contents = data )
289286 self .engine = 'xlrd'
287+ elif self .engine == xlrd_f .engine :
288+ self .book = xlrd_f .open_workbook (io )
289+ elif self .engine == ezodf_f .engine :
290+ # force import error when necessary
291+ import ezodf
292+ self .book = ezodf_f .open_workbook (io )
290293 else :
291294 raise ValueError ('Must explicitly set engine if not passing in'
292295 ' buffer or path for io.' )
@@ -546,6 +549,7 @@ def _parse_ods(self, sheetname=0, header=0, skiprows=None, skip_footer=0,
546549 parse_dates = False , date_parser = None , na_values = None ,
547550 thousands = None , chunksize = None , convert_float = True ,
548551 verbose = False , ** kwds ):
552+ # adds support for parsing ODS files, see PR #9070
549553
550554 def _parse_cell (cell ):
551555 """converts the contents of the cell into a pandas
0 commit comments