-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
FIX support both instance and class level methods in _AvailableIfDescriptor.__get__
#20623
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
Conversation
@harupy did you forget to commit one file ? |
@WeichenXu123 I just wanted to double-check if we can really reproduce the issue first. I'll update |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix @harupy. It seems that this PR is ready for review, right? It's still marked as draft.
sklearn/utils/metaestimators.py
Outdated
@@ -111,7 +111,10 @@ def __get__(self, obj, owner=None): | |||
) | |||
|
|||
# lambda, but not partial, allows help() to work with update_wrapper | |||
out = lambda *args, **kwargs: self.fn(obj, *args, **kwargs) # noqa | |||
if obj is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment to state that this makes it possible to use the decorated method as an unbound method, for instance when monkeypatching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it!
@ogrisel Thanks for the feedback! |
All reactions
Sorry, something went wrong.
sklearn/utils/metaestimators.py
Outdated
@@ -111,7 +111,10 @@ def __get__(self, obj, owner=None): | |||
) | |||
|
|||
# lambda, but not partial, allows help() to work with update_wrapper | |||
out = lambda *args, **kwargs: self.fn(obj, *args, **kwargs) # noqa | |||
if obj is None: | |||
out = lambda *args, **kwargs: self.fn(*args, **kwargs) # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this branch, we need also do delegation attribute exist checking first (and raise AttributeError if delegation attribute does not exist), and then call self.fn(*args, **kwargs)
Sorry, something went wrong.
All reactions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g.:
pipeline_instance.predict_proba(X)
it will raise 'predict_proba' attribute not found error when pipeline_instance._final_estimator
does not have predict_proba
attribute.
Similarly, when we call:
Pipeline.predict_proba(pipeline_instance, X)
it should also do the delegation object attribute exist checking before really call predict_proba
on delegated object.
Sorry, something went wrong.
All reactions
Signed-off-by: harupy <hkawamura0130@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, something went wrong.
All reactions
_AvailableIfDescriptor.__get__
_AvailableIfDescriptor.__get__
Thanks @harupy for finding and solving this issue. |
All reactions
-
👍 1 reaction
Sorry, something went wrong.
jnothman
WeichenXu123
ogrisel
glemaitre
Successfully merging this pull request may close these issues.
Bug when using a function decorated byif_delegate_has_method
Reference Issues/PRs
Fixes #20614
What does this implement/fix? Explain your changes.
Fix this line:
scikit-learn/sklearn/utils/metaestimators.py
Line 114 in 5d88f9a
to:
Any other comments?