Convert notebooks to modular code
Project description
nbmodular
Convert data scientist notebooks with poor modularity to fully modular notebooks and / or python modules.
Roadmap
- Convert cell code into functions:
- Inputs are those variables detected in current cell and also detected in previous cells. This solution requires that created variables have unique names across the notebook. However, even if a new variable with the same name is defined inside the cell, the resulting function is still correct.
- Outputs are, at this moment, all the variables detected in current cell that are also detected in posterior cells.
- Filter out outputs:
- Variables detected in current cell, and also detected in previous
cells, might not be needed as outputs of the current cell, if the
current cell doesn’t modify those variables. To detect potential
modifications:
- AST:
- If variable appears only on the right of assign statements or in if statements.
- If it appears only as argument of functions which we know don’t
modify the variable, such as
print
.
- Comparing variable values before and after cell:
- Good for small variables where doing a deep copy is not computationally expensive.
- Using type checker:
- Making the variable
Final
and using mypy or other type checker to see if it is modified in the code.
- Making the variable
- AST:
- Provide hints:
- Variables that come from other cells might not be needed as output. The remaining are most probably needed.
- Variables that are modified are clearly needed.
- Variables detected in current cell, and also detected in previous
cells, might not be needed as outputs of the current cell, if the
current cell doesn’t modify those variables. To detect potential
modifications:
Install
pip install nbmodular
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nbmodular-0.0.1.tar.gz
(5.8 kB
view hashes)
Built Distribution
Close
Hashes for nbmodular-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73582417177116acd2c138efaf6239616396393d1f4f84bc86ded179a2034706 |
|
MD5 | e32d480704c079a7fac48d8187adbee2 |
|
BLAKE2b-256 | 4a804565699f501e9f091962dc7d779c88887531d141ecf4a3384b5e3647dec6 |