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 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 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()

This comment has been minimized.

Copy link
@jnothman

jnothman Jul 25, 2019

Author Member

This was calling get_params before all attributes were set.

pass

def fit(self, X, y=None):
return self

This comment has been minimized.

Copy link
@jnothman

jnothman Jul 25, 2019

Author Member

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

return X

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

This comment has been minimized.

Copy link
@jnothman

jnothman Jul 25, 2019

Author Member

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

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

rth left a comment

Thanks @jnothman !

Copy link
Member

amueller left a comment

lgtm

@rth

This comment has been minimized.

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
16 of 17 checks passed
16 of 17 checks passed
codecov/patch 89.18% of diff hit (target 96.86%)
Details
LGTM analysis: C/C++ No code changes detected
Details
LGTM analysis: JavaScript No code changes detected
Details
LGTM analysis: Python No new or fixed alerts
Details
ci/circleci: deploy Your tests passed on CircleCI!
Details
ci/circleci: doc Your tests passed on CircleCI!
Details
ci/circleci: doc-min-dependencies Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
codecov/project 96.86% (-0.01%) compared to 5936ae3
Details
scikit-learn.scikit-learn Build #20190727.5 succeeded
Details
scikit-learn.scikit-learn (Linux py35_conda_openblas) Linux py35_conda_openblas succeeded
Details
scikit-learn.scikit-learn (Linux py35_ubuntu_atlas) Linux py35_ubuntu_atlas succeeded
Details
scikit-learn.scikit-learn (Linux pylatest_conda_mkl_pandas) Linux pylatest_conda_mkl_pandas succeeded
Details
scikit-learn.scikit-learn (Linux32 py35_ubuntu_atlas_32bit) Linux32 py35_ubuntu_atlas_32bit succeeded
Details
scikit-learn.scikit-learn (Windows py35_pip_openblas_32bit) Windows py35_pip_openblas_32bit succeeded
Details
scikit-learn.scikit-learn (Windows py37_conda_mkl) Windows py37_conda_mkl succeeded
Details
scikit-learn.scikit-learn (macOS pylatest_conda_mkl) macOS pylatest_conda_mkl succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.