|
15 | 15 |
|
16 | 16 | from pandas.io.common import _is_url, urlopen, parse_url
|
17 | 17 | from pandas.io.parsers import TextParser
|
18 |
| -from pandas.compat import (lrange, lmap, u, string_types, iteritems, text_type, |
19 |
| - raise_with_traceback) |
| 18 | +from pandas.compat import (lrange, lmap, u, string_types, iteritems, |
| 19 | + raise_with_traceback, binary_type) |
20 | 20 | from pandas.core import common as com
|
21 | 21 | from pandas import Series
|
22 | 22 |
|
|
51 | 51 | _RE_WHITESPACE = re.compile(r'[\r\n]+|\s{2,}')
|
52 | 52 |
|
53 | 53 |
|
| 54 | +char_types = string_types + (binary_type,) |
| 55 | + |
| 56 | + |
54 | 57 | def _remove_whitespace(s, regex=_RE_WHITESPACE):
|
55 | 58 | """Replace extra whitespace inside of a string with a single space.
|
56 | 59 |
|
@@ -114,13 +117,13 @@ def _read(obj):
|
114 | 117 | text = url.read()
|
115 | 118 | elif hasattr(obj, 'read'):
|
116 | 119 | text = obj.read()
|
117 |
| - elif isinstance(obj, string_types): |
| 120 | + elif isinstance(obj, char_types): |
118 | 121 | text = obj
|
119 | 122 | try:
|
120 | 123 | if os.path.isfile(text):
|
121 | 124 | with open(text, 'rb') as f:
|
122 | 125 | return f.read()
|
123 |
| - except TypeError: |
| 126 | + except (TypeError, ValueError): |
124 | 127 | pass
|
125 | 128 | else:
|
126 | 129 | raise TypeError("Cannot read object of type %r" % type(obj).__name__)
|
|
0 commit comments