Skip to main content

Extract results from Jupyter notebooks

Project description

nbresult

A simple package to test Jupyter notebook result for the Le Wagon's Data Science Bootcamp.

Installation

Installation with pip from Pypi:

pip install nbresult

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:

variable

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

pytest

OR

Run the tests with make:

  • Setup a Makefile
# Makefile

default: pytest

pytest:
  PYTHONDONTWRITEBYTECODE=1 pytest -v --color=yes
  • Run make

make

OR

Run the tests inside the notebook:

from nbresult import ChallengeResult

result = ChallengeResult('score',
    score=log_model_score
)
result.write()
print(result.check())

notebook

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

nbresult-0.0.4.tar.gz (707.5 kB view details)

Uploaded Source

File details

Details for the file nbresult-0.0.4.tar.gz.

File metadata

  • Download URL: nbresult-0.0.4.tar.gz
  • Upload date:
  • Size: 707.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/56.2.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for nbresult-0.0.4.tar.gz
Algorithm Hash digest
SHA256 ec1349f734b41164925e24572451f87f6380de23dd6068802b6a2e5ef6b72c16
MD5 bc953c78764fbd12e303c7b4c25f81d9
BLAKE2b-256 5367fc9119da6cf4f030396e4234960047b6b9589c7e9ff8816212e232790ea1

See more details on using hashes here.

Provenance

Supported by

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