8000 [WIP] FIX avoid making deepcopy in clone by glemaitre · Pull Request #9696 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[WIP] FIX avoid making deepcopy in clone #9696

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

Closed
wants to merge 4 commits into from

Conversation

glemaitre
Copy link
Member

Reference Issue

closes #5563

What does this implement/fix? Explain your changes.

Do not trigger a deep copy of the parameters when cloning estimators.

Any other comments?

Copy link
Member
@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.

Thanks for this.

I think @amueller was proposing that we don't copy at all. I now realise that not copying at all will break grid search over pipeline where steps are substituted.

We will have to think carefully about this change.

sklearn/base.py Outdated
if deepcopy is None:
warnings.warn("A simple copy will be performed after 0.22 instead of a"
" deep copy. Set 'deepcopy=True' if you wish to make a"
" deep copy of the objects which are not estimators.",
Copy link
Member

Choose a reason for hiding this comment

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

Objects -> parameters

sklearn/base.py Outdated
Use ``deepcopy=True`` to get the previous behavior.

deepcopy : boolean, optional
Whether to make a deep copy or a simple copy of the objects that ware
Copy link
Member

Choose a reason for hiding this comment

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

Ware -> are

@glemaitre
Copy link
Member Author

@jnothman I will need to turn deepcopy to True or False to avoid triggering the warning.

Do we call all clone with deepcopy=False for all the current call or only a subset of them.

@ogrisel should also have the answer since that he raised the issue.

@jnothman
Copy link
Member
jnothman commented Sep 7, 2017 via email

Copy link
Member
@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.

I suppose the deepcopy=True case should be tested..?

Otherwise, the code looks okay (I'm not happy that it touches so much, and maybe we should note that we intend to get rid of the parameter).

Now I suppose we should merge it and wait for people to complain that it broke their code?

If safe is false, clone will fall back to a deep copy on objects
that are not estimators.

If safe is false, clone will fall back to a copy (deep copy or simple
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this be better described as "if True, the argument to clone must be an estimator (i.e. support get_params). Otherwise the object will be copied ..."

@@ -26,7 +27,7 @@ def _first_and_last_element(arr):
return arr[0, 0], arr[-1, -1]


def clone(estimator, safe=True):
def clone(estimator, safe=True, deepcopy=None):
Copy link
Member
@jnothman jnothman Oct 17, 2017

Choose a reason for hiding this comment

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

I've been preferring deepcopy='warn' and similar lately over None.

I wonder if we can instead use magic to check if the caller is internal to this library, and if so, just replace deepcopy='warn' with deepcopy=False.

import inspect

def is_caller_sklearn():
    caller = inspect.current_frame().f_back.f_back
    return caller is not None and caller.f_globals['__name__'].startswith('sklearn.')

@adrinjalali
Copy link
Member

I think we can close this for the same reason as #5563 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Needs Decision Requires decision
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clone should not really deepcopy constructor parameters
4 participants
0