Skip to content

Commit

Permalink
fix: Don't save dataframe if empty, closes #32
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed May 6, 2022
1 parent 7da376e commit 9b83348
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

0.3.9 (Unreleased)
------------------

Changed
~~~~~~~

- :func:`~ocdskingfishercolab.save_dataframe_to_sheet` and :func:`save_dataframe_to_spreadsheet` do nothing if the data frame is empty.

0.3.8 (2022-04-27)
------------------

Expand Down
10 changes: 9 additions & 1 deletion ocdskingfishercolab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ def save_dataframe_to_sheet(dataframe, sheetname, prompt=True):
:param str sheetname: a sheet name
:param bool prompt: whether to prompt the user
"""
if prompt is False or input('Save to Google Sheets? (y/N)') == 'y':
if dataframe.empty:
print('Data frame is empty.')
return

if not prompt or input('Save to Google Sheets? (y/N)') == 'y':
gc = authenticate_gspread()
try:
sheet = gc.open(spreadsheet_name)
Expand All @@ -187,6 +191,10 @@ def save_dataframe_to_spreadsheet(dataframe, name):
:param pandas.DataFrame dataframe: a data frame
:param str name: the basename of the Excel file to write
"""
if dataframe.empty:
print('Data frame is empty.')
return

write_data_as_json(dataframe['release_package'][0], 'release_package.json')

with warnings.catch_warnings():
Expand Down
1 change: 0 additions & 1 deletion tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ def test_save_dataframe_to_spreadsheet(save, capsys, tmpdir):
save.assert_called_once_with({'title': 'yet_another_excel_file.xlsx'}, 'flattened.xlsx')


@pytest.mark.xfail()
@patch('ocdskingfishercolab._save_file_to_drive')
def test_save_dataframe_to_spreadsheet_empty(save, capsys, tmpdir):
df = pandas.DataFrame()
Expand Down

0 comments on commit 9b83348

Please sign in to comment.