|
61 | 61 | from pandas.core.sparse.array import BlockIndex, IntIndex
|
62 | 62 | from pandas.core.generic import NDFrame
|
63 | 63 | from pandas.errors import PerformanceWarning
|
64 |
| -from pandas.io.common import get_filepath_or_buffer, _stringify_path |
| 64 | +from pandas.io.common import (get_filepath_or_buffer, _get_handle, |
| 65 | + _stringify_path) |
65 | 66 | from pandas.core.internals import BlockManager, make_block, _safe_reshape
|
66 | 67 | import pandas.core.internals as internals
|
67 | 68 |
|
@@ -186,39 +187,31 @@ def read_msgpack(path_or_buf, encoding='utf-8', iterator=False, **kwargs):
|
186 | 187 | return Iterator(path_or_buf)
|
187 | 188 |
|
188 | 189 | def read(fh):
|
| 190 | + print(fh) |
189 | 191 | l = list(unpack(fh, encoding=encoding, **kwargs))
|
190 | 192 | if len(l) == 1:
|
191 | 193 | return l[0]
|
192 | 194 | return l
|
193 | 195 |
|
194 |
| - # see if we have an actual file |
195 | 196 | if isinstance(path_or_buf, compat.string_types):
|
196 |
| - |
197 | 197 | try:
|
198 | 198 | exists = os.path.exists(path_or_buf)
|
| 199 | + |
| 200 | + # if the filepath is too long will raise here |
| 201 | + # 5874 |
199 | 202 | except (TypeError, ValueError):
|
200 | 203 | exists = False
|
201 | 204 |
|
202 | 205 | if exists:
|
203 | 206 | with open(path_or_buf, 'rb') as fh:
|
204 | 207 | return read(fh)
|
205 |
| - |
206 |
| - # treat as a binary-like |
207 |
| - if isinstance(path_or_buf, compat.binary_type): |
208 |
| - fh = None |
209 |
| - try: |
210 |
| - fh = compat.BytesIO(path_or_buf) |
211 |
| - return read(fh) |
212 |
| - finally: |
213 |
| - if fh is not None: |
214 |
| - fh.close() |
215 |
| - |
216 |
| - # a buffer like |
217 |
| - if hasattr(path_or_buf, 'read') and compat.callable(path_or_buf.read): |
| 208 | + elif hasattr(path_or_buf, 'read'): |
| 209 | + return read(path_or_buf) |
| 210 | + else: |
| 211 | + raise ValueError('path_or_buf needs to be a string file path or file-like') |
| 212 | + else: |
218 | 213 | return read(path_or_buf)
|
219 | 214 |
|
220 |
| - raise ValueError('path_or_buf needs to be a string file path or file-like') |
221 |
| - |
222 | 215 |
|
223 | 216 | dtype_dict = {21: np.dtype('M8[ns]'),
|
224 | 217 | u('datetime64[ns]'): np.dtype('M8[ns]'),
|
|
0 commit comments