Skip to content

Commit

Permalink
Raise ValueError on deg with not enough columns.
Browse files Browse the repository at this point in the history
Fixes #37
  • Loading branch information
apmcleod committed Aug 30, 2020
1 parent 5e5d62d commit 21fdef5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion mdtk/degradations.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,18 @@ def pre_process(df, sort=False):
-------
df : pd.DataFrame
The postprocessed dataframe.
Raises
------
ValueError
If the given df does not have all of the necessary columns.
"""
df = df.loc[:, NOTE_DF_SORT_ORDER]
try:
df = df.loc[:, NOTE_DF_SORT_ORDER]
except KeyError: # df has incorrect columns
raise ValueError(
f"Input note_df must have all of the columns: {NOTE_DF_SORT_ORDER}"
)
if sort:
df = df.sort_values(NOTE_DF_SORT_ORDER)
df = df.reset_index(drop=True)
Expand Down
5 changes: 5 additions & 0 deletions mdtk/tests/test_degradations.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ def test_pre_process():
f"instead of \n{float_res}"
)

# Check not correct columns raises ValueError
invalid_df = pd.DataFrame({"track": [0, 1], "onset": [0, 50], "pitch": [10, 20]})
with pytest.raises(ValueError):
deg.pre_process(invalid_df)


def test_post_process():
basic_res = pd.DataFrame(
Expand Down

0 comments on commit 21fdef5

Please sign in to comment.