Simplify TextIOWrapper usage · pandas-dev/pandas@640dc1b (original) (raw)

Original file line number Diff line number Diff line change
@@ -359,14 +359,6 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
359 359
360 360 handles.append(f)
361 361
362 -# In Python 3
363 -if compat.PY3:
364 -from io import TextIOWrapper
365 -f = TextIOWrapper(f, encoding=encoding)
366 -handles.append(f)
367 -
368 -return f, handles
369 -
370 362 elif is_path:
371 363 if compat.PY2:
372 364 # Python 2
@@ -380,7 +372,7 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
380 372 handles.append(f)
381 373
382 374 # in Python 3, convert BytesIO or fileobjects passed with an encoding
383 -if compat.PY3 and isinstance(path_or_buf, compat.BytesIO):
375 +if compat.PY3 and (compression or isinstance(f, compat.BytesIO)):
384 376 from io import TextIOWrapper
385 377 f = TextIOWrapper(f, encoding=encoding)
386 378 handles.append(f)