Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jnothman
Copy link
Member

Reference Issues/PRs

Fixes #14461

What does this implement/fix? Explain your changes.

Previously, the default implementation of get_params would use getattr to retrieve a parameter value from an estimator, but would default to retrieve None if an AttributeError would otherwise have been raised.

This can lead to surprising behaviour upon clone when __init__ is not correctly defined, as shown in #14461.

I propose that we raise an AttributeError when a param cannot be retrieved by getattr. This PR deprecates returning None, and raises a FutureWarning.

Any other comments?

TODO: add tests

Copy link
Member Author

@jnothman jnothman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amueller would probably like this tightening of our __init__ expectations


def __init__(self, steps, memory=None, verbose=False):
self.steps = steps
self._validate_steps()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was calling get_params before all attributes were set.

pass

def fit(self, X, y=None):
return self
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage is missing on lines like this, which I think is fine.

return X

def diag(self, X):
return np.ones(X.shape[0])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage is missing on lines like this, which I think is fine.

Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jnothman !

Copy link
Member

@amueller amueller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rth
Copy link
Member

rth commented Jul 26, 2019

Even if affected users will see the warning maybe it's also worth adding a what's new entry?

@jnothman jnothman merged commit 0279108 into scikit-learn:master Jul 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloning custom transform replaces values in __init__ dictionary

3 participants