Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 55 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,70 @@ on:
branches: [ main ]

jobs:
build:
devel:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.7, 3.8]
python-version: [3.8]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install package
run: pip install .[dev]
- name: make test-devel
run: make test-devel

readme:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.7, 3.8]
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install package and dependencies
run: pip install rundoc .
- name: make test-readme
run: make test-readme

- name: Install dependencies
run: |
sudo apt-get install pandoc
python -m pip install --upgrade pip
pip install tox tox-gh-actions
unit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.7, 3.8]
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install package and dependencies
run: pip install .[test]
- name: make test-unit
run: make test-unit

- name: Test with tox
run: tox
tutorials:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.7, 3.8]
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install package and dependencies
run: pip install .[test]
- name: make test-tutorials
run: make test-tutorials
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ test-readme: ## run the readme snippets

.PHONY: test-tutorials
test-tutorials: ## run the tutorial notebooks
jupyter nbconvert --execute --ExecutePreprocessor.timeout=3600 --to=html --stdout notebooks/*.ipynb > /dev/null
find notebooks -path "*/.ipynb_checkpoints" -prune -false -o -name "*.ipynb" -exec \
jupyter nbconvert --execute --ExecutePreprocessor.timeout=3600 --to=html --stdout {} > /dev/null \;


.PHONY: test
Expand Down
6 changes: 3 additions & 3 deletions notebooks/modeling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@
"hash": "2d6fabd7bf745a21519616ebdce3b2479184204dadf576aa19f086ff78438203"
},
"kernelspec": {
"display_name": "zephyr",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "zephyr"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -195,7 +195,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
"version": "3.8.16"
}
},
"nbformat": 4,
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ universal = 1
max-line-length = 99
exclude = docs, .tox, .git, __pycache__, .ipynb_checkpoints
per-file-ignores = __init__.py:F401
ignore = # keep empty to prevent default ignores

[isort]
include_trailing_comment = True
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
install_requires = [
'numpy>=1.16.0,<1.23.0',
'pandas>=1,<2',
'composeml>=0.1.6,<1.0',
'composeml>=0.1.6,<0.10',
'featuretools>=1.0.0,<2.0.0',
'mlblocks>=0.4.0,<0.5',
'mlblocks>=0.5.0,<0.6',
'xgboost>=0.72.1,<1',
'jupyter==1.0.0',
]
Expand Down Expand Up @@ -50,6 +50,7 @@
'Sphinx>=1.7.1,<3',
'sphinx_rtd_theme>=0.2.4,<0.5',
'autodocsumm>=0.1.10',
'mistune>=0.7,<2',
'Jinja2<3.1',

# style check
Expand Down
52 changes: 51 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import pickle

import numpy as np
import pandas as pd
import pytest

from zephyr_ml.core import Zephyr

Expand Down Expand Up @@ -32,6 +34,28 @@ def setup_class(cls):
def setup(self):
self.zephyr = Zephyr('xgb')

def test_hyperparameters(self):
hyperparameters = {
"xgboost.XGBClassifier#1": {
"max_depth": 2
},
"zephyr_ml.primitives.postprocessing.FindThreshold#1": {
"metric": "precision"
}
}

zephyr = Zephyr('xgb', hyperparameters)

assert zephyr._hyperparameters == hyperparameters

def test_json(self):
file = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
json_zephyr = Zephyr(os.path.join(file, 'zephyr_ml', 'pipelines', 'xgb.json'))

json_zephyr_hyperparameters = json_zephyr._mlpipeline.get_hyperparameters()
zephyr_hyperparameters = self.zephyr._mlpipeline.get_hyperparameters()
assert json_zephyr_hyperparameters == zephyr_hyperparameters

def test_fit(self):
self.zephyr.fit(self.train, self.train_y)

Expand All @@ -48,12 +72,21 @@ def test_fit_predict(self):
assert isinstance(predicted, list)

def test_save_load(self, tmpdir):
path = os.path.join(tmpdir, 'some/path.pkl')
path = os.path.join(tmpdir, 'some_path.pkl')
self.zephyr.save(path)

new_zephyr = Zephyr.load(path)
assert new_zephyr == self.zephyr

def test_load_failed(self, tmpdir):
path = os.path.join(tmpdir, 'some_path.pkl')
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, 'wb') as pickle_file:
pickle.dump("something", pickle_file)

with pytest.raises(ValueError):
Zephyr.load(path)

def test_evaluate(self):
self.zephyr.fit(self.test, self.test_y)
scores = self.zephyr.evaluate(X=self.test, y=self.test_y)
Expand Down Expand Up @@ -81,6 +114,23 @@ def test_evaluate_fit(self):
})
pd.testing.assert_series_equal(expected, scores)

def test_evaluate_previously_fitted_with_fit_true(self):
self.zephyr.fit(self.train, self.train_y)

scores = self.zephyr.evaluate(
X=self.test,
y=self.test_y,
fit=True
)

expected = pd.Series({
'accuracy': 1.0,
'f1': 1.0,
'recall': 1.0,
'precision': 1.0,
})
pd.testing.assert_series_equal(expected, scores)

def test_evaluate_train_data(self):
scores = self.zephyr.evaluate(
X=self.test,
Expand Down
9 changes: 7 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
[tox]
envlist = py3{6,7}, test-devel
envlist = py3{7,8}, test-devel

[travis]
python =
3.8: py38, test-devel
3.7: py37

[gh-actions]
python =
3.7: py37, test-devel
3.6: py36
3.8: py38

[testenv]
passenv = CI TRAVIS TRAVIS_*
Expand Down
4 changes: 2 additions & 2 deletions zephyr_ml/primitives/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class FindThreshold:

This is intended for classification problems.

Args:
Args:
metric (str):
String representing which metric to use.
String representing which metric to use.
"""

def __init__(self, metric='f1'):
Expand Down