Skip to content

Commit 474a67e

Browse files
committed
Fix test for AR model output so that input matrix is invertible. This change addresses the numpy.linalg.LinAlgError: Singular matrix error encountered in GitHub Actions.
1 parent bb9153b commit 474a67e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tests/analysis/test_fit_ar_model.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,24 @@ def test_create_lagged_features():
4444

4545

4646
def test_ar_model_output():
47-
dates = pd.date_range("2020-01-01", periods=5, freq="D")
47+
rng = np.random.default_rng(312)
48+
49+
dates = pd.date_range("2020-01-01", periods=10, freq="D")
50+
4851
df = pd.DataFrame(
4952
{
50-
"price": [2, 4, 6, 8, 10],
51-
"price_lag1": [np.nan, 2, 4, 6, 8],
52-
"price_lag2": [np.nan, np.nan, 2, 4, 6],
53+
"price": rng.random(10) * 100,
5354
},
5455
index=dates,
55-
).dropna()
56+
)
57+
58+
df["price_lag1"] = df["price"].shift(1) + rng.standard_normal(10) * 5
59+
df["price_lag2"] = df["price"].shift(2) + rng.standard_normal(10) * 5
60+
61+
df = df.dropna()
62+
5663
coeffs = _ar_model(df, "price", 2)
64+
5765
assert len(coeffs) == expected_coeff_count
5866
assert isinstance(coeffs, np.ndarray)
5967

0 commit comments

Comments
 (0)