8000 [MRG] Fix sklearn.utils._param_validation._InstancesOf is insufficient for numpy data types by Diadochokinetic · Pull Request #23600 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG] Fix sklearn.utils._param_validation._InstancesOf is insufficient for numpy data types #23600

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

Conversation

Diadochokinetic
Copy link
Contributor

Reference Issues/PRs

Fixes #23599

What does this implement/fix? Explain your changes.

sklearn.utils._param_validation._InstancesOf currently doesn't support numpy data types. The fix changes self.type into self.param_type to allow testing for different types than the built-in 'type'.

Any other comments?

This fix is necessary to implement validate_params (#23462) in objects that have numpy data types as parameters (e.g. #23579).

@Diadochokinetic Diadochokinetic changed the title Fix sklearn.utils._param_validation._InstancesOf is insufficient for numpy data types [MRG] Fix sklearn.utils._param_validation._InstancesOf is insufficient for numpy data types Jun 12, 2022
Copy link
Member
@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! I do not think this PR changes the behavior of _InstancesOf.

def __init__(self, type):
self.type = type
def __init__(self, param_type):
self.param_type = param_type
Copy link
Member

Choose a reason for hiding this comment

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

As commented in #23599 (comment):

The "type" here is not the builtin type anymore but the locally scoped "type". A simple Python example:

class A:
    def __init__(self, type):
        self.type = type
        
a = A(100)
print(a.type)
# 100

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for clarifiying

@Diadochokinetic Diadochokinetic deleted the enhance_instancesof branch June 14, 2022 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sklearn.utils._param_validation._InstancesOf is insufficient for numpy data types
2 participants
0