18
18
from pandas .io .parsers import TextParser
19
19
from pandas .errors import EmptyDataError
20
20
from pandas .io .common import (_is_url , _urlopen , _validate_header_arg ,
21
- get_filepath_or_buffer , _NA_VALUES )
21
+ get_filepath_or_buffer , _NA_VALUES ,
22
+ _stringify_path )
22
23
from pandas .core .indexes .period import Period
23
24
import pandas ._libs .json as json
24
25
from pandas .compat import (map , zip , reduce , range , lrange , u , add_metaclass ,
@@ -233,7 +234,7 @@ def __init__(self, io, **kwds):
233
234
raise ImportError ("pandas requires xlrd >= 0.9.0 for excel "
234
235
"support, current version " + xlrd .__VERSION__ )
235
236
236
- self .io = io
237
+ self .io = _stringify_path ( io )
237
238
238
239
engine = kwds .pop ('engine' , None )
239
240
@@ -242,19 +243,19 @@ def __init__(self, io, **kwds):
242
243
243
244
# If io is a url, want to keep the data as bytes so can't pass
244
245
# to get_filepath_or_buffer()
245
- if _is_url (io ):
246
- io = _urlopen (io )
247
- elif not isinstance (io , (ExcelFile , xlrd .Book )):
248
- io , _ , _ = get_filepath_or_buffer (io )
249
-
250
- if engine == 'xlrd' and isinstance (io , xlrd .Book ):
251
- self .book = io
252
- elif not isinstance (io , xlrd .Book ) and hasattr (io , "read" ):
246
+ if _is_url (self . io ):
247
+ self . io = _urlopen (self . io )
248
+ elif not isinstance (self . io , (ExcelFile , xlrd .Book )):
249
+ self . io , _ , _ = get_filepath_or_buffer (self . io )
250
+
251
+ if engine == 'xlrd' and isinstance (self . io , xlrd .Book ):
252
+ self .book = self . io
253
+ elif not isinstance (self . io , xlrd .Book ) and hasattr (self . io , "read" ):
253
254
# N.B. xlrd.Book has a read attribute too
254
- data = io .read ()
255
+ data = self . io .read ()
255
256
self .book = xlrd .open_workbook (file_contents = data )
256
- elif isinstance (io , compat .string_types ):
257
- self .book = xlrd .open_workbook (io )
257
+ elif isinstance (self . io , compat .string_types ):
258
+ self .book = xlrd .open_workbook (self . io )
258
259
else :
259
260
raise ValueError ('Must explicitly set engine if not passing in'
260
261
' buffer or path for io.' )
0 commit comments