Skip to content

Commit 0d875f8

Browse files
committed
Fix: Initialize second_model properly in StateSpaceTimeSeries
- Change from bare type annotation to proper initialization with None - Add runtime check in fit() method to ensure model is built - Clarifies that second_model is created internally, not an input parameter
1 parent f14c72d commit 0d875f8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

causalpy/pymc_models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ def __init__(
16191619
self.seasonal_length = seasonal_length
16201620
self.mode = mode
16211621
self.ss_mod: Any = None
1622-
self.second_model: pm.Model
1622+
self.second_model: pm.Model | None = None # Created in build_model()
16231623
self._validate_and_initialize_components()
16241624

16251625
def _validate_and_initialize_components(self):
@@ -1744,6 +1744,8 @@ def fit(
17441744
Returns the InferenceData with parameter draws.
17451745
"""
17461746
self.build_model(X, y, coords)
1747+
if self.second_model is None:
1748+
raise RuntimeError("Model not built. Call build_model() first.")
17471749
with self.second_model:
17481750
self.idata = pm.sample(**self.sample_kwargs)
17491751
if self.idata is not None:

0 commit comments

Comments
 (0)