File tree 2 files changed +11
-7
lines changed
2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,8 @@ Documentation Changes
86
86
Bug Fixes
87
87
~~~~~~~~~
88
88
89
+ - Bug in ``pd.read_msgpack()`` with a non existent file is passed in Python 2 (:issue:`15296`)
90
+
89
91
Conversion
90
92
^^^^^^^^^^
91
93
Original file line number Diff line number Diff line change @@ -192,7 +192,6 @@ def read(fh):
192
192
193
193
# see if we have an actual file
194
194
if isinstance (path_or_buf , compat .string_types ):
195
-
196
195
try :
197
196
exists = os .path .exists (path_or_buf )
198
197
except (TypeError , ValueError ):
@@ -202,18 +201,21 @@ def read(fh):
202
201
with open (path_or_buf , 'rb' ) as fh :
203
202
return read (fh )
204
203
205
- # treat as a binary-like
206
204
if isinstance (path_or_buf , compat .binary_type ):
205
+ # treat as a binary-like
207
206
fh = None
208
207
try :
209
- fh = compat .BytesIO (path_or_buf )
210
- return read (fh )
208
+ # We can't distinguish between a path and a buffer of bytes in
209
+ # Python 2 so instead assume the first byte of a valid path is
210
+ # less than 0x80.
211
+ if compat .PY3 or ord (path_or_buf [0 ]) >= 0x80 :
212
+ fh = compat .BytesIO (path_or_buf )
213
+ return read (fh )
211
214
finally :
212
215
if fh is not None :
213
216
fh .close ()
214
-
215
- # a buffer like
216
- if hasattr (path_or_buf , 'read' ) and compat .callable (path_or_buf .read ):
217
+ elif hasattr (path_or_buf , 'read' ) and compat .callable (path_or_buf .read ):
218
+ # treat as a buffer like
217
219
return read (path_or_buf )
218
220
219
221
raise ValueError ('path_or_buf needs to be a string file path or file-like' )
You can’t perform that action at this time.
0 commit comments