Skip to content

Commit

Permalink
Merge pull request #7 from SASlabgroup/fix_dataframe_with_no_files_error
Browse files Browse the repository at this point in the history
Fix dataframe with no files error
  • Loading branch information
jacobrdavis authored Aug 28, 2023
2 parents 21e056d + 67bf695 commit c87788e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions microSWIFTtelemetry/sbd/compile_sbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,24 @@ def compile_sbd(
if var_type == 'pandas':
df = pandas.DataFrame(data)
errors = pandas.DataFrame(errors)

if not df.empty:
to_pandas_datetime_index(df)
else:
warnings.warn("Empty DataFrame; if you expected data, make sure "
"the `buoy_id` is a valid microSWIFT ID and that "
"`start_date` and `end_date` are correct.")

if not errors.empty:
errors = errors.sort_values(by='file_name')
errors.reset_index(drop=True, inplace=True)

#TODO: concatenate dfs?
return df, errors

if var_type == 'xarray': # TODO: support for xarray
raise NotImplementedError('xarray is not supported yet')

#TODO: should this be 'dataframe' and 'dataset'?
raise ValueError("var_type can only be 'dict', 'pandas', or 'xarray'")


Expand All @@ -116,7 +123,6 @@ def to_pandas_datetime_index(
df[datetime_column] = to_datetime(df['datetime'], utc=True)
df.set_index('datetime', inplace=True)
df.sort_index(inplace=True)
# df.drop(['datetime'], axis=1, inplace=True)


def _combine_dict_list(dict_list):
Expand Down
2 changes: 1 addition & 1 deletion microSWIFTtelemetry/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Format expected by setup.py and doc/source/conf.py: string of form "X.Y.Z"
_version_major = 0
_version_minor = 3
_version_micro = 2 # use '' for first of series, number for 1 and above
_version_micro = 3 # use '' for first of series, number for 1 and above
# _version_extra = 'dev'
_version_extra = '' # TODO: Uncomment this for full releases

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup, find_packages
PACKAGES = find_packages()

# Get version and release info, which is all stored in littlebuoybigwaves/version.py
# Get version and release info from version.py
ver_file = os.path.join('microSWIFTtelemetry', 'version.py')
with open(ver_file) as f:
exec(f.read())
Expand Down

0 comments on commit c87788e

Please sign in to comment.