Skip to content

[MRG] BUG: check equality instead of identity in check_cv #12155

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

Merged
merged 3 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions sklearn/model_selection/_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class KFold(_BaseKFold):

def __init__(self, n_splits='warn', shuffle=False,
random_state=None):
if n_splits is 'warn':
if n_splits == 'warn':
warnings.warn(NSPLIT_WARNING, FutureWarning)
n_splits = 3
super(KFold, self).__init__(n_splits, shuffle, random_state)
Expand Down Expand Up @@ -493,7 +493,7 @@ class GroupKFold(_BaseKFold):
stratification of the dataset.
"""
def __init__(self, n_splits='warn'):
if n_splits is 'warn':
if n_splits == 'warn':
warnings.warn(NSPLIT_WARNING, FutureWarning)
n_splits = 3
super(GroupKFold, self).__init__(n_splits, shuffle=False,
Expand Down Expand Up @@ -594,7 +594,7 @@ class StratifiedKFold(_BaseKFold):
"""

def __init__(self, n_splits='warn', shuffle=False, random_state=None):
if n_splits is 'warn':
if n_splits == 'warn':
warnings.warn(NSPLIT_WARNING, FutureWarning)
n_splits = 3
super(StratifiedKFold, self).__init__(n_splits, shuffle, random_state)
Expand Down Expand Up @@ -748,7 +748,7 @@ class TimeSeriesSplit(_BaseKFold):
where ``n_samples`` is the number of samples.
"""
def __init__(self, n_splits='warn', max_train_size=None):
if n_splits is 'warn':
if n_splits == 'warn':
warnings.warn(NSPLIT_WARNING, FutureWarning)
n_splits = 3
super(TimeSeriesSplit, self).__init__(n_splits,
Expand Down Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions sklearn/model_selection/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=2)


@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)
Expand Down