notebook-refactorlisted
Install: claude install-skill Methasit-Pun/data_engineer_claude_skills
# Notebook Refactor
Exploratory notebooks grow by appending cells. That's fine for discovery and terrible for review, reuse, and reproduction. This skill restructures a notebook into functions a reviewer can read and a machine can re-run top-to-bottom.
## Where this sits (boundary)
- **vs. [[data-modeling]] (python-data-patterns):** that skill fixes *performance and correctness* (memory, vectorization, Polars/Spark). This skill fixes *structure and reviewability*. Refactor structure here; if a function is also slow or buggy, hand the internals to python-data-patterns.
## The smells to fix
- One giant cell doing five things
- Hidden order dependency — cell 12 only works if cell 7 ran, with no signal
- Globals mutated across cells; variables reused for different meanings
- Magic numbers and paths hard-coded mid-logic
- Copy-pasted blocks that differ by one value
- Output/plots interleaved so logic can't be read straight through
- No way to test anything without running the whole notebook
## Refactor procedure
1. **Make it re-runnable first.** Restart kernel, run all. Fix anything that breaks on a clean top-to-bottom pass. You can't refactor what you can't reproduce.
2. **Separate the four kinds of cell.** Sort content into: **config/params** (paths, dates, constants) → top; **pure logic** (transformations) → functions; **side effects** (I/O, writes); **presentation** (plots, displays) → bottom.
3. **Extract subfunctions.** Turn each coherent block into a named function