Repository: scikit-learn/scikit-learn
Pull request: [MRG] BUG: check equality instead of identity in check_cv
closes #12154 

Check for equality instead of identity which does not hold when n_jobs=-1 due to some copy.

Problem statement:
BUG: check_cv check for cv is 'warn' instead of cv == 'warn' which is raising an exception with n_jobs=-1
In `_split.py`, `cv is 'warn'` will not work as intended since cv will be copied if `n_jobs=-1`.

```python
from sklearn.datasets import load_iris                                               
from sklearn.model_selection import GridSearchCV                                     
from sklearn.model_selection import cross_validate                                   
from sklearn.svm import SVC                                                          
                                                                                     
X, y = load_iris(return_X_y=True)                                                    
clf = SVC(gamma='auto')                                                              
grid = GridSearchCV(clf, param_grid={'C': [1, 10]}, iid=False)                       
score = cross_validate(grid, X, y,                                                   
                       n_jobs=-1,                                                    
                       cv=5, error_score='raise')  # to remove deprecation warning
```

```pytb
ValueError: Expected cv as an integer, cross-validation object (from sklearn.model_selection) or an iterable. Got warn.
```

Hints from issue discussion:

Commit message: BUG: check equality instead of identity in check_cv

Patch to review:
diff --git a/sklearn/model_selection/_split.py b/sklearn/model_selection/_split.py
index 75c8e5d239d08..0aefbeb7f04e2 100644
--- a/sklearn/model_selection/_split.py
+++ b/sklearn/model_selection/_split.py
@@ -1939,7 +1939,7 @@ def check_cv(cv='warn', y=None, classifier=False):
         The return value is a cross-validator which generates the train/test
         splits via the ``split`` method.
     """
-    if cv is None or cv is 'warn':
+    if cv is None or cv == 'warn':
         warnings.warn(CV_WARNING, FutureWarning)
         cv = 3
 
diff --git a/sklearn/model_selection/tests/test_validation.py b/sklearn/model_selection/tests/test_validation.py
index 0d7a05f39d714..9f50ffe67ff3e 100644
--- a/sklearn/model_selection/tests/test_validation.py
+++ b/sklearn/model_selection/tests/test_validation.py
@@ -281,6 +281,17 @@ def test_cross_val_score():
                   error_score='raise')
 
 
+@pytest.mark.filterwarnings('ignore:You should specify a value for')  # 0.22
+def test_cross_validate_many_jobs():
+    # regression test for #12154: cv='warn' with n_jobs=-1 trigger a copy of
+    # the parameters leading to a failure in check_cv due to cv is 'warn'
+    # instead of cv == 'warn'.
+    X, y = load_iris(return_X_y=True)
+    clf = SVC(gamma='auto')
+    grid = GridSearchCV(clf, param_grid={'C': [1, 10]})
+    cross_validate(grid, X, y, n_jobs=-1)
+
+
 @pytest.mark.filterwarnings('ignore: You should specify a value')  # 0.22
 def test_cross_validate_invalid_scoring_param():
     X, y = make_classification(random_state=0)


Code review comments:
diff_hunk: @@ -281,6 +281,17 @@ def test_cross_val_score():
                   error_score='raise')
 
 
+@pytest.mark.filterwarnings('ignore:You should specify a value for')  # 0.22
+def test_cross_validate_many_jobs():
+    # regression test for #12154: cv='warn' with n_jobs=-1 trigger a copy of
+    # the parameters leading to a failure in check_cv due to cv is 'warn'
+    # instead of cv == 'warn'.
+    X, y = load_iris(return_X_y=True)
+    clf = SVC(gamma='auto')
+    grid = GridSearchCV(clf, param_grid={'C': [1, 10]})
+    cross_validate(grid, X, y, n_jobs=-1)
path: sklearn/model_selection/tests/test_validation.py
text: @user1:
`n_jobs=2` should be enough?

@author:
True