1818from pandas .io .parsers import TextParser
1919from pandas .errors import EmptyDataError
2020from 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 )
2223from pandas .core .indexes .period import Period
2324import pandas ._libs .json as json
2425from pandas .compat import (map , zip , reduce , range , lrange , u , add_metaclass ,
@@ -233,7 +234,7 @@ def __init__(self, io, **kwds):
233234 raise ImportError ("pandas requires xlrd >= 0.9.0 for excel "
234235 "support, current version " + xlrd .__VERSION__ )
235236
236- self .io = io
237+ self .io = _stringify_path ( io )
237238
238239 engine = kwds .pop ('engine' , None )
239240
@@ -242,19 +243,19 @@ def __init__(self, io, **kwds):
242243
243244 # If io is a url, want to keep the data as bytes so can't pass
244245 # 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" ):
253254 # N.B. xlrd.Book has a read attribute too
254- data = io .read ()
255+ data = self . io .read ()
255256 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 )
258259 else :
259260 raise ValueError ('Must explicitly set engine if not passing in'
260261 ' buffer or path for io.' )
0 commit comments