-
Notifications
You must be signed in to change notification settings - Fork 61
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 all 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,22 @@ | |
|
|
||
| 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. | ||
|
|
||
| """ | ||
|
|
||
| from unittest.mock import Mock, patch | ||
|
|
||
| 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 | ||
|
|
@@ -49,6 +59,14 @@ def rank_data(clf_data): | |
| class TestLightGBM: | ||
| """Tests for LGBMClassifier, LGBMRegressor, LGBMRanker""" | ||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def capture_stdout(self): | ||
| # Mock print and rich.print so that running these tests with pytest -s | ||
| # does not spam stdout. Other, more common methods of suppressing | ||
| # printing to stdout don't seem to work, perhaps because of pytest. | ||
| with patch("builtins.print", Mock()), patch("rich.print", Mock()): | ||
| yield | ||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def lgbm(self): | ||
| lgbm = pytest.importorskip("lightgbm") | ||
|
|
@@ -83,9 +101,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) | ||
|
|
||
| @pytest.mark.parametrize("boosting_type", boosting_types) | ||
| def test_regressor(self, lgbm, regr_data, trusted, boosting_type): | ||
| kw = {} | ||
|
|
@@ -99,9 +120,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) | ||
|
|
||
| @pytest.mark.parametrize("boosting_type", boosting_types) | ||
| def test_ranker(self, lgbm, rank_data, trusted, boosting_type): | ||
| kw = {} | ||
|
|
@@ -115,9 +139,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) | ||
|
|
||
|
|
||
| class TestXGBoost: | ||
| """Tests for XGBClassifier, XGBRegressor, XGBRFClassifier, XGBRFRegressor, XGBRanker | ||
|
|
@@ -136,6 +163,14 @@ class TestXGBoost: | |
|
|
||
| """ | ||
|
|
||
| @pytest.fixture(autouse=True) | ||
|
Member
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. TIL
Collaborator
Author
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. And TIL about the |
||
| def capture_stdout(self): | ||
| # Mock print and rich.print so that running these tests with pytest -s | ||
| # does not spam stdout. Other, more common methods of suppressing | ||
| # printing to stdout don't seem to work, perhaps because of pytest. | ||
| with patch("builtins.print", Mock()), patch("rich.print", Mock()): | ||
| yield | ||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def xgboost(self): | ||
| xgboost = pytest.importorskip("xgboost") | ||
|
|
@@ -170,9 +205,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) | ||
|
|
||
| @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 +224,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) | ||
|
|
||
| @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 +243,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) | ||
|
|
||
| @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 +262,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) | ||
|
|
||
| @pytest.mark.parametrize("booster", boosters) | ||
| @pytest.mark.parametrize("tree_method", tree_methods) | ||
| def test_ranker(self, xgboost, rank_data, trusted, booster, tree_method): | ||
|
|
@@ -234,13 +281,24 @@ 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) | ||
|
|
||
|
|
||
| class TestCatboost: | ||
| """Tests for CatBoostClassifier, CatBoostRegressor, and CatBoostRanker""" | ||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def capture_stdout(self): | ||
| # Mock print and rich.print so that running these tests with pytest -s | ||
| # does not spam stdout. Other, more common methods of suppressing | ||
| # printing to stdout don't seem to work, perhaps because of pytest. | ||
| with patch("builtins.print", Mock()), patch("rich.print", Mock()): | ||
| yield | ||
|
|
||
| # CatBoost data is a little different so that it works as categorical data | ||
| @pytest.fixture(scope="module") | ||
| def cb_clf_data(self, clf_data): | ||
|
|
@@ -290,9 +348,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) | ||
|
|
||
| @pytest.mark.parametrize("boosting_type", boosting_types) | ||
| def test_regressor(self, catboost, cb_regr_data, trusted, boosting_type): | ||
| estimator = catboost.CatBoostRegressor( | ||
|
|
@@ -303,9 +364,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) | ||
|
Member
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. these are going to print a bunch of stuff in the terminal when we run tests, shouldn't we be capturing the output? It also makes me realize, maybe we want to have an output arg for
Collaborator
Author
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.
pytest automatically captures stdout unless used with the
What would that argument do? We have the
Member
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.
I know by default pytest captures output, but even when we pass
Collaborator
Author
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.
You should still be able to change
I see. For
Collaborator
Author
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. CI is green, please review again |
||
|
|
||
| @pytest.mark.parametrize("boosting_type", boosting_types) | ||
| def test_ranker(self, catboost, cb_rank_data, trusted, boosting_type): | ||
| estimator = catboost.CatBoostRanker( | ||
|
|
@@ -316,5 +380,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) | ||
Uh oh!
There was an error while loading. Please reload this page.