Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API don't default get_params output to None in the future #14464

Merged
merged 3 commits into from Jul 28, 2019

Conversation

jnothman
Copy link
Member

@jnothman jnothman commented Jul 25, 2019

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

@amueller would probably like this tightening of our __init__ expectations

@@ -127,9 +127,9 @@ class Pipeline(_BaseComposition):

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

@jnothman jnothman Jul 25, 2019

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

@jnothman jnothman Jul 25, 2019

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

@jnothman jnothman Jul 25, 2019

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.

rth
rth approved these changes Jul 25, 2019
Copy link
Member

@rth rth left a comment

Thanks @jnothman !

Copy link
Member

@amueller amueller left a comment

lgtm

@rth
Copy link
Member

@rth 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
16 of 17 checks passed
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.

3 participants