From b4f7b74c04e8777996a86438aa2fd0a9509fdb1c Mon Sep 17 00:00:00 2001 From: ao gong <41768719+ageorge156@users.noreply.github.com> Date: Fri, 21 Aug 2026 21:25:11 +0800 Subject: [PATCH] test: reject unsorted rebalance dates --- tests/test_portfolio_construction.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_portfolio_construction.py b/tests/test_portfolio_construction.py index 32756d2..cd43af1 100644 --- a/tests/test_portfolio_construction.py +++ b/tests/test_portfolio_construction.py @@ -141,6 +141,16 @@ def test_weight_table_rejects_duplicate_rebalance_dates() -> None: scores_to_weight_table(scores, top_k=1) +def test_weight_table_rejects_unsorted_rebalance_dates() -> None: + scores = pd.DataFrame( + {"A": [1.0, 2.0]}, + index=pd.to_datetime(["2026-01-07", "2026-01-05"]), + ) + + with pytest.raises(ValueError, match="chronological order"): + scores_to_weight_table(scores, top_k=1) + + def test_weight_table_rejects_non_numeric_scores() -> None: scores = pd.DataFrame({"A": ["high"], "B": ["low"]})