@@ -44,6 +44,23 @@ def __init__(self, a=None):
4444 self .a = 1
4545
4646
47+ class NoEstimator (object ):
48+ def __init__ (self ):
49+ pass
50+
51+ def fit (self , X = None , y = None ):
52+ return self
53+
54+ def predict (self , X = None ):
55+ return None
56+
57+
58+ class VargEstimator (BaseEstimator ):
59+ """Sklearn estimators shouldn't have vargs."""
60+ def __init__ (self , * vargs ):
61+ pass
62+
63+
4764#############################################################################
4865# The tests
4966
@@ -88,6 +105,12 @@ def test_clone_buggy():
88105 buggy .a = 2
89106 assert_raises (RuntimeError , clone , buggy )
90107
108+ no_estimator = NoEstimator ()
109+ assert_raises (TypeError , clone , no_estimator )
110+
111+ varg_est = VargEstimator ()
112+ assert_raises (RuntimeError , clone , varg_est )
113+
91114
92115def test_clone_empty_array ():
93116 """Regression test for cloning estimators with empty arrays"""
@@ -110,6 +133,9 @@ def test_repr():
110133 "T(a=K(c=None, d=None), b=K(c=None, d=None))"
111134 )
112135
136+ some_est = T (a = ["long_params" ] * 1000 )
137+ assert_equal (len (repr (some_est )), 415 )
138+
113139
114140def test_str ():
115141 """Smoke test the str of the base estimator"""
@@ -135,3 +161,16 @@ def test_is_classifier():
135161 assert_true (is_classifier (Pipeline ([('svc' , svc )])))
136162 assert_true (is_classifier (Pipeline ([('svc_cv' ,
137163 GridSearchCV (svc , {'C' : [0.1 , 1 ]}))])))
164+
165+
166+ def test_set_params ():
167+ # test nested estimator parameter setting
168+ clf = Pipeline ([("svc" , SVC ())])
169+ # non-existing parameter in svc
170+ assert_raises (ValueError , clf .set_params , svc__stupid_param = True )
171+ # non-existing parameter of pipeline
172+ assert_raises (ValueError , clf .set_params , svm__stupid_param = True )
173+ # we don't currently catch if the things in pipeline are estimators
174+ #bad_pipeline = Pipeline([("bad", NoEstimator())])
175+ #assert_raises(AttributeError, bad_pipeline.set_params,
176+ #bad__stupid_param=True)
0 commit comments