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

Commit

Permalink
Merge pull request #22 from newsela/add-to_excel
Browse files Browse the repository at this point in the history
Adds to_excel to save excel files to s3
  • Loading branch information
richiverse authored Mar 20, 2019
2 parents a297d20 + 280ac05 commit 9c42f89
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
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.10'
__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)

0 comments on commit 9c42f89

Please sign in to comment.