-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG] Test __array_function__ not called in non-estimator API (#15865) #18292
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -23,8 +23,21 @@ | |||||
from sklearn.preprocessing import scale | ||||||
from sklearn.utils import parallel_backend | ||||||
from sklearn.utils._testing import _convert_container | ||||||
from sklearn.utils.estimator_checks import _NotAnArray | ||||||
|
||||||
|
||||||
def test_array_function_not_called(): | ||||||
X = np.array([[1, 1], [1, 2], [1, 3], [1, 4], | ||||||
[2, 1], [2, 2], [2, 3], [2, 4], | ||||||
[3, 1], [3, 2], [3, 3], [3, 4]]) | ||||||
X = _NotAnArray(X) | ||||||
y = _NotAnArray([1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2]) | ||||||
estimator = LogisticRegression() | ||||||
estimator.fit(X, y) | ||||||
rng = np.random.RandomState(42) | ||||||
permutation_importance(estimator, X, y, n_repeats=5, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the test is based on
Suggested change
|
||||||
random_state=rng, n_jobs=1) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not need to include
Suggested change
|
||||||
|
||||||
|
||||||
@pytest.mark.parametrize("n_jobs", [1, 2]) | ||||||
def test_permutation_importance_correlated_feature_regression(n_jobs): | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -14,6 +14,7 @@ | |||||||
|
||||||||
from sklearn.model_selection.tests.test_search import FailingClassifier | ||||||||
|
||||||||
from sklearn.utils.estimator_checks import _NotAnArray | ||||||||
from sklearn.utils._testing import assert_almost_equal | ||||||||
from sklearn.utils._testing import assert_raises | ||||||||
from sklearn.utils._testing import assert_raise_message | ||||||||
|
@@ -226,6 +227,17 @@ def get_params(self, deep=False): | |||||||
return {'a': self.a, 'allow_nd': self.allow_nd} | ||||||||
|
||||||||
|
||||||||
def test_array_function_not_called(): | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here and nit about moving the test to the end of the file.
Suggested change
|
||||||||
X = np.array([[1, 1], [1, 2], [1, 3], [1, 4], | ||||||||
[2, 1], [2, 2], [2, 3], [2, 4], | ||||||||
[3, 1], [3, 2], [3, 3], [3, 4]]) | ||||||||
X = _NotAnArray(X) | ||||||||
y = _NotAnArray([1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2]) | ||||||||
estimator = LogisticRegression() | ||||||||
grid = GridSearchCV(estimator, param_grid={'C': [1, 10]}) | ||||||||
cross_validate(grid, X, y, n_jobs=2) | ||||||||
Comment on lines
+237
to
+238
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think we need nested cross validation to check that
Suggested change
Also |
||||||||
|
||||||||
|
||||||||
# XXX: use 2D array, since 1D X is being detected as a single sample in | ||||||||
# check_consistent_length | ||||||||
X = np.ones((10, 2)) | ||||||||
|
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.
To provide context for future maintainers that are not familiar with NEP18:
Small nit: may this test be moved to the end of the file?