Skip to content

Commit

Permalink
Add methods for pandas is_file_like check
Browse files Browse the repository at this point in the history
  • Loading branch information
bra-fsn committed Nov 29, 2021
1 parent f9b2c30 commit 572aca7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion df_io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def __init__(self, files, max_workers=None):
self._files = files
self._executor = ThreadPoolExecutor(max_workers)

def read(self):
raise NotImplemented("Can only write")

def write(self, data):
futures = {self._executor.submit(f.write, data): f for f in self._files}
for future in as_completed(futures):
Expand All @@ -46,6 +49,23 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, exc_traceback):
self.close()

def __iter__(self, *args, **kwargs):
"""Pandas is_file_like needs this to exist."""
raise NotImplementedError

def readable(self):
return False

def seekable(self):
return False

def writable(self):
return True

@property
def closed(self):
return all([x.closed for x in self._files])


def read_df(path, fmt="csv", reader_args=[], reader_options={}):
pd_reader = getattr(pd, 'read_{}'.format(fmt))
Expand Down Expand Up @@ -149,4 +169,4 @@ def flush_and_close(f):
flush_and_close(f)


__version__ = '0.0.7'
__version__ = '0.0.8'

0 comments on commit 572aca7

Please sign in to comment.