Skip to content

Commit d19879f

Browse files
committed
Merge branch 'main' into multi-cell-geolift
2 parents 21dd051 + 2916688 commit d19879f

34 files changed

+7586
-730
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: ["3.10", "3.11"]
14+
python-version: ["3.10", "3.11", "3.12"]
1515

1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
1818
- name: Set up Python
19-
uses: actions/setup-python@v3
19+
uses: actions/setup-python@v5
2020
with:
2121
python-version: ${{ matrix.python-version }}
22+
- name: Update pip and setuptools
23+
run: pip install --upgrade pip setuptools
24+
- name: Setup environment
25+
run: pip install -e .[test]
2226
- name: Run doctests
23-
run: |
24-
pip install -e .[test]
25-
pytest --doctest-modules --ignore=causalpy/tests/ causalpy/
27+
run: pytest --doctest-modules --ignore=causalpy/tests/ causalpy/
2628
- name: Run tests
27-
run: |
28-
pip install -e .[test]
29-
pytest --cov-report=xml --no-cov-on-fail
29+
run: pytest --cov-report=xml --no-cov-on-fail
3030
- name: Upload coverage to Codecov
31-
uses: codecov/codecov-action@v3
31+
uses: codecov/codecov-action@v4
3232
with:
3333
token: ${{ secrets.CODECOV_TOKEN }} # use token for more robust uploads
3434
name: ${{ matrix.python-version }}

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
name: Build source distribution
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1616
with:
1717
fetch-depth: 0
18-
- uses: actions/setup-python@v4
18+
- uses: actions/setup-python@v5
1919
with:
2020
python-version: 3.11
2121
- name: Build the sdist and the wheel
@@ -60,7 +60,7 @@ jobs:
6060
user: __token__
6161
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
6262
repository_url: https://test.pypi.org/legacy/
63-
- uses: actions/setup-python@v4
63+
- uses: actions/setup-python@v5
6464
with:
6565
python-version: 3.11
6666
- name: Test pip install from test.pypi
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Read the Docs Pull Request Preview
2+
on:
3+
pull_request_target:
4+
types:
5+
- opened
6+
7+
permissions:
8+
pull-requests: write
9+
10+
jobs:
11+
documentation-links:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: readthedocs/actions/preview@v1
15+
with:
16+
project-slug: "causalpy"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ _build
77
build/
88
dist/
99
docs/_build/
10+
docs/build/
11+
docs/jupyter_execute/
1012
*.vscode
1113
.coverage
1214
*.jupyterlab-workspace

.pre-commit-config.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ repos:
2222
exclude_types: [svg]
2323
- id: check-yaml
2424
- id: check-added-large-files
25+
exclude: &exclude_pattern 'iv_weak_instruments.ipynb'
2526
args: ["--maxkb=1500"]
2627
- repo: https://github.com/astral-sh/ruff-pre-commit
27-
rev: v0.4.3
28+
rev: v0.4.9
2829
hooks:
30+
# Run the linter
2931
- id: ruff
30-
args: ["--fix", "--output-format=full"]
32+
types_or: [ python, pyi, jupyter ]
33+
args: [ --fix ]
34+
# Run the formatter
3135
- id: ruff-format
32-
- repo: https://github.com/nbQA-dev/nbQA
33-
rev: 1.8.5
34-
hooks:
35-
- id: nbqa-ruff
36+
types_or: [ python, pyi, jupyter ]
3637
- repo: https://github.com/econchick/interrogate
3738
rev: 1.7.0
3839
hooks:

.readthedocs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ version: 2
77

88
# Set the version of Python and other tools you might need
99
build:
10-
os: ubuntu-20.04
10+
os: ubuntu-lts-latest
1111
tools:
12-
python: "3.10"
12+
python: "3.11"
1313
# You can also specify other tool versions:
1414
# nodejs: "16"
1515
# rust: "1.55"

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ lint:
1010
check_lint:
1111
ruff check .
1212
ruff format --diff --check .
13-
nbqa black --check .
14-
nbqa ruff .
1513
interrogate .
1614

1715
doctest:

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pip install git+https://github.com/pymc-labs/CausalPy.git
3434

3535
```python
3636
import causalpy as cp
37-
37+
import matplotlib.pyplot as plt
3838

3939
# Import and process data
4040
df = (
@@ -57,6 +57,8 @@ fig, ax = result.plot();
5757

5858
# Get a results summary
5959
result.summary()
60+
61+
plt.show()
6062
```
6163

6264
## Roadmap

causalpy/data/datasets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"geolift_multi_cell": {"filename": "geolift_multi_cell.csv"},
3737
"risk": {"filename": "AJR2001.csv"},
3838
"nhefs": {"filename": "nhefs.csv"},
39+
"schoolReturns": {"filename": "schoolingReturns.csv"},
3940
}
4041

4142

causalpy/data/schoolingReturns.csv

Lines changed: 3011 additions & 0 deletions
Large diffs are not rendered by default.

causalpy/pymc_experiments.py

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ def print_coefficients(self, round_to=None) -> None:
102102
... "progressbar": False
103103
... }),
104104
... )
105-
<BLANKLINE>
106-
<BLANKLINE>
107-
<BLANKLINE>
108-
<BLANKLINE>
109-
<BLANKLINE>
110105
>>> result.print_coefficients(round_to=1) # doctest: +NUMBER
111106
Model coefficients:
112107
Intercept 1, 94% HDI [1, 1]
@@ -165,11 +160,6 @@ class PrePostFit(ExperimentalDesign, PrePostFitDataValidator):
165160
... }
166161
... ),
167162
... )
168-
<BLANKLINE>
169-
<BLANKLINE>
170-
<BLANKLINE>
171-
<BLANKLINE>
172-
<BLANKLINE>
173163
>>> result.summary(round_to=1) # doctest: +NUMBER
174164
==================================Pre-Post Fit==================================
175165
Formula: actual ~ 0 + a + g
@@ -212,11 +202,9 @@ def __init__(
212202
self.post_X = np.asarray(new_x)
213203
self.post_y = np.asarray(new_y)
214204

215-
# DEVIATION FROM SKL EXPERIMENT CODE =============================
216205
# fit the model to the observed (pre-intervention) data
217206
COORDS = {"coeffs": self.labels, "obs_indx": np.arange(self.pre_X.shape[0])}
218207
self.model.fit(X=self.pre_X, y=self.pre_y, coords=COORDS)
219-
# ================================================================
220208

221209
# score the goodness of fit to the pre-intervention data
222210
self.score = self.model.score(X=self.pre_X, y=self.pre_y)
@@ -357,7 +345,6 @@ def summary(self, round_to=None) -> None:
357345

358346
print(f"{self.expt_type:=^80}")
359347
print(f"Formula: {self.formula}")
360-
# TODO: extra experiment specific outputs here
361348
self.print_coefficients(round_to)
362349

363350

@@ -396,11 +383,6 @@ class InterruptedTimeSeries(PrePostFit):
396383
... }
397384
... )
398385
... )
399-
<BLANKLINE>
400-
<BLANKLINE>
401-
<BLANKLINE>
402-
<BLANKLINE>
403-
<BLANKLINE>
404386
"""
405387

406388
expt_type = "Interrupted Time Series"
@@ -436,11 +418,6 @@ class SyntheticControl(PrePostFit):
436418
... }
437419
... ),
438420
... )
439-
<BLANKLINE>
440-
<BLANKLINE>
441-
<BLANKLINE>
442-
<BLANKLINE>
443-
<BLANKLINE>
444421
"""
445422

446423
expt_type = "Synthetic Control"
@@ -497,11 +474,6 @@ class DifferenceInDifferences(ExperimentalDesign, DiDDataValidator):
497474
... }
498475
... )
499476
... )
500-
<BLANKLINE>
501-
<BLANKLINE>
502-
<BLANKLINE>
503-
<BLANKLINE>
504-
<BLANKLINE>
505477
"""
506478

507479
def __init__(
@@ -793,11 +765,6 @@ class RegressionDiscontinuity(ExperimentalDesign, RDDataValidator):
793765
... ),
794766
... treatment_threshold=0.5,
795767
... )
796-
<BLANKLINE>
797-
<BLANKLINE>
798-
<BLANKLINE>
799-
<BLANKLINE>
800-
<BLANKLINE>
801768
"""
802769

803770
def __init__(
@@ -1207,10 +1174,6 @@ class PrePostNEGD(ExperimentalDesign, PrePostNEGDDataValidator):
12071174
... }
12081175
... )
12091176
... )
1210-
<BLANKLINE>
1211-
<BLANKLINE>
1212-
<BLANKLINE>
1213-
<BLANKLINE>
12141177
>>> result.summary(round_to=1) # doctest: +NUMBER
12151178
==================Pretest/posttest Nonequivalent Group Design===================
12161179
Formula: post ~ 1 + C(group) + pre
@@ -1441,8 +1404,6 @@ class InstrumentalVariable(ExperimentalDesign, IVDataValidator):
14411404
... formula=formula,
14421405
... model=InstrumentalVariableRegression(sample_kwargs=sample_kwargs),
14431406
... )
1444-
<BLANKLINE>
1445-
<BLANKLINE>
14461407
"""
14471408

14481409
def __init__(
@@ -1489,7 +1450,7 @@ def __init__(
14891450
"mus": [self.ols_beta_first_params, self.ols_beta_second_params],
14901451
"sigmas": [1, 1],
14911452
"eta": 2,
1492-
"lkj_sd": 2,
1453+
"lkj_sd": 1,
14931454
}
14941455
self.priors = priors
14951456
self.model.fit(
@@ -1568,8 +1529,6 @@ class InversePropensityWeighting(ExperimentalDesign, PropensityDataValidator):
15681529
... },
15691530
... ),
15701531
... )
1571-
<BLANKLINE>
1572-
<BLANKLINE>
15731532
"""
15741533

15751534
def __init__(

0 commit comments

Comments
 (0)