|
12 | 12 | from pandas.core.common import AbstractMethodError
|
13 | 13 | from pandas.types.common import is_number
|
14 | 14 |
|
| 15 | +try: |
| 16 | + from s3fs import S3File |
| 17 | + need_text_wrapping = (BytesIO, S3File) |
| 18 | +except ImportError: |
| 19 | + need_text_wrapping = (BytesIO,) |
| 20 | + |
15 | 21 | # common NA values
|
16 | 22 | # no longer excluding inf representations
|
17 | 23 | # '1.#INF','-1.#INF', '1.#INF000000',
|
@@ -212,10 +218,10 @@ def get_filepath_or_buffer(filepath_or_buffer, encoding=None,
|
212 | 218 | return reader, encoding, compression
|
213 | 219 |
|
214 | 220 | if _is_s3_url(filepath_or_buffer):
|
215 |
| - from pandas.io.s3 import get_filepath_or_buffer |
216 |
| - return get_filepath_or_buffer(filepath_or_buffer, |
217 |
| - encoding=encoding, |
218 |
| - compression=compression) |
| 221 | + from pandas.io import s3 |
| 222 | + return s3.get_filepath_or_buffer(filepath_or_buffer, |
| 223 | + encoding=encoding, |
| 224 | + compression=compression) |
219 | 225 |
|
220 | 226 | # It is a pathlib.Path/py.path.local or string
|
221 | 227 | filepath_or_buffer = _stringify_path(filepath_or_buffer)
|
@@ -391,7 +397,7 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
|
391 | 397 | handles.append(f)
|
392 | 398 |
|
393 | 399 | # in Python 3, convert BytesIO or fileobjects passed with an encoding
|
394 |
| - if compat.PY3 and (compression or isinstance(f, compat.BytesIO)): |
| 400 | + if compat.PY3 and (compression or isinstance(f, need_text_wrapping)): |
395 | 401 | from io import TextIOWrapper
|
396 | 402 | f = TextIOWrapper(f, encoding=encoding)
|
397 | 403 | handles.append(f)
|
|
0 commit comments