@@ -390,7 +390,8 @@ def test_stratified_kfold_ratios(k, shuffle):
390390 distr = np .bincount (y ) / len (y )
391391
392392 test_sizes = []
393- skf = StratifiedKFold (k , random_state = 0 , shuffle = shuffle )
393+ random_state = None if not shuffle else 0
394+ skf = StratifiedKFold (k , random_state = random_state , shuffle = shuffle )
394395 for train , test in skf .split (X , y ):
395396 assert_allclose (np .bincount (y [train ]) / len (train ), distr , atol = 0.02 )
396397 assert_allclose (np .bincount (y [test ]) / len (test ), distr , atol = 0.02 )
@@ -409,9 +410,10 @@ def test_stratified_kfold_label_invariance(k, shuffle):
409410 X = np .ones (len (y ))
410411
411412 def get_splits (y ):
413+ random_state = None if not shuffle else 0
412414 return [(list (train ), list (test ))
413415 for train , test
414- in StratifiedKFold (k , random_state = 0 ,
416+ in StratifiedKFold (k , random_state = random_state ,
415417 shuffle = shuffle ).split (X , y )]
416418
417419 splits_base = get_splits (y )
@@ -1582,3 +1584,12 @@ def test_leave_p_out_empty_trainset():
15821584 ValueError ,
15831585 match = 'p=2 must be strictly less than the number of samples=2' ):
15841586 next (cv .split (X , y , groups = [1 , 2 ]))
1587+
1588+
1589+ @pytest .mark .parametrize ('Klass' , (KFold , StratifiedKFold ))
1590+ def test_random_state_shuffle_false (Klass ):
1591+ # passing a non-default random_state when shuffle=False makes no sense
1592+ # TODO 0.24: raise a ValueError instead of a warning
1593+ with pytest .warns (DeprecationWarning ,
1594+ match = 'has no effect since shuffle is False' ):
1595+ Klass (3 , shuffle = False , random_state = 0 )
0 commit comments