copd-model-c / training /tests /test_calculate_days_since_last_event.py
IamGrooooot's picture
Initial release: 72-hour COPD exacerbation prediction model
e69d4e4
"""Unit tests for the calculate_days_since_last_event function."""
import copd
import pandas as pd
def test_output_equals_expected_exac():
"""Compare the output and expected dataframes."""
input_df = pd.DataFrame({'Date': pd.date_range('2022-01-01', '2022-01-15'),
'IsExac': [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]})
expected_df = pd.DataFrame({'Date': pd.date_range('2022-01-01', '2022-01-15'),
'IsExac': [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
'DaysSinceLastExac': [-1, -1, -1, 1, 2, 3, 1, 1, 2, 3, 4,
5, 6, 7, 8]})
output_df = copd.calculate_days_since_last_event(
df=input_df, event_col='IsExac', output_col='DaysSinceLastExac')
pd.testing.assert_frame_equal(output_df, expected_df)
def test_output_equals_expected_rescue_meds():
"""Compare the output and expected dataframes."""
input_df = pd.DataFrame({
'Date': pd.date_range('2022-02-01', '2022-02-15'),
'IsRescueMedExac': [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0]})
expected_df = pd.DataFrame({'Date': pd.date_range('2022-02-01', '2022-02-15'),
'IsRescueMedExac': [
0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0],
'DaysSinceLastRescueMeds': [
-1, -1, -1, 1, 2, 3, 1, 1, 2, 3, 4, 5, 1, 2, 3]})
output_df = copd.calculate_days_since_last_event(
df=input_df, event_col='IsRescueMedExac', output_col='DaysSinceLastRescueMeds')
pd.testing.assert_frame_equal(output_df, expected_df)