Skip to content

Commit 71be9df

Browse files
Add validation to _data_setter for non-standard data node names (#847)
* Rebase onto main and add happy-path validation test - Resolved merge conflicts in all three files against origin/main - Restored upstream class docstring rubric (Parameters + Examples) in PyMCModel - Restored actionable error message pointing to BayesianBasisExpansionTimeSeries - Added test_standard_data_nodes_predict exercising the validation happy path to satisfy codecov/patch Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Rebase onto main preserving all upstream classes and PR validation Previous stash-based resolution accidentally dropped ~330 lines from pymc_models.py, removing SyntheticDifferenceInDifferencesWeightFitter and other classes added to main after the branch diverged. This commit takes origin/main's full pymc_models.py (2652 lines) and re-applies only the PR's changes: class docstring note, _data_setter validation, method docstring update, and the codecov happy-path test. Also adds test_standard_data_nodes_predict to cover the validation loop's non-error path, resolving the codecov/patch gap. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Use origin/main panel_regression.py (no PR changes needed here) * Remove unused import (ruff fix) --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 13af0ef commit 71be9df

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

causalpy/tests/test_pymc_models.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,30 @@ def build_model(self, X, y, coords):
270270
with pytest.raises(ValueError, match="Data node 'y' not found"):
271271
model.predict(X=X)
272272

273+
def test_standard_data_nodes_predict(self, rng, mock_pymc_sample):
274+
"""Standard model with 'X' and 'y' data nodes exercises validation happy path."""
275+
from causalpy.pymc_models import LinearRegression
276+
277+
X = xr.DataArray(
278+
rng.normal(size=(10, 1)),
279+
dims=["obs_ind", "coeffs"],
280+
coords={"obs_ind": np.arange(10), "coeffs": ["x1"]},
281+
)
282+
y = xr.DataArray(
283+
rng.normal(size=(10, 1)),
284+
dims=["obs_ind", "treated_units"],
285+
coords={"obs_ind": np.arange(10), "treated_units": ["unit_0"]},
286+
)
287+
coords = {
288+
"obs_ind": np.arange(10),
289+
"coeffs": ["x1"],
290+
"treated_units": ["unit_0"],
291+
}
292+
model = LinearRegression(sample_kwargs={"chains": 2, "draws": 2})
293+
model.fit(X, y, coords=coords)
294+
predictions = model.predict(X=X)
295+
assert isinstance(predictions, az.InferenceData)
296+
273297

274298
def test_idata_property(mock_pymc_sample, did_data):
275299
"""Test that we can access the idata property of the model"""

0 commit comments

Comments
 (0)