agentleFS
samuhssamuhs/mad-science/skills/developing-data-science-notebooks/SKILL.md

developing-data-science-notebooks

Skill1 starsChanged 13 days agoMITView on GitHub

Develop production-grade Jupyter notebooks for data science research that follow state-of-the-art code practices (cell structure, modularization, reproducibility) and are designed to transition cleanly into production artifacts (API, worker, DAG). Use when creating, restructuring, or reviewing data science notebooks.

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 10 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this ordering when building the notebook top-down:

    line 18
  2. Distinctive:

    No cell state dependency — restart & run all must work from clean kernel.

    line 29
  3. Distinctive:

    No duplicated logic between cells/notebooks (DRY).

    line 36
  4. Distinctive:

    Keep code PEP8 and Clean Code: meaningful names, sensible comments, small functions.

    line 37
  5. Very specific:

    Never edit raw data (immutable): read from data/raw, write final products to data/processed.

    line 43
  6. Distinctive:

    CI: every commit must validate the notebook — clean execution top-down + test suite + lint — before merge.

    line 76
  7. Distinctive:

    CD: every tested version automatically generates an artifact and deploys (staging → production) via scheduler/event (e.g.

    line 77
  8. Distinctive:

    When reviewing an existing notebook, check in order:

    line 82
  9. Distinctive:

    No import+compute cells; cells ≤100 lines with clear purpose.

    line 85
  10. Distinctive:

    No duplicated code across cells.

    line 86
  11. Distinctive:

    If it will be productionized: parameterized, CI-covered, extracted modules tested, experiments logged.

    line 89

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Developing Data Science Notebooks

Applies engineering best practices to Jupyter notebooks so the research code is readable, reproducible, and ready to be productionized. Synthesized from: PLOS "Ten Simple Rules" (2019), Google Cloud Jupyter Notebook Manifesto, Cookiecutter Data Science (DrivenData), nbdev, papermill, and the arXiv study on notebook collaboration practices.

Core Mindset

  • The notebook is exploration and narrative; the product is born from the modules extracted from it. Treat the notebook like software, not a draft.
  • Code that stabilizes gets refactored into functions and modules of your own installable package. The notebook becomes the orchestrator/consumer of that package.
  • A "consolidated" notebook is one you can Runtime → Restart & Run All with zero errors, top to bottom.

Checklist: Code Structure

Use this ordering when building the notebook top-down:

  1. Title + preamble (Markdown, H1): what the analysis answers, its purpose, audience. Write for your future self (over-explain).
  2. Imports isolated from logic — never mix import statements with computation in the same cell (breaks doc generation and hides side effects; only top-level statements count — imports inside functions/try are fine).
  3. Parameters cell at the top marked with the parameters tag (dates, thresholds, paths, file names) — everything that changes between runs. Never bury config in the middle.
  4. One cell = one meaningful step: one transformation, one function, one plot. Max ~100 lines per cell. Use Markdown above each cell explaining the why, not just the what.
  5. Functions over duplicated code: any snippet reused between cells or notebooks becomes a function. When in doubt, wrap it.
  6. Table of contents + section headers (Markdown H2/H3) for navigation; split very long notebooks into sequenced small notebooks with serialized intermediates (a top-level index notebook linking them).

Checklist: Code Quality

  • No cell state dependency — restart & run all must work from clean kernel.
  • %load_ext autoreload + %autoreload 2 and import your own modules when working in parallel with package code:
    %load_ext autoreload
    %autoreload 2
    from mypkg.features import make_dataset
  • No duplicated logic between cells/notebooks (DRY). Signs you should refactor to a module: copying an old notebook to start a new one, copy-pasting functions between notebooks, creating classes inside cells.
  • Keep code PEP8 and Clean Code: meaningful names, sensible comments, small functions.
  • Options supported: ipytest for unit tests inside the notebook; a real IDE for refactoring/debugging.

Checklist: Reproducibility

  • Declare the environment: pinned requirements.txt/environment.yml. Print critical dependency versions at the end (e.g. watermark extension).
  • Never edit raw data (immutable): read from data/raw, write final products to data/processed.
  • Version control: git + nbdime for human-readable notebook diffs, or save notebooks as plain text (.py/.md) via Jupytext — trivial diffs and code review.
  • Validate reproducibility: full restart→run-all before considering it done.

Path to Production (API, Worker, DAG)

Signs the notebook is ready to be productionized (CCDS)

SignalAction
Duplicating notebooks to start new onesExtract shared logic to a module
Copy-pasting functions between notebooksMove to module + add tests
Creating classes inside cellsRefactor into package module

Step 0 — Parameterize (papermill)

  1. Tag one cell as parameters (variables for dates, paths, thresholds).
  2. The notebook becomes non-interactively executable:
    papermill input.ipynb output.ipynb -p start_date 2026-01-01
  3. This is the gateway to running it as a scheduled job/stage.

Delivery shapes

TargetHow
DAG / pipeline stepBreak long notebook into per-stage notebooks that serialize intermediates to disk; orchestrate with Makefile, Airflow, Luigi, Prefect, Dagster, or Flyte.
APIRefactor stable stages (extraction, cleaning, features) into package modules; implement the service (e.g. FastAPI) on the tested modules; the notebook remains the demo/contract.
WorkerEvent (Pub/Sub, queue) triggers execution of the parameterized notebook (Google manifest CD pattern), or of the extracted module.

CI/CD for notebooks (Google manifest)

  • CI: every commit must validate the notebook — clean execution top-down + test suite + lint — before merge. Notebook is reviewed like a PR.
  • CD: every tested version automatically generates an artifact and deploys (staging → production) via scheduler/event (e.g. Cloud Functions + Scheduler).
  • Experiment logging: automatically record code, hyperparameters, data sources, results, and runtime for every execution so experiments are auditable.

Review Pass

When reviewing an existing notebook, check in order:

  1. Runs clean top-to-bottom; no hidden state.
  2. Params at top in a parameters cell; no config buried mid-notebook.
  3. No import+compute cells; cells ≤100 lines with clear purpose.
  4. No duplicated code across cells; functions used; stable logic heads toward a module.
  5. Dependencies pinned; versions printed; raw data untouched.
  6. Committed via nbdime/Jupytext — diffs are human-readable.
  7. If it will be productionized: parameterized, CI-covered, extracted modules tested, experiments logged.

Red Flags

  • Notebook that only works because only some cells were executed in a particular order.
  • Hardcoded secrets, credentials, or absolute machine-specific paths inside cells.
  • Long-lived notebook duplicating logic that already exists in the package.
  • Claims of "done" without a clean restart→run-all verification.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.