Skip to content

Commit

Permalink
Add tests of errors raised by prepare_input_dataframes
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegrabowski committed Sep 2, 2024
1 parent 130452a commit 98988fa
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions tests/test_disaggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,117 @@ def test_litterman_A_to_M(self):
self.assertEqual(expected, sales_m_litterman.to_frame())


def test_invalid_dataframe_warnings():
with pytest.raises(
ValueError,
match="No datetime index found on the dataframe passed as argument to low_freq_df",
):
disaggregate_series(
pd.DataFrame({"data": [1, 2, 3]}),
pd.DataFrame({"data": [1, 2, 3]}),
method="denton",
agg_func="sum",
)

with pytest.raises(
ValueError,
match="No datetime index found on the dataframe passed as argument to high_freq_df",
):
disaggregate_series(
pd.DataFrame(
{"data": [1, 2, 3]}, index=pd.date_range("2020-01-01", periods=3, freq="D")
),
pd.DataFrame({"data": [1, 2, 3]}),
method="denton",
agg_func="sum",
)

with pytest.raises(ValueError, match="low_freq_df has missing values"):
disaggregate_series(
pd.DataFrame(
{"data": [1, np.nan, 3]}, index=pd.date_range("2020-01-01", periods=3, freq="D")
),
pd.DataFrame(
{"data": [1, 2, 3]}, index=pd.date_range("2020-01-01", periods=3, freq="D")
),
method="denton",
agg_func="sum",
)

with pytest.raises(ValueError, match="high_freq_df has missing values"):
disaggregate_series(
pd.DataFrame(
{"data": [1, 2, 3]}, index=pd.date_range("2020-01-01", periods=3, freq="D")
),
pd.DataFrame(
{"data": [1, np.nan, 3]}, index=pd.date_range("2020-01-01", periods=3, freq="D")
),
method="denton",
agg_func="sum",
)

with pytest.raises(
ValueError,
match="Start date found on high frequency data 2020-01-01 is after start date "
"found on low frequency data 1999-01-01.",
):
disaggregate_series(
pd.DataFrame(
{"data": [1, 2, 3]}, index=pd.date_range("1999-01-01", periods=3, freq="D")
),
pd.DataFrame(
{"data": [1, 2, 3]}, index=pd.date_range("2020-01-01", periods=3, freq="D")
),
method="denton",
agg_func="sum",
)

with pytest.raises(
ValueError,
match="User provided target_freq does not match frequency information found on "
"indicator data.",
):
disaggregate_series(
pd.DataFrame(
{"data": [1, 2, 3]}, index=pd.date_range("2020-01-01", periods=3, freq="D")
),
pd.DataFrame(
{"data": [1, 2, 3]}, index=pd.date_range("2020-01-01", periods=3, freq="D")
),
method="denton",
agg_func="sum",
target_freq="M",
)

with pytest.raises(
ValueError,
match="Indicator data high_freq_df does not have a valid time index with "
"frequency information",
):
disaggregate_series(
pd.DataFrame(
{"data": [1, 2, 3]}, index=pd.date_range("2020-01-01", periods=3, freq="M")
),
pd.DataFrame(
{"data": [1, 2, 3]},
index=pd.to_datetime(["2020-01-01", "2020-03-04", "2020-12-06"]),
),
method="denton",
agg_func="sum",
)

with pytest.raises(
ValueError, match='high_freq_df can only be None for methods "denton" and "denton-cholette"'
):
disaggregate_series(
pd.DataFrame(
{"data": [1, 2, 3]}, index=pd.date_range("2020-01-01", periods=3, freq="Q")
),
None,
method="litterman",
agg_func="sum",
)


if __name__ == "__main__":
unittest.main()

0 comments on commit 98988fa

Please sign in to comment.