Skip to content

Commit

Permalink
Better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
lesteve committed Nov 17, 2016
1 parent f15fe9c commit 6b1cf0f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sklearn/utils/estimator_checks.py
Expand Up @@ -1410,15 +1410,17 @@ def check_no_fit_attributes_set_in_init(name, Estimator):
"""Check that Estimator.__init__ doesn't set trailing-_ attributes."""
estimator = Estimator()
for attr in dir(estimator):
if attr.endswith("_") and not attr.startswith("_"):
if attr.endswith("_") and not attr.startswith("__"):
# This check is for properties, they can be listed in dir
# while at the same time have hasattr return False as long
# as the property getter raises an AttributeError
assert_false(
hasattr(estimator, attr),
"Fitted attributes ending with '_' should not be initialized "
'in the constructor of an estimator but instead in the '
'fit method itself. Attribute {0!r} was found'
"By convention, attributes ending with '_' are "
'estimated from data in scikit-learn. Consequently they '
'should not be initialized in the constructor of an '
'estimator but instead in the fit method '
'itself. Attribute {0!r} was found '
' in estimator {1}'.format(estimator, attr))


Expand Down

0 comments on commit 6b1cf0f

Please sign in to comment.