Skip to content

Add default PyMC models when model=None for all experiment classes#707

Open
ErikRingen wants to merge 2 commits intomainfrom
661-docs-claim-default-models-but-baseexperiment-requires-explicit-model
Open

Add default PyMC models when model=None for all experiment classes#707
ErikRingen wants to merge 2 commits intomainfrom
661-docs-claim-default-models-but-baseexperiment-requires-explicit-model

Conversation

@ErikRingen
Copy link

Summary

Closes #661.

Experiment docstrings claimed default PyMC models would be used when model was omitted, but BaseExperiment immediately raised ValueError("model not set or passed."). This aligns actual behavior with the documented API.

  • Add _default_model_class class attribute to BaseExperiment with fallback logic that instantiates the default when model is None
  • Set appropriate defaults on all 9 experiment subclasses: LinearRegression for most, WeightedSumFitter for SyntheticControl, InstrumentalVariableRegression for InstrumentalVariable, PropensityScore for InversePropensityWeighting
  • Fix incorrect type hints (BaseExperiment -> PyMCModel) in InstrumentalVariable, InversePropensityWeighting, and RegressionKink
  • Remove redundant self.model = model in InstrumentalVariable that would have overwritten the default set by super().__init__()

Test plan

  • New parametrized integration test covers all 9 experiment classes with model=None
  • Explicit model precedence test confirms user-provided models are not overridden
  • Existing test_model_experiment_compatability tests pass (OLS rejection still works)
  • Full CI integration test suite passes

Made with Cursor

Closes #661. Experiment docstrings claimed default models would be used
when model was omitted, but BaseExperiment immediately raised ValueError.

- Add _default_model_class class attribute to BaseExperiment with
  fallback logic that instantiates the default when model is None
- Set appropriate defaults on all 9 experiment subclasses:
  LinearRegression for most, WeightedSumFitter for SyntheticControl,
  InstrumentalVariableRegression for IV, PropensityScore for IPW
- Fix incorrect type hints (BaseExperiment -> PyMCModel) in IV, IPW,
  and RegressionKink
- Remove redundant self.model = model in InstrumentalVariable that
  would have overwritten the default
- Add parametrized integration tests for all 9 experiment classes

Co-authored-by: Cursor <cursoragent@cursor.com>
@cursor
Copy link

cursor bot commented Feb 11, 2026

PR Summary

Medium Risk
Changes default initialization behavior across many experiment entrypoints, which could affect downstream expectations and sampling defaults; coverage is added but runtime/model-configuration differences may still surface in user workflows.

Overview
Experiment subclasses now provide a documented default PyMC model when model=None, by adding BaseExperiment._default_model_class and instantiating it automatically before the existing model-type support checks.

All affected experiments set _default_model_class (mostly LinearRegression, with WeightedSumFitter for SyntheticControl, InstrumentalVariableRegression for InstrumentalVariable, and PropensityScore for InversePropensityWeighting), update docstrings/type hints accordingly, and remove an InstrumentalVariable assignment that would have overwritten the default. Adds a parametrized integration test (test_default_models.py) to ensure defaults are used and that explicitly passed models still take precedence.

Written by Cursor Bugbot for commit e38fa9e. This will update automatically on new commits. Configure here.

@github-actions github-actions bot added the bug Something isn't working label Feb 11, 2026
@read-the-docs-community
Copy link

read-the-docs-community bot commented Feb 11, 2026

Documentation build overview

📚 causalpy | 🛠️ Build #31370886 | 📁 Comparing e38fa9e against latest (323e657)


🔍 Preview build

Show files changed (22 files in total): 📝 22 modified | ➕ 0 added | ➖ 0 deleted
File Status
404.html 📝 modified
api/generated/causalpy.experiments.diff_in_diff.DifferenceInDifferences.html 📝 modified
api/generated/causalpy.experiments.instrumental_variable.InstrumentalVariable.init.html 📝 modified
api/generated/causalpy.experiments.instrumental_variable.InstrumentalVariable.html 📝 modified
api/generated/causalpy.experiments.inverse_propensity_weighting.InversePropensityWeighting.init.html 📝 modified
api/generated/causalpy.experiments.inverse_propensity_weighting.InversePropensityWeighting.html 📝 modified
api/generated/causalpy.experiments.prepostnegd.PrePostNEGD.html 📝 modified
api/generated/causalpy.experiments.regression_discontinuity.RegressionDiscontinuity.html 📝 modified
api/generated/causalpy.experiments.regression_kink.RegressionKink.init.html 📝 modified
api/generated/causalpy.experiments.regression_kink.RegressionKink.html 📝 modified
api/generated/causalpy.experiments.staggered_did.StaggeredDifferenceInDifferences.html 📝 modified
api/generated/causalpy.experiments.synthetic_control.SyntheticControl.html 📝 modified
_modules/causalpy/experiments/base.html 📝 modified
_modules/causalpy/experiments/diff_in_diff.html 📝 modified
_modules/causalpy/experiments/instrumental_variable.html 📝 modified
_modules/causalpy/experiments/interrupted_time_series.html 📝 modified
_modules/causalpy/experiments/inverse_propensity_weighting.html 📝 modified
_modules/causalpy/experiments/prepostnegd.html 📝 modified
_modules/causalpy/experiments/regression_discontinuity.html 📝 modified
_modules/causalpy/experiments/regression_kink.html 📝 modified
_modules/causalpy/experiments/staggered_did.html 📝 modified
_modules/causalpy/experiments/synthetic_control.html 📝 modified

@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.40%. Comparing base (323e657) to head (e38fa9e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #707      +/-   ##
==========================================
+ Coverage   94.36%   94.40%   +0.04%     
==========================================
  Files          44       45       +1     
  Lines        7591     7646      +55     
  Branches      461      463       +2     
==========================================
+ Hits         7163     7218      +55     
  Misses        264      264              
  Partials      164      164              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs claim default models but BaseExperiment requires explicit model

1 participant