-
Notifications
You must be signed in to change notification settings - Fork 60
FIX: bug when visualizing byte nodes #352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
289a4e4
3371ed7
ee49944
5ab7445
af522ef
9307c77
5cb3038
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,20 @@ | |
|
||
Packages that are not builtins, standard lib, numpy, scipy, or scikit-learn. | ||
|
||
Testing: | ||
|
||
- persistence of unfitted models | ||
- persistence of fitted models | ||
- visualization of dumped models | ||
|
||
with a range of hyperparameters. | ||
|
||
""" | ||
|
||
import pytest | ||
from sklearn.datasets import make_classification, make_regression | ||
|
||
from skops.io import dumps, loads | ||
from skops.io import dumps, loads, visualize | ||
from skops.io.tests._utils import assert_method_outputs_equal, assert_params_equal | ||
|
||
# Default settings for generated data | ||
|
@@ -46,6 +54,11 @@ def rank_data(clf_data): | |
return X, y, group | ||
|
||
|
||
def _null(*args, **kwargs): | ||
# used to prevent printing anything to stdout when calling visualize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. passing this as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is true. The relevant part of the code is executed, though, i.e. the tests would fail without the bugfix. If you want me to still change it, I can think of something (I guess auto fixture that overrides There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but you're also specifically testing this bug anyway. So it'd be nice to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, makes sense, done. |
||
return | ||
|
||
|
||
class TestLightGBM: | ||
"""Tests for LGBMClassifier, LGBMRegressor, LGBMRanker""" | ||
|
||
|
@@ -83,9 +96,12 @@ def test_classifier(self, lgbm, clf_data, trusted, boosting_type): | |
|
||
X, y = clf_data | ||
estimator.fit(X, y) | ||
loaded = loads(dumps(estimator), trusted=trusted) | ||
dumped = dumps(estimator) | ||
loaded = loads(dumped, trusted=trusted) | ||
assert_method_outputs_equal(estimator, loaded, X) | ||
|
||
visualize(dumped, trusted=trusted, sink=_null) | ||
|
||
@pytest.mark.parametrize("boosting_type", boosting_types) | ||
def test_regressor(self, lgbm, regr_data, trusted, boosting_type): | ||
kw = {} | ||
|
@@ -99,9 +115,12 @@ def test_regressor(self, lgbm, regr_data, trusted, boosting_type): | |
|
||
X, y = regr_data | ||
estimator.fit(X, y) | ||
loaded = loads(dumps(estimator), trusted=trusted) | ||
dumped = dumps(estimator) | ||
loaded = loads(dumped, trusted=trusted) | ||
assert_method_outputs_equal(estimator, loaded, X) | ||
|
||
visualize(dumped, trusted=trusted, sink=_null) | ||
|
||
@pytest.mark.parametrize("boosting_type", boosting_types) | ||
def test_ranker(self, lgbm, rank_data, trusted, boosting_type): | ||
kw = {} | ||
|
@@ -115,9 +134,12 @@ def test_ranker(self, lgbm, rank_data, trusted, boosting_type): | |
|
||
X, y, group = rank_data | ||
estimator.fit(X, y, group=group) | ||
loaded = loads(dumps(estimator), trusted=trusted) | ||
dumped = dumps(estimator) | ||
loaded = loads(dumped, trusted=trusted) | ||
assert_method_outputs_equal(estimator, loaded, X) | ||
|
||
visualize(dumped, trusted=trusted, sink=_null) | ||
|
||
|
||
class TestXGBoost: | ||
"""Tests for XGBClassifier, XGBRegressor, XGBRFClassifier, XGBRFRegressor, XGBRanker | ||
|
@@ -170,9 +192,12 @@ def test_classifier(self, xgboost, clf_data, trusted, booster, tree_method): | |
|
||
X, y = clf_data | ||
estimator.fit(X, y) | ||
loaded = loads(dumps(estimator), trusted=trusted) | ||
dumped = dumps(estimator) | ||
loaded = loads(dumped, trusted=trusted) | ||
assert_method_outputs_equal(estimator, loaded, X) | ||
|
||
visualize(dumped, trusted=trusted, sink=_null) | ||
|
||
@pytest.mark.parametrize("booster", boosters) | ||
@pytest.mark.parametrize("tree_method", tree_methods) | ||
def test_regressor(self, xgboost, regr_data, trusted, booster, tree_method): | ||
|
@@ -186,9 +211,12 @@ def test_regressor(self, xgboost, regr_data, trusted, booster, tree_method): | |
|
||
X, y = regr_data | ||
estimator.fit(X, y) | ||
loaded = loads(dumps(estimator), trusted=trusted) | ||
dumped = dumps(estimator) | ||
loaded = loads(dumped, trusted=trusted) | ||
assert_method_outputs_equal(estimator, loaded, X) | ||
|
||
visualize(dumped, trusted=trusted, sink=_null) | ||
|
||
@pytest.mark.parametrize("booster", boosters) | ||
@pytest.mark.parametrize("tree_method", tree_methods) | ||
def test_rf_classifier(self, xgboost, clf_data, trusted, booster, tree_method): | ||
|
@@ -202,9 +230,12 @@ def test_rf_classifier(self, xgboost, clf_data, trusted, booster, tree_method): | |
|
||
X, y = clf_data | ||
estimator.fit(X, y) | ||
loaded = loads(dumps(estimator), trusted=trusted) | ||
dumped = dumps(estimator) | ||
loaded = loads(dumped, trusted=trusted) | ||
assert_method_outputs_equal(estimator, loaded, X) | ||
|
||
visualize(dumped, trusted=trusted, sink=_null) | ||
|
||
@pytest.mark.parametrize("booster", boosters) | ||
@pytest.mark.parametrize("tree_method", tree_methods) | ||
def test_rf_regressor(self, xgboost, regr_data, trusted, booster, tree_method): | ||
|
@@ -218,9 +249,12 @@ def test_rf_regressor(self, xgboost, regr_data, trusted, booster, tree_method): | |
|
||
X, y = regr_data | ||
estimator.fit(X, y) | ||
loaded = loads(dumps(estimator), trusted=trusted) | ||
dumped = dumps(estimator) | ||
loaded = loads(dumped, trusted=trusted) | ||
assert_method_outputs_equal(estimator, loaded, X) | ||
|
||
visualize(dumped, trusted=trusted, sink=_null) | ||
|
||
@pytest.mark.parametrize("booster", boosters) | ||
@pytest.mark.parametrize("tree_method", tree_methods) | ||
def test_ranker(self, xgboost, rank_data, trusted, booster, tree_method): | ||
|
@@ -234,9 +268,12 @@ def test_ranker(self, xgboost, rank_data, trusted, booster, tree_method): | |
|
||
X, y, group = rank_data | ||
estimator.fit(X, y, group=group) | ||
loaded = loads(dumps(estimator), trusted=trusted) | ||
dumped = dumps(estimator) | ||
loaded = loads(dumped, trusted=trusted) | ||
assert_method_outputs_equal(estimator, loaded, X) | ||
|
||
visualize(dumped, trusted=trusted, sink=_null) | ||
|
||
|
||
class TestCatboost: | ||
"""Tests for CatBoostClassifier, CatBoostRegressor, and CatBoostRanker""" | ||
|
@@ -290,9 +327,12 @@ def test_classifier(self, catboost, cb_clf_data, trusted, boosting_type): | |
|
||
X, y = cb_clf_data | ||
estimator.fit(X, y, cat_features=[0, 1]) | ||
loaded = loads(dumps(estimator), trusted=trusted) | ||
dumped = dumps(estimator) | ||
loaded = loads(dumped, trusted=trusted) | ||
assert_method_outputs_equal(estimator, loaded, X) | ||
|
||
visualize(dumped, trusted=trusted, sink=_null) | ||
|
||
@pytest.mark.parametrize("boosting_type", boosting_types) | ||
def test_regressor(self, catboost, cb_regr_data, trusted, boosting_type): | ||
estimator = catboost.CatBoostRegressor( | ||
|
@@ -303,9 +343,12 @@ def test_regressor(self, catboost, cb_regr_data, trusted, boosting_type): | |
|
||
X, y = cb_regr_data | ||
estimator.fit(X, y, cat_features=[0, 1]) | ||
loaded = loads(dumps(estimator), trusted=trusted) | ||
dumped = dumps(estimator) | ||
loaded = loads(dumped, trusted=trusted) | ||
assert_method_outputs_equal(estimator, loaded, X) | ||
|
||
visualize(dumped, trusted=trusted, sink=_null) | ||
|
||
@pytest.mark.parametrize("boosting_type", boosting_types) | ||
def test_ranker(self, catboost, cb_rank_data, trusted, boosting_type): | ||
estimator = catboost.CatBoostRanker( | ||
|
@@ -316,5 +359,8 @@ def test_ranker(self, catboost, cb_rank_data, trusted, boosting_type): | |
|
||
X, y, group_id = cb_rank_data | ||
estimator.fit(X, y, cat_features=[0, 1], group_id=group_id) | ||
loaded = loads(dumps(estimator), trusted=trusted) | ||
dumped = dumps(estimator) | ||
loaded = loads(dumped, trusted=trusted) | ||
assert_method_outputs_equal(estimator, loaded, X) | ||
|
||
visualize(dumped, trusted=trusted, sink=_null) |
Uh oh!
There was an error while loading. Please reload this page.