Skip to content

Commit 8cc3383

Browse files
moving build out of constructor
1 parent 84aa791 commit 8cc3383

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

pymc_experimental/model_builder.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def __init__(
6363
self.sample_config = sampler_config # parameters for sampling
6464
self.idata = None # inference data object
6565
self.data = data
66-
self.build()
6766

6867
def build(self):
6968
"""
@@ -192,6 +191,7 @@ def load(cls, fname):
192191
idata.fit_data.to_dataframe(),
193192
)
194193
self.idata = idata
194+
self.build()
195195
if self.id != idata.attrs["id"]:
196196
raise ValueError(
197197
f"The file '{fname}' does not contain an inference data of the same model or configuration as '{self._model_type}'"
@@ -224,10 +224,8 @@ def fit(self, data: Dict[str, Union[np.ndarray, pd.DataFrame, pd.Series]] = None
224224

225225
if data is not None:
226226
self.data = data
227-
self._data_setter(data)
228-
229-
if self.basic_RVs == []:
230227
self.build()
228+
self._data_setter(data)
231229

232230
with self:
233231
self.idata = pm.sample(**self.sample_config)

pymc_experimental/tests/test_model_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def create_sample_input(cls):
8484
def initial_build_and_fit(check_idata=True):
8585
data, model_config, sampler_config = test_ModelBuilder.create_sample_input()
8686
model = test_ModelBuilder(model_config, sampler_config, data)
87-
model.fit()
87+
model.fit(data=data)
8888
if check_idata:
8989
assert model.idata is not None
9090
assert "posterior" in model.idata.groups()

0 commit comments

Comments
 (0)