File tree Expand file tree Collapse file tree 3 files changed +26
-8
lines changed Expand file tree Collapse file tree 3 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -326,17 +326,18 @@ def _check_param_grid(param_grid):
326326 param_grid = [param_grid ]
327327
328328 for p in param_grid :
329- for v in p .values ():
329+ for name , v in p .items ():
330330 if isinstance (v , np .ndarray ) and v .ndim > 1 :
331331 raise ValueError ("Parameter array should be one-dimensional." )
332332
333333 check = [isinstance (v , k ) for k in (list , tuple , np .ndarray )]
334334 if True not in check :
335- raise ValueError ("Parameter values should be a list." )
335+ raise ValueError ("Parameter values for parameter ({0}) need "
336+ "to be a sequence." .format (name ))
336337
337338 if len (v ) == 0 :
338- raise ValueError ("Parameter values should be a non-empty "
339- "list." )
339+ raise ValueError ("Parameter values for parameter ({0}) need "
340+ "to be a non-empty sequence." . format ( name ) )
340341
341342
342343class _CVScoreTuple (namedtuple ('_CVScoreTuple' ,
Original file line number Diff line number Diff line change @@ -328,17 +328,18 @@ def _check_param_grid(param_grid):
328328 param_grid = [param_grid ]
329329
330330 for p in param_grid :
331- for v in p .values ():
331+ for name , v in p .items ():
332332 if isinstance (v , np .ndarray ) and v .ndim > 1 :
333333 raise ValueError ("Parameter array should be one-dimensional." )
334334
335335 check = [isinstance (v , k ) for k in (list , tuple , np .ndarray )]
336336 if True not in check :
337- raise ValueError ("Parameter values should be a list." )
337+ raise ValueError ("Parameter values for parameter ({0}) need "
338+ "to be a sequence." .format (name ))
338339
339340 if len (v ) == 0 :
340- raise ValueError ("Parameter values should be a non-empty "
341- "list." )
341+ raise ValueError ("Parameter values for parameter ({0}) need "
342+ "to be a non-empty sequence." . format ( name ) )
342343
343344
344345# XXX Remove in 0.20
Original file line number Diff line number Diff line change @@ -168,6 +168,22 @@ def test_grid_search():
168168 assert_raises (ValueError , grid_search .fit , X , y )
169169
170170
171+ def test_grid_search_incorrect_param_grid ():
172+ clf = MockClassifier ()
173+ assert_raise_message (
174+ ValueError ,
175+ "Parameter values for parameter (C) need to be a sequence." ,
176+ GridSearchCV , clf , {'C' : 1 })
177+
178+
179+ def test_grid_search_param_grid_includes_sequence_of_a_zero_length ():
180+ clf = MockClassifier ()
181+ assert_raise_message (
182+ ValueError ,
183+ "Parameter values for parameter (C) need to be a non-empty sequence." ,
184+ GridSearchCV , clf , {'C' : []})
185+
186+
171187@ignore_warnings
172188def test_grid_search_no_score ():
173189 # Test grid-search on classifier that has no score function.
You can’t perform that action at this time.
0 commit comments