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
File details
Details for the file nbresult-0.1.0.tar.gz
.
File metadata
- Download URL: nbresult-0.1.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c306c35453e6cebb4916b46543c87b35cf68e62bc1a4c5268583afe43a111287 |
|
MD5 | a4717ffe5b5fb05133f3254c72531fed |
|
BLAKE2b-256 | b5bc93769883ec2a715ed6c08b508774a6697fb9bfa9d0cb3bf8d6b4ca9bdda1 |