Skip to content

Commit

Permalink
Pandas has fixed this bug, adapt to it
Browse files Browse the repository at this point in the history
  • Loading branch information
bra-fsn committed Jun 14, 2021
1 parent cd85199 commit 4224e75
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions df_io/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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'

0 comments on commit 4224e75

Please sign in to comment.