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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions sklearn/utils/_param_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ class _InstancesOf(_Constraint):

Parameters
----------
type : type
The valid type.
param_type : param_type
The valid paramater type.
"""

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


def _type_name(self, t):
"""Convert type into human readable string."""
Expand All @@ -193,10 +193,10 @@ def _type_name(self, t):
return f"{module}.{qualname}"

def is_satisfied_by(self, val):
return isinstance(val, self.type)
return isinstance(val, self.param_type)

def __str__(self):
return f"an instance of {self._type_name(self.type)!r}"
return f"an instance of {self._type_name(self.param_type)!r}"


class _NoneConstraint(_Constraint):
Expand Down
0