Extract results from Jupyter notebooks
Project description
nbresult
A simple package to test Jupyter notebook result for the Le Wagon's Data Science Bootcamp.
1. Installation
Installation with pip from Pypi:
pip install nbresult
2. Usage
2.1 Basic usage
Considering the default data challenge architecture:
.
├── challenge.ipynb
├── Makefile
├── README.md
├── data
│ └── data.csv
└── tests
└── __init__.py
If you want to test a variable log_model_score from the challenge.ipynb notebook with pytest:
Anywhere in the notebook you can add a cell with the following code:
from nbresult import ChallengeResult
result = ChallengeResult('score',
score=log_model_score
)
result.write()
This outputs a score.pickle file in the tests directory:
.
├── challenge.ipynb
├── Makefile
├── README.md
├── data
│ └── data.csv
└── tests
├── __init__.py
└── score.pickle
Now you would like to write test on the log_model_score with pytest. Create a test_score.py file:
# tests/test_score.py
from nbresult import ChallengeResultTestCase
class TestScore(ChallengeResultTestCase):
def test_score_is_above_82(self):
self.assertEqual(self.result.score > 0.82, True)
Finally you can run your tests with pytest:
pytest tests/test_score.py
OR
Run the tests with make:
- Setup a
Makefile
# Makefile
default: pytest
pytest:
PYTHONDONTWRITEBYTECODE=1 pytest -v --color=yes
- Run
make
OR
Run the tests inside the notebook:
from nbresult import ChallengeResult
result = ChallengeResult('score',
score=log_model_score
)
result.write()
print(result.check())
2.2 Advanced usage
For more advanced folder structure, you also can specify a subdir folder in which store & read pickle file
from nbresult import ChallengeResult
result = ChallengeResult('score',
subdir='a', # This will store pickle in tests/a/score.pickle
score=log_model_score
)
result.write()
result.check()
Check out detailed example below
Testing
Run make
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nbresult-0.1.1.tar.gz.
File metadata
- Download URL: nbresult-0.1.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2243d74843eaee0127692fe9574638be8107e350a0cc1eb43a09c08ddb3eeb7e
|
|
| MD5 |
846a18267a57da68ed75752981034d9d
|
|
| BLAKE2b-256 |
cad5bd2c986a556692f6f6f5b4a3d3e84cb0d5de5543afd6528681ac4b94b303
|
File details
Details for the file nbresult-0.1.1-py3-none-any.whl.
File metadata
- Download URL: nbresult-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
017eedf7b5964c9eb82198db2943545f139bbd4de6ad7a92de75d2ba23ea3b62
|
|
| MD5 |
9d3b4f6fe56460e1c2240d795b102256
|
|
| BLAKE2b-256 |
d07dbfcab3fd5bab7072ce01f55d3313d7b4860d46642d628752ef78b5245593
|