Skip to content

Commit

Permalink
Merge branch 'main' into unsquash-images-in-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
drbenvincent committed Mar 1, 2025
2 parents f4417ce + 0d6e4f8 commit e92eea6
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 21 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: PyPI release

on:
workflow_dispatch:
pull_request:
Expand All @@ -23,28 +24,30 @@ jobs:
run: |
pip install build
python -m build
ls dist # List the contents of the dist directory
- name: Check the sdist installs and imports
run: |
mkdir -p test-sdist
cd test-sdist
python -m venv venv-sdist
venv-sdist/bin/python -m pip install ../dist/causalpy*.tar.gz
echo "Checking import and version number (on release)"
venv-sdist/bin/python -c "import causalpy; assert causalpy.__version__ == '${{ github.ref_name }}' if '${{ github.ref_type }}' == 'tag' else causalpy.__version__; print(causalpy.__version__)"
venv-sdist/bin/python -c "import causalpy; assert causalpy.__version__ == '${{ github.ref_name }}' if '${{ github.ref_type }}' == 'tag' else causalpy.__version__; print(causalpy.__version__)"
cd ..
- name: Check the bdist installs and imports
run: |
mkdir -p test-bdist
cd test-bdist
python -m venv venv-bdist
venv-bdist/bin/python -m pip install ../dist/CausalPy*.whl
venv-bdist/bin/python -m pip install ../dist/causalpy*.whl
echo "Checking import and version number (on release)"
venv-bdist/bin/python -c "import causalpy; assert causalpy.__version__ == '${{ github.ref_name }}' if '${{ github.ref_type }}' == 'tag' else causalpy.__version__; print(causalpy.__version__)"
venv-bdist/bin/python -c "import causalpy; assert causalpy.__version__ == '${{ github.ref_name }}' if '${{ github.ref_type }}' == 'tag' else causalpy.__version__; print(causalpy.__version__)"
cd ..
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: artifact
path: dist/*

test:
name: Upload to Test PyPI
permissions:
Expand Down Expand Up @@ -72,7 +75,7 @@ jobs:
python -m venv venv-test-pypi
venv-test-pypi/bin/python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple causalpy
echo "Checking import and version number"
venv-test-pypi/bin/python -c "import causalpy; assert causalpy.__version__ == '${{ github.ref_name }}'"
venv-test-pypi/bin/python -c "import causalpy; assert causalpy.__version__ == '${{ github.ref_name }}'"
publish:
environment: release
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/uml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Update the UML Diagrams
on:
workflow_dispatch:
schedule:
- cron: '0 12 * * 1'

jobs:
build:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Configure Git Identity
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Update the UML Diagrams
run: |
sudo apt-get update && sudo apt-get install -y graphviz
make uml
- name: Detect UML changes
id: changes
run: |
git add docs/source/uml/*.png
if git diff --staged --exit-code; then
echo "No changes to commit"
echo "changes_exist=false" >> $GITHUB_OUTPUT
else
echo "changes_exist=true" >> $GITHUB_OUTPUT
fi
- name: Create PR for changes
if: steps.changes.outputs.changes_exist == 'true'
run: |
git checkout -b update-uml-diagrams
git commit -m "Update UML Diagrams"
git push -u origin update-uml-diagrams
gh pr create \
--base main \
--title "Update UML Diagrams" \
--body "This PR updates the UML diagrams
This PR was created automatically by the [UML workflow](https://github.com/pymc-labs/CausalPy/blob/main/.github/workflows/uml.yml).
See the logs [here](https://github.com/pymc-labs/CausalPy/actions/workflows/uml.yml) for more details." \
--label "no releasenotes" \
--reviewer drbenvincent
env:
GH_TOKEN: ${{ github.token }}
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
exclude: &exclude_pattern 'iv_weak_instruments.ipynb'
args: ["--maxkb=1500"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
rev: v0.9.8
hooks:
# Run the linter
- id: ruff
Expand All @@ -42,7 +42,7 @@ repos:
# see here https://github.com/econchick/interrogate/issues/60#issuecomment-735436566
pass_filenames: false
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell
additional_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion causalpy/pymc_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def print_row(
) -> None:
"""Print one row of the coefficient table"""
formatted_name = f" {name: <{max_label_length}}"
formatted_val = f"{round_num(coeff_samples.mean().data, round_to)}, 94% HDI [{round_num(coeff_samples.quantile(0.03).data, round_to)}, {round_num(coeff_samples.quantile(1-0.03).data, round_to)}]" # noqa: E501
formatted_val = f"{round_num(coeff_samples.mean().data, round_to)}, 94% HDI [{round_num(coeff_samples.quantile(0.03).data, round_to)}, {round_num(coeff_samples.quantile(1 - 0.03).data, round_to)}]" # noqa: E501
print(f" {formatted_name} {formatted_val}")

print("Model coefficients:")
Expand Down
12 changes: 6 additions & 6 deletions causalpy/tests/test_api_stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def test_causal_inference_and_discovery_with_python_example():

# Build the model
model = cp.pymc_models.WeightedSumFitter(sample_kwargs=sample_kwargs)
assert isinstance(
model, WeightedSumFitter
), "model is not an instance of WeightedSumFitter"
assert isinstance(model, WeightedSumFitter), (
"model is not an instance of WeightedSumFitter"
)

formula = "twitter ~ 0 + tiktok + linkedin + instagram"

Expand All @@ -49,9 +49,9 @@ def test_causal_inference_and_discovery_with_python_example():
formula=formula,
model=model,
)
assert isinstance(
results, SyntheticControl
), "results is not an instance of SyntheticControl"
assert isinstance(results, SyntheticControl), (
"results is not an instance of SyntheticControl"
)

fig, ax = results.plot()
assert isinstance(fig, plt.Figure)
2 changes: 1 addition & 1 deletion docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ CausalPy has a broad range of quasi-experimental methods for causal inference:
| Geographical lift | Measures the impact of an intervention in a specific geographic area by comparing it to similar areas without the intervention. Commonly used in marketing to assess regional campaigns. |
| ANCOVA | Analysis of Covariance combines ANOVA and regression to control for the effects of one or more quantitative covariates. Used when comparing group means while controlling for other variables. |
| Differences in Differences | Compares the changes in outcomes over time between a treatment group and a control group. Used in observational studies to estimate causal effects by accounting for time trends. |
| Regression discontinuity | Identifies causal effects by exploiting a cutoff or threshold in an assignment variable. Used when treatment is assigned based on a threshold value of an observed variable, allowing comparison just above and below the cutoff. |
|Regression discontinuity | Identifies causal effects by exploiting a sharp cutoff or threshold in an assignment variable. Used when treatment is assigned based on a threshold value of an observed variable, allowing comparison just above and below the cutoff. |
| Regression kink designs | Focuses on changes in the slope (kinks) of the relationship between variables rather than jumps at cutoff points. Used to identify causal effects when treatment intensity changes at a threshold. |
| Interrupted time series | Analyzes the effect of an intervention by comparing time series data before and after the intervention. Used when data is collected over time and an intervention occurs at a known point, allowing assessment of changes in level or trend. |
| Instrumental variable regression | Addresses endogeneity by using an instrument variable that is correlated with the endogenous explanatory variable but uncorrelated with the error term. Used when explanatory variables are correlated with the error term, providing consistent estimates of causal effects. |
Expand Down
2 changes: 1 addition & 1 deletion docs/source/notebooks/multi_cell_geolift.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@
"unpooled_results = []\n",
"\n",
"for i, target_geo in enumerate(treated):\n",
" print(f\"Analyzing test geo: {target_geo} ({i+1} of {len(treated)})\")\n",
" print(f\"Analyzing test geo: {target_geo} ({i + 1} of {len(treated)})\")\n",
" formula = f\"{target_geo} ~ 0 + {' + '.join(untreated)}\"\n",
" print(formula)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/notebooks/rd_pymc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Regression discontinuity with `pymc` models"
"# Sharp regression discontinuity with `pymc` models"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/source/notebooks/rd_pymc_drinking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# Drinking age - Bayesian analysis\n",
"\n",
"This example uses the regression discontinuity design to make claims about the causal effects of the minimum legal drinking age (21 in the USA) upon all cause mortality rates. The dataset is from a study by {cite:t}`carpenter2009effect`."
"This example uses the sharp regression discontinuity design to make claims about the causal effects of the minimum legal drinking age (21 in the USA) upon all cause mortality rates. The dataset is from a study by {cite:t}`carpenter2009effect`."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/source/notebooks/rd_skl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Regression discontinuity with sci-kit learn models"
"# Sharp regression discontinuity with sci-kit learn models"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/source/notebooks/rd_skl_drinking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# Drinking age with a scikit-learn model\n",
"\n",
"This example uses the regression discontinuity design to make claims about the causal effects of the minimum legal drinking age (21 in the USA) upon all cause mortality rates. The dataset is from a study by {cite:t}`carpenter2009effect`."
"This example uses the sharp regression discontinuity design to make claims about the causal effects of the minimum legal drinking age (21 in the USA) upon all cause mortality rates. The dataset is from a study by {cite:t}`carpenter2009effect`."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/source/notebooks/rkink_pymc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
" beta = rng.random(5)\n",
" ax[0, col].plot(x, f(x, beta, kink), lw=3)\n",
" ax[1, col].plot(x, np.gradient(f(x, beta, kink), x), lw=3)\n",
" ax[0, col].set(title=f\"Random {col+1}\")\n",
" ax[0, col].set(title=f\"Random {col + 1}\")\n",
" ax[1, col].set(xlabel=\"x\")\n",
"\n",
"ax[0, 0].set(ylabel=\"$y = f(x)$\")\n",
Expand Down

0 comments on commit e92eea6

Please sign in to comment.