forked from ibis-project/ibis-ml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pprint.py
52 lines (38 loc) · 1.39 KB
/
test_pprint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pytest
import ibis_ml as ml
@pytest.fixture()
def rec():
imputer = ml.ImputeMean(ml.numeric())
scaler = ml.ScaleStandard(ml.numeric())
encoder = ml.OneHotEncode(ml.string(), min_frequency=20, max_categories=10)
return ml.Recipe(imputer, scaler, encoder)
@pytest.fixture()
def pipe(rec):
pytest.importorskip("sklearn")
from sklearn.pipeline import Pipeline
from sklearn.svm import SVC
return Pipeline([("rec", rec), ("svc", SVC())])
def test_steps(rec):
expected = [
"ImputeMean(numeric())",
"ScaleStandard(numeric())",
"OneHotEncode(string(), min_frequency=20, max_categories=10)",
]
assert [repr(step) for step in rec.steps] == expected
def test_recipe(rec):
expected = """
Recipe(ImputeMean(numeric()),
ScaleStandard(numeric()),
OneHotEncode(string(), min_frequency=20, max_categories=10))"""
expected = expected[1:] # remove first \n
assert repr(rec) == expected
def test_recipe_in_sklearn_pipeline(pipe):
expected = """
Pipeline(steps=[('rec',
Recipe(ImputeMean(numeric()), ScaleStandard(numeric()),
OneHotEncode(string(),
min_frequency=20,
max_categories=10))),
('svc', SVC())])"""
expected = expected[1:] # remove first \n
assert repr(pipe) == expected