Skip to content

Commit 48cf9b5

Browse files
committed
make lots of tests pass
1 parent 7b1e600 commit 48cf9b5

29 files changed

+2540
-2542
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ We recommend that your contribution complies with the following guidelines befor
128128
make doctest
129129
```
130130

131-
- Doctest can also be run directly via pytest, which can be helpful to run only specific tests during development. The following commands run all doctests, only doctests in the pymc_models module, and only the doctests for the `ModelBuilder` class in pymc_models:
131+
- Doctest can also be run directly via pytest, which can be helpful to run only specific tests during development. The following commands run all doctests, only doctests in the pymc_models module, and only the doctests for the `PyMCModel` class in pymc_models:
132132

133133
```bash
134134
pytest --doctest-modules causalpy/
135135
pytest --doctest-modules causalpy/pymc_models.py
136-
pytest --doctest-modules causalpy/pmyc_models.py::causalpy.pymc_models.ModelBuilder
136+
pytest --doctest-modules causalpy/pmyc_models.py::causalpy.pymc_models.PyMCModel
137137
```
138138

139139
- To indicate a work in progress please mark the PR as `draft`. Drafts may be useful to (1) indicate you are working on something to avoid duplicated work, (2) request broad review of functionality or API, or (3) seek collaborators.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ df = (
4444
)
4545

4646
# Run the analysis
47-
result = cp.pymc_experiments.RegressionDiscontinuity(
47+
result = cp.RegressionDiscontinuity(
4848
df,
4949
formula="all ~ 1 + age + treated",
5050
running_variable_name="age",

causalpy/pymc_experiments.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# >>> import causalpy as cp
5656
# >>> df = cp.load_data("did")
5757
# >>> seed = 42
58-
# >>> result = cp.pymc_experiments.DifferenceInDifferences(
58+
# >>> result = cp.DifferenceInDifferences(
5959
# ... df,
6060
# ... formula="y ~ 1 + group*post_treatment",
6161
# ... time_variable_name="t",
@@ -304,7 +304,7 @@
304304
# >>> import causalpy as cp
305305
# >>> df = cp.load_data("did")
306306
# >>> seed = 42
307-
# >>> result = cp.pymc_experiments.DifferenceInDifferences(
307+
# >>> result = cp.DifferenceInDifferences(
308308
# ... df,
309309
# ... formula="y ~ 1 + group*post_treatment",
310310
# ... time_variable_name="t",
@@ -595,7 +595,7 @@
595595
# >>> import causalpy as cp
596596
# >>> df = cp.load_data("rd")
597597
# >>> seed = 42
598-
# >>> result = cp.pymc_experiments.RegressionDiscontinuity(
598+
# >>> result = cp.RegressionDiscontinuity(
599599
# ... df,
600600
# ... formula="y ~ 1 + x + treated + x:treated",
601601
# ... model=cp.pymc_models.LinearRegression(
@@ -1004,7 +1004,7 @@
10041004
# >>> import causalpy as cp
10051005
# >>> df = cp.load_data("anova1")
10061006
# >>> seed = 42
1007-
# >>> result = cp.pymc_experiments.PrePostNEGD(
1007+
# >>> result = cp.PrePostNEGD(
10081008
# ... df,
10091009
# ... formula="post ~ 1 + C(group) + pre",
10101010
# ... group_variable_name="group",
@@ -1358,7 +1358,7 @@
13581358
# >>> import causalpy as cp
13591359
# >>> df = cp.load_data("nhefs")
13601360
# >>> seed = 42
1361-
# >>> result = cp.pymc_experiments.InversePropensityWeighting(
1361+
# >>> result = cp.InversePropensityWeighting(
13621362
# ... df,
13631363
# ... formula="trt ~ 1 + age + race",
13641364
# ... outcome_variable ="outcome",

causalpy/skl_experiments.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
# >>> import causalpy as cp
6868
# >>> df = cp.load_data("sc")
6969
# >>> treatment_time = 70
70-
# >>> result = cp.skl_experiments.PrePostFit(
70+
# >>> result = cp.PrePostFit(
7171
# ... df,
7272
# ... treatment_time,
7373
# ... formula="actual ~ 0 + a + b + c + d + e + f + g",
@@ -255,7 +255,7 @@
255255
# ... .set_index("date")
256256
# ... )
257257
# >>> treatment_time = pd.to_datetime("2017-01-01")
258-
# >>> result = cp.skl_experiments.InterruptedTimeSeries(
258+
# >>> result = cp.InterruptedTimeSeries(
259259
# ... df,
260260
# ... treatment_time,
261261
# ... formula="y ~ 1 + t + C(month)",
@@ -285,7 +285,7 @@
285285
# >>> import causalpy as cp
286286
# >>> df = cp.load_data("sc")
287287
# >>> treatment_time = 70
288-
# >>> result = cp.skl_experiments.SyntheticControl(
288+
# >>> result = cp.SyntheticControl(
289289
# ... df,
290290
# ... treatment_time,
291291
# ... formula="actual ~ 0 + a + b + c + d + e + f + g",
@@ -334,7 +334,7 @@
334334
# >>> import causalpy as cp
335335
# >>> from sklearn.linear_model import LinearRegression
336336
# >>> df = cp.load_data("did")
337-
# >>> result = cp.skl_experiments.DifferenceInDifferences(
337+
# >>> result = cp.DifferenceInDifferences(
338338
# ... df,
339339
# ... formula="y ~ 1 + group*post_treatment",
340340
# ... time_variable_name="t",
@@ -558,7 +558,7 @@
558558
# >>> import causalpy as cp
559559
# >>> from sklearn.linear_model import LinearRegression
560560
# >>> data = cp.load_data("rd")
561-
# >>> result = cp.skl_experiments.RegressionDiscontinuity(
561+
# >>> result = cp.RegressionDiscontinuity(
562562
# ... data,
563563
# ... formula="y ~ 1 + x + treated",
564564
# ... model=LinearRegression(),

causalpy/tests/test_input_validation.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_did_validation_post_treatment_formula():
4040
)
4141

4242
with pytest.raises(FormulaException):
43-
_ = cp.pymc_experiments.DifferenceInDifferences(
43+
_ = cp.DifferenceInDifferences(
4444
df,
4545
formula="y ~ 1 + group*post_SOMETHING",
4646
time_variable_name="t",
@@ -49,7 +49,7 @@ def test_did_validation_post_treatment_formula():
4949
)
5050

5151
with pytest.raises(FormulaException):
52-
_ = cp.skl_experiments.DifferenceInDifferences(
52+
_ = cp.DifferenceInDifferences(
5353
df,
5454
formula="y ~ 1 + group*post_SOMETHING",
5555
time_variable_name="t",
@@ -73,7 +73,7 @@ def test_did_validation_post_treatment_data():
7373
)
7474

7575
with pytest.raises(DataException):
76-
_ = cp.pymc_experiments.DifferenceInDifferences(
76+
_ = cp.DifferenceInDifferences(
7777
df,
7878
formula="y ~ 1 + group*post_treatment",
7979
time_variable_name="t",
@@ -82,7 +82,7 @@ def test_did_validation_post_treatment_data():
8282
)
8383

8484
with pytest.raises(DataException):
85-
_ = cp.skl_experiments.DifferenceInDifferences(
85+
_ = cp.DifferenceInDifferences(
8686
df,
8787
formula="y ~ 1 + group*post_treatment",
8888
time_variable_name="t",
@@ -106,7 +106,7 @@ def test_did_validation_unit_data():
106106
)
107107

108108
with pytest.raises(DataException):
109-
_ = cp.pymc_experiments.DifferenceInDifferences(
109+
_ = cp.DifferenceInDifferences(
110110
df,
111111
formula="y ~ 1 + group*post_treatment",
112112
time_variable_name="t",
@@ -115,7 +115,7 @@ def test_did_validation_unit_data():
115115
)
116116

117117
with pytest.raises(DataException):
118-
_ = cp.skl_experiments.DifferenceInDifferences(
118+
_ = cp.DifferenceInDifferences(
119119
df,
120120
formula="y ~ 1 + group*post_treatment",
121121
time_variable_name="t",
@@ -139,7 +139,7 @@ def test_did_validation_group_dummy_coded():
139139
)
140140

141141
with pytest.raises(DataException):
142-
_ = cp.pymc_experiments.DifferenceInDifferences(
142+
_ = cp.DifferenceInDifferences(
143143
df,
144144
formula="y ~ 1 + group*post_treatment",
145145
time_variable_name="t",
@@ -148,7 +148,7 @@ def test_did_validation_group_dummy_coded():
148148
)
149149

150150
with pytest.raises(DataException):
151-
_ = cp.skl_experiments.DifferenceInDifferences(
151+
_ = cp.DifferenceInDifferences(
152152
df,
153153
formula="y ~ 1 + group*post_treatment",
154154
time_variable_name="t",
@@ -168,7 +168,7 @@ def test_sc_input_error():
168168
with pytest.raises(BadIndexException):
169169
df = cp.load_data("sc")
170170
treatment_time = pd.to_datetime("2016 June 24")
171-
_ = cp.pymc_experiments.SyntheticControl(
171+
_ = cp.SyntheticControl(
172172
df,
173173
treatment_time,
174174
formula="actual ~ 0 + a + b + c + d + e + f + g",
@@ -178,7 +178,7 @@ def test_sc_input_error():
178178
with pytest.raises(BadIndexException):
179179
df = cp.load_data("sc")
180180
treatment_time = pd.to_datetime("2016 June 24")
181-
_ = cp.skl_experiments.SyntheticControl(
181+
_ = cp.SyntheticControl(
182182
df,
183183
treatment_time,
184184
formula="actual ~ 0 + a + b + c + d + e + f + g",
@@ -202,7 +202,7 @@ def test_sc_brexit_input_error():
202202
all_countries = list(all_countries)
203203
other_countries = list(other_countries)
204204
formula = target_country + " ~ " + "0 + " + " + ".join(other_countries)
205-
_ = cp.pymc_experiments.SyntheticControl(
205+
_ = cp.SyntheticControl(
206206
df,
207207
treatment_time,
208208
formula=formula,
@@ -224,7 +224,7 @@ def test_ancova_validation_2_levels():
224224
)
225225

226226
with pytest.raises(DataException):
227-
_ = cp.pymc_experiments.PrePostNEGD(
227+
_ = cp.PrePostNEGD(
228228
df,
229229
formula="post ~ 1 + C(group) + pre",
230230
group_variable_name="group",
@@ -247,7 +247,7 @@ def test_rd_validation_treated_in_formula():
247247
)
248248

249249
with pytest.raises(FormulaException):
250-
_ = cp.pymc_experiments.RegressionDiscontinuity(
250+
_ = cp.RegressionDiscontinuity(
251251
df,
252252
formula="y ~ 1 + x",
253253
model=cp.pymc_models.LinearRegression(sample_kwargs=sample_kwargs),
@@ -257,7 +257,7 @@ def test_rd_validation_treated_in_formula():
257257
with pytest.raises(FormulaException):
258258
from sklearn.linear_model import LinearRegression
259259

260-
_ = cp.skl_experiments.RegressionDiscontinuity(
260+
_ = cp.RegressionDiscontinuity(
261261
df,
262262
formula="y ~ 1 + x",
263263
model=LinearRegression(),
@@ -276,7 +276,7 @@ def test_rd_validation_treated_is_dummy():
276276
)
277277

278278
with pytest.raises(DataException):
279-
_ = cp.pymc_experiments.RegressionDiscontinuity(
279+
_ = cp.RegressionDiscontinuity(
280280
df,
281281
formula="y ~ 1 + x + treated",
282282
model=cp.pymc_models.LinearRegression(sample_kwargs=sample_kwargs),
@@ -286,7 +286,7 @@ def test_rd_validation_treated_is_dummy():
286286
from sklearn.linear_model import LinearRegression
287287

288288
with pytest.raises(DataException):
289-
_ = cp.skl_experiments.RegressionDiscontinuity(
289+
_ = cp.RegressionDiscontinuity(
290290
df,
291291
formula="y ~ 1 + x + treated",
292292
model=LinearRegression(),
@@ -302,7 +302,7 @@ def test_iv_treatment_var_is_present():
302302
instruments_data = pd.DataFrame({"z": [1, 3, 4], "w": [2, 3, 4]})
303303

304304
with pytest.raises(DataException):
305-
_ = cp.pymc_experiments.InstrumentalVariable(
305+
_ = cp.InstrumentalVariable(
306306
instruments_data=instruments_data,
307307
data=data,
308308
instruments_formula=instruments_formula,
@@ -347,7 +347,7 @@ def test_rkink_bandwidth_check():
347347
with pytest.raises(ValueError):
348348
kink = 0.5
349349
df = setup_regression_kink_data(kink)
350-
_ = cp.pymc_experiments.RegressionKink(
350+
_ = cp.RegressionKink(
351351
df,
352352
formula=f"y ~ 1 + x + I((x-{kink})*treated)",
353353
model=cp.pymc_models.LinearRegression(sample_kwargs=sample_kwargs),
@@ -358,7 +358,7 @@ def test_rkink_bandwidth_check():
358358
with pytest.raises(ValueError):
359359
kink = 0.5
360360
df = setup_regression_kink_data(kink)
361-
_ = cp.pymc_experiments.RegressionKink(
361+
_ = cp.RegressionKink(
362362
df,
363363
formula=f"y ~ 1 + x + I((x-{kink})*treated)",
364364
model=cp.pymc_models.LinearRegression(sample_kwargs=sample_kwargs),
@@ -372,7 +372,7 @@ def test_rkink_epsilon_check():
372372
with pytest.raises(ValueError):
373373
kink = 0.5
374374
df = setup_regression_kink_data(kink)
375-
_ = cp.pymc_experiments.RegressionKink(
375+
_ = cp.RegressionKink(
376376
df,
377377
formula=f"y ~ 1 + x + I((x-{kink})*treated)",
378378
model=cp.pymc_models.LinearRegression(sample_kwargs=sample_kwargs),
@@ -383,7 +383,7 @@ def test_rkink_epsilon_check():
383383
with pytest.raises(ValueError):
384384
kink = 0.5
385385
df = setup_regression_kink_data(kink)
386-
_ = cp.pymc_experiments.RegressionKink(
386+
_ = cp.RegressionKink(
387387
df,
388388
formula=f"y ~ 1 + x + I((x-{kink})*treated)",
389389
model=cp.pymc_models.LinearRegression(sample_kwargs=sample_kwargs),

0 commit comments

Comments
 (0)