Skip to main content

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.
    • 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.

Install

pip install nbmodular

Project details


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.2.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nbmodular-0.0.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file nbmodular-0.0.2.tar.gz.

File metadata

  • Download URL: nbmodular-0.0.2.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for nbmodular-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4864f0acf9b236fad134037e22c4a5ade8a24cff5903d57c0666e5a68595af84
MD5 b5933728e98486e0ccde9c7ff6067529
BLAKE2b-256 f4d93c24dd074c9b45871fed7a6c906ec902434e1ee45f2a00ba5efd34baed82

See more details on using hashes here.

File details

Details for the file nbmodular-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: nbmodular-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for nbmodular-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 efa78bac97b79b5e0439e39f809a1cc746295e9bfbb55dc37333af519a502f3f
MD5 95d87646815b794df6c7df87402e19e7
BLAKE2b-256 186f173146f0bfc9ebf333b24aee4b44a1ac5e17e1274ce062af9ce22c98cdc4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page