8000 Add set_param check and test · scikit-learn/scikit-learn@f865379 · GitHub
[go: up one dir, main page]

Skip to content

Commit f865379

Browse files
Add set_param check and test
1 parent 379f54b commit f865379

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

sklearn/utils/estimator_checks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ def param_filter(p):
14571457
# true for mixins
14581458
return
14591459
params = estimator.get_params()
1460+
estimator.set_params(**params)
14601461
if name in META_ESTIMATORS:
14611462
# they can need a non-default argument
14621463
init_params = init_params[1:]

sklearn/utils/tests/test_estimator_checks.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ def predict(self, X):
2828
return np.ones(X.shape[0])
2929

3030

31+
class NoSetter(BaseBadClassifier):
32+
def __init__(self, p=None):
33+
self._p = p
34+
35+
@property
36+
def p(self):
37+
return self._p
38+
39+
3140
class NoCheckinPredict(BaseBadClassifier):
3241
def fit(self, X, y):
3342
X, y = check_X_y(X, y)
@@ -66,6 +75,9 @@ def test_check_estimator():
6675
# check that we have a set_params and can clone
6776
msg = "it does not implement a 'get_params' methods"
6877
assert_raises_regex(TypeError, msg, check_estimator, object)
78+
# check that properties can be set
79+
msg = "can't set attribute"
80+
assert_raises_regex(AttributeError, msg, check_estimator, NoSetter)
6981
# check that we have a fit method
7082
msg = "object has no attribute 'fit'"
7183
assert_raises_regex(AttributeError, msg, check_estimator, BaseEstimator)

0 commit comments

Comments
 (0)
0