@@ -72,6 +72,8 @@ def get_writer(engine_name):
72
72
class BaseFile (object ):
73
73
""" Class for identifying the type of reader
74
74
"""
75
+ # added in order to deal with both Open Document Format and MS Excel
76
+ # fil types, see PR #9070
75
77
76
78
def __init__ (self , engine , extensions , io_class , open_workbook ,
77
79
try_engine = False ):
@@ -272,21 +274,22 @@ def __init__(self, io, **kwds):
272
274
self .book = io
273
275
return
274
276
275
- if self .engine == xlrd_f .engine :
277
+ if self .engine == xlrd_f .engine and isinstance ( io , xlrd_f . io_class ) :
276
278
# force import error when necessary
277
279
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" ):
284
282
# N.B. xlrd.Book has a read attribute too
285
283
data = io .read ()
286
- # this only works with xlrd
287
284
import xlrd
288
285
self .book = xlrd .open_workbook (file_contents = data )
289
286
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 )
290
293
else :
291
294
raise ValueError ('Must explicitly set engine if not passing in'
292
295
' buffer or path for io.' )
@@ -546,6 +549,7 @@ def _parse_ods(self, sheetname=0, header=0, skiprows=None, skip_footer=0,
546
549
parse_dates = False , date_parser = None , na_values = None ,
547
550
thousands = None , chunksize = None , convert_float = True ,
548
551
verbose = False , ** kwds ):
552
+ # adds support for parsing ODS files, see PR #9070
549
553
550
554
def _parse_cell (cell ):
551
555
"""converts the contents of the cell into a pandas
0 commit comments