File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,13 @@ Fixed models
76
76
`CVE-2020-28975 <https://nvd.nist.gov/vuln/detail/CVE-2020-28975 >`__.
77
77
:pr: `21336 ` by `Thomas Fan `_.
78
78
79
+ :mod: `sklearn.utils `
80
+ ....................
81
+
82
+ - |Fix | Solve a bug in :func: `~sklearn.utils.metaestimators.if_delegate_has_method `
83
+ where the underlying check for an attribute did not work with NumPy arrays.
84
+ :pr: `21145 ` by :user: `Zahlii <Zahlii> `.
85
+
79
86
.. _changes_1_0 :
80
87
81
88
Version 1.0.0
Original file line number Diff line number Diff line change @@ -194,7 +194,9 @@ def _check(self, obj):
194
194
if delegate is None :
195
195
return False
196
196
# raise original AttributeError
197
- return getattr (delegate , self .attribute_name ) or True
197
+ getattr (delegate , self .attribute_name )
198
+
199
+ return True
198
200
199
201
200
202
def if_delegate_has_method (delegate ):
Original file line number Diff line number Diff line change
1
+ import numpy as np
1
2
import pytest
2
3
3
4
from sklearn .utils .metaestimators import if_delegate_has_method
@@ -69,6 +70,12 @@ class HasNoPredict:
69
70
pass
70
71
71
72
73
+ class HasPredictAsNDArray :
74
+ """A mock sub-estimator where predict is a NumPy array"""
75
+
76
+ predict = np .ones ((10 , 2 ), dtype = np .int64 )
77
+
78
+
72
79
def test_if_delegate_has_method ():
73
80
assert hasattr (MetaEst (HasPredict ()), "predict" )
74
81
assert not hasattr (MetaEst (HasNoPredict ()), "predict" )
@@ -122,3 +129,13 @@ def test_available_if_unbound_method():
122
129
match = "This 'AvailableParameterEstimator' has no attribute 'available_func'" ,
123
130
):
124
131
AvailableParameterEstimator .available_func (est )
132
+
133
+
134
+ def test_if_delegate_has_method_numpy_array ():
135
+ """Check that we can check for an attribute that is a NumPy array.
136
+
137
+ This is a non-regression test for:
138
+ https://github.com/scikit-learn/scikit-learn/issues/21144
139
+ """
140
+ estimator = MetaEst (HasPredictAsNDArray ())
141
+ assert hasattr (estimator , "predict" )
You can’t perform that action at this time.
0 commit comments