Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Adds to_excel to save excel files to s3 #22

Merged
merged 3 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas_ext/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Versioning kept here."""
__version__ = '0.4.9'
__version__ = '0.4.11'
__license__ = "MIT"

__title__ = "pandas_ext"
Expand Down
1 change: 0 additions & 1 deletion pandas_ext/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ def to_csv(df: pd.DataFrame, path: str, **kwargs) -> None:
return dest.write(bytes_to_write)

return df.to_csv(path, **kwargs)

16 changes: 16 additions & 0 deletions pandas_ext/excel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pandas as pd
import s3fs

from pandas_ext.common.utils import is_s3_path


def to_excel(df: pd.DataFrame, path: str, **kwargs) -> None:
"""Given a df, write it to s3 if necessary."""
if is_s3_path(path):
bytes_to_write = df.to_excel(None, **kwargs).encode()

s3 = s3fs.S3FileSystem()
with s3.open(path, 'wb') as dest:
return dest.write(bytes_to_write)

return df.to_excel(path, **kwargs)