← ClaudeAtlas

notebook-refactorlisted

Refactor a Jupyter/.ipynb notebook from top-to-bottom exploratory sprawl into small, named, reviewable functions with clear inputs and outputs. Extract subfunctions, separate config/params from logic, remove hidden cell-order dependencies and global-state leakage, add docstrings and light tests, and make the notebook re-runnable top-to-bottom and diff-friendly. Use this skill whenever the user has a messy notebook they want cleaned up, wants notebook code turned into functions or a module, is preparing a notebook for review/handoff/production, or asks to make an .ipynb readable or testable. This is about code STRUCTURE and reviewability; performance and correctness of data code is python-data-patterns' job.
Methasit-Pun/data_engineer_claude_skills · ★ 1 · Code & Development · score 65
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