File tree 3 files changed +22
-6
lines changed
3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -131,3 +131,4 @@ Bug Fixes
131
131
- Bug in ``DatetimeIndex`` and ``PeriodIndex.value_counts`` resets name from its result, but retains in result's ``Index``. (:issue:`10150`)
132
132
133
133
- Bug in `pandas.concat` with ``axis=0`` when column is of dtype ``category`` (:issue:`10177`)
134
+ - Bug in ``read_msgpack`` where input type is not always checked (:issue:`10369`)
Original file line number Diff line number Diff line change @@ -141,24 +141,28 @@ def read(fh):
141
141
142
142
try :
143
143
exists = os .path .exists (path_or_buf )
144
- except (TypeError ,ValueError ):
144
+ except (TypeError , ValueError ):
145
145
exists = False
146
146
147
147
if exists :
148
148
with open (path_or_buf , 'rb' ) as fh :
149
149
return read (fh )
150
150
151
- # treat as a string -like
152
- if not hasattr (path_or_buf , 'read' ):
153
-
151
+ # treat as a binary -like
152
+ if isinstance (path_or_buf , compat . binary_type ):
153
+ fh = None
154
154
try :
155
155
fh = compat .BytesIO (path_or_buf )
156
156
return read (fh )
157
157
finally :
158
- fh .close ()
158
+ if fh is not None :
159
+ fh .close ()
159
160
160
161
# a buffer like
161
- return read (path_or_buf )
162
+ if hasattr (path_or_buf , 'read' ) and compat .callable (path_or_buf .read ):
163
+ return read (path_or_buf )
164
+
165
+ raise ValueError ('path_or_buf needs to be a string file path or file-like' )
162
166
163
167
dtype_dict = {21 : np .dtype ('M8[ns]' ),
164
168
u ('datetime64[ns]' ): np .dtype ('M8[ns]' ),
Original file line number Diff line number Diff line change @@ -93,6 +93,17 @@ def test_iterator_with_string_io(self):
93
93
for i , result in enumerate (read_msgpack (s ,iterator = True )):
94
94
tm .assert_frame_equal (result ,dfs [i ])
95
95
96
+ def test_invalid_arg (self ):
97
+ #GH10369
98
+ class A (object ):
99
+ def __init__ (self ):
100
+ self .read = 0
101
+
102
+ tm .assertRaises (ValueError , read_msgpack , path_or_buf = None )
103
+ tm .assertRaises (ValueError , read_msgpack , path_or_buf = {})
104
+ tm .assertRaises (ValueError , read_msgpack , path_or_buf = A ())
105
+
106
+
96
107
class TestNumpy (TestPackers ):
97
108
98
109
def test_numpy_scalar_float (self ):
You can’t perform that action at this time.
0 commit comments