Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/test_notebook.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test Notebook
name: Test Other Notebooks

on:
pull_request:
Expand All @@ -8,6 +8,7 @@ on:
- "tests/**.py"
- "pymc_marketing/**"
- "docs/source/notebooks/**.ipynb"
- "!docs/source/notebooks/mmm/**.ipynb"
- "!docs/source/notebooks/*/dev/**.ipynb"
push:
branches: [main]
Expand All @@ -16,14 +17,15 @@ on:
- "tests/**.py"
- "pymc_marketing/**"
- "docs/source/notebooks/**.ipynb"
- "!docs/source/notebooks/mmm/**.ipynb"
- "!docs/source/notebooks/*/dev/**.ipynb"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
example_notebooks:
other_notebooks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
Expand All @@ -35,5 +37,5 @@ jobs:
run: |
sudo apt-get install graphviz graphviz-dev
pip install -e .[docs,test,dag]
- name: Run notebooks
run: make run_notebooks
- name: Run non-MMM notebooks
run: make run_notebooks_other
39 changes: 39 additions & 0 deletions .github/workflows/test_notebook_mmm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Test MMM Notebooks

on:
pull_request:
branches: [main]
paths:
- "pyproject.toml"
- "tests/**.py"
- "pymc_marketing/**"
- "docs/source/notebooks/mmm/**.ipynb"
- "!docs/source/notebooks/*/dev/**.ipynb"
push:
branches: [main]
paths:
- "pyproject.toml"
- "tests/**.py"
- "pymc_marketing/**"
- "docs/source/notebooks/mmm/**.ipynb"
- "!docs/source/notebooks/*/dev/**.ipynb"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
mmm_notebooks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install dependencies
run: |
sudo apt-get install graphviz graphviz-dev
pip install -e .[docs,test,dag]
- name: Run MMM notebooks
run: make run_notebooks_mmm
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ cleandocs: ## Clean the documentation build directories
run_notebooks: ## Run Jupyter notebooks
python scripts/run_notebooks/runner.py

run_notebooks_mmm: ## Run MMM Jupyter notebooks only
python scripts/run_notebooks/runner.py --exclude-dirs clv bass customer_choice general

run_notebooks_other: ## Run non-MMM Jupyter notebooks
python scripts/run_notebooks/runner.py --exclude-dirs mmm

uml: ## Install documentation dependencies and generate UML diagrams
pip install .[docs]
pyreverse pymc_marketing/mmm -d docs/source/uml -f 'ALL' -o png -p mmm
Expand Down
19 changes: 9 additions & 10 deletions docs/source/notebooks/clv/clv_quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 1,
"id": "65621d72",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -3086,30 +3086,29 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 2,
"id": "d56da0f3-9f85-4972-898c-ba0490cdb12e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Last updated: Sun Jul 27 2025\n",
"Last updated: Wed Oct 08 2025\n",
"\n",
"Python implementation: CPython\n",
"Python version : 3.12.11\n",
"IPython version : 9.4.0\n",
"IPython version : 9.3.0\n",
"\n",
"pymc : 5.25.1\n",
"pytensor: 2.31.7\n",
"\n",
"arviz : 0.22.0\n",
"pandas : 2.3.1\n",
"numpy : 2.2.6\n",
"pymc_marketing: 0.15.1\n",
"matplotlib : 3.10.3\n",
"pytensor : 2.31.7\n",
"arviz : 0.21.0\n",
"pymc_extras : 0.4.0\n",
"pymc_marketing: 0.15.1\n",
"numpy : 2.2.0\n",
"pandas : 2.3.0\n",
"\n",
"Watermark: 2.5.0\n",
"\n"
Expand All @@ -3125,7 +3124,7 @@
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand Down
22 changes: 7 additions & 15 deletions docs/source/notebooks/mmm/mmm_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 13.1.1 (0)\n",
"<!-- Generated by graphviz version 14.0.0 (20250921.2048)\n",
" -->\n",
"<!-- Pages: 1 -->\n",
"<svg width=\"451pt\" height=\"116pt\"\n",
Expand Down Expand Up @@ -91,7 +91,7 @@
"</svg>\n"
],
"text/plain": [
"<graphviz.graphs.Digraph at 0x10aab01d0>"
"<graphviz.graphs.Digraph at 0x104d4b380>"
]
},
"execution_count": 1,
Expand Down Expand Up @@ -12215,31 +12215,23 @@
},
{
"cell_type": "code",
"execution_count": 64,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Last updated: Thu Aug 07 2025\n",
"Last updated: Wed Oct 08 2025\n",
"\n",
"Python implementation: CPython\n",
"Python version : 3.12.11\n",
"IPython version : 9.4.0\n",
"IPython version : 9.3.0\n",
"\n",
"pymc_marketing: 0.15.1\n",
"pytensor : 2.31.7\n",
"\n",
"seaborn : 0.13.2\n",
"pymc_extras : 0.4.0\n",
"matplotlib : 3.10.3\n",
"graphviz : 0.21\n",
"arviz : 0.22.0\n",
"pymc : 5.25.1\n",
"pymc_marketing: 0.15.1\n",
"pandas : 2.3.1\n",
"numpy : 2.2.6\n",
"graphviz: 0.21\n",
"\n",
"Watermark: 2.5.0\n",
"\n"
Expand All @@ -12255,7 +12247,7 @@
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "pymc-marketing-dev",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand Down
18 changes: 17 additions & 1 deletion scripts/run_notebooks/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ def parse_args():
type=str,
help="List of notebooks to run. If not provided, all notebooks will be run.",
)
parser.add_argument(
"--exclude-dirs",
nargs="+",
type=str,
help="List of directories to exclude (e.g., mmm clv)",
)
return parser.parse_args()


Expand All @@ -115,12 +121,22 @@ def parse_args():
if args.notebooks:
notebooks_to_run = [Path(notebook) for notebook in args.notebooks]

if args.exclude_dirs:
exclude_set = set(args.exclude_dirs)
notebooks_to_run = [
nb for nb in notebooks_to_run if nb.parent.name not in exclude_set
]

setup_logging()
logging.info("Starting notebook runner")
logging.info(f"Notebooks to run: {notebooks_to_run}")
Parallel(n_jobs=-1)(
results = Parallel(n_jobs=-1)(
delayed(run_notebook)(**run_params)
for run_params in run_parameters(notebooks_to_run)
)
del results
import gc

gc.collect()

logging.info("Notebooks run successfully!")