Skip to content

Commit

Permalink
feat: more informative errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBernstorff committed Dec 8, 2022
1 parent cfab77e commit 3141487
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/timeseriesflattener/flattened_ds_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ def _check_for_duplicate_rows(self):
col_subset=[self.id_col_name, self.timestamp_col_name],
):
raise ValueError(
"Duplicate patient/timestamp combinations in prediction_times_df, aborting",
"Duplicate id/timestamp combinations in prediction_times_df, aborting",
)

def _check_that_timestamp_and_id_columns_exist(self):
"""Check that the required columns are present in the initial
dataframe."""
dataframe.
"""

for col_name in (self.timestamp_col_name, self.id_col_name):
if col_name not in self.df.columns:
raise ValueError(
raise KeyError(
f"{col_name} does not exist in prediction_times_df, change the df or set another argument",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_col_does_not_exist_in_prediction_times():

prediction_times_df = str_to_df(prediction_times_str)

with pytest.raises(ValueError):
with pytest.raises(KeyError, match=r".*does not exist.*"):
TimeseriesFlattener( # noqa
prediction_times_df=prediction_times_df,
timestamp_col_name="timestamp",
Expand Down Expand Up @@ -60,10 +60,10 @@ def test_col_does_not_exist():


def test_duplicate_prediction_times():
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=r".*duplicate.*"):
prediction_times_df_str = """dw_ek_borger,timestamp,
1,2021-12-31 00:00:00
1,2021-11-31 00:00:00
1,2021-12-30 00:00:00
1,2021-12-30 00:00:00
"""

TimeseriesFlattener(
Expand Down

0 comments on commit 3141487

Please sign in to comment.