From 4224e751c5b15339fa9467d4c0a84e41bd40b318 Mon Sep 17 00:00:00 2001 From: bra-fsn Date: Mon, 14 Jun 2021 15:29:52 +0200 Subject: [PATCH] Pandas has fixed this bug, adapt to it --- df_io/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/df_io/__init__.py b/df_io/__init__.py index 77462d4..db79aa5 100644 --- a/df_io/__init__.py +++ b/df_io/__init__.py @@ -1,8 +1,8 @@ import os import gzip +import io import shutil import tempfile -from io import TextIOWrapper import numpy as np import pandas as pd import s3fs @@ -14,7 +14,8 @@ def _writer_wrapper(writer, f, writer_args, writer_options): writer(f, *writer_args, **writer_options) except TypeError: # hack for https://github.com/pandas-dev/pandas/issues/19827 - f = TextIOWrapper(f) + # provide compatibility with older Pandas + f = io.TextIOWrapper(f) writer(f, *writer_args, **writer_options) return f @@ -102,11 +103,15 @@ def flush_and_close(f): f = _writer_wrapper(writer, f, writer_args, writer_options) # we have to write a newline after every rounds, so won't get # the new round started in the same line - f.write('\n') + # wrapper can return binary or text, act accordingly + if isinstance(f, (io.RawIOBase, io.BufferedIOBase)): + f.write(b'\n') + else: + f.write('\n') else: # in all other cases we're just calling the writer _writer_wrapper(writer, f, writer_args, writer_options) flush_and_close(f) -__version__ = '0.0.4' +__version__ = '0.0.5'