ds-notebook-refactor
Installation
SKILL.md
Notebook Refactor
Jupyter notebooks are great for research but risky for production. This skill helps you safely migrate code out of cells and into testable modules.
The Refactor Checklist
- Identify Logic: Find the cells that actually perform data transformations (ignore the plotting cells for now).
- Extract Functions: Move cell code into well-named functions with type hints.
- Handle Config: Extract hard-coded paths and variables into a
config.yamlor.envfile. - Parameterize: Ensure your main script can take arguments (e.g., input path).
- Unit Test: Write a small test for your new function using representative dummy data.
Before vs. After
- Before: A notebook with 50 cells, global variables, and
print()statements everywhere. - After: A single
pipeline.pythat imports functions fromutils.pyand logs progress.
Best Practices
- Use a
.ipynbto.pyexporter for a head start, but always manually clean the result. - Keep your plotting logic separate from your transformation logic.