Skip to content

Commit 6e1418e

Browse files
authored
ValueError that is thrown by _check_param_grid method now includes parameters name when values of a parameter have incorrect type.
Old ValueError: ValueError: Parameter values should be a list. New ValueError: ValueError: Parameter(key1) values should be a non-empty list.
1 parent a18344e commit 6e1418e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

sklearn/grid_search.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff 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({0}) values should be a list."
336+
"".format(name))
336337

337338
if len(v) == 0:
338-
raise ValueError("Parameter values should be a non-empty "
339-
"list.")
339+
raise ValueError("Parameter({0}) values should be a non-empty "
340+
"list.".format(name))
340341

341342

342343
class _CVScoreTuple (namedtuple('_CVScoreTuple',

0 commit comments

Comments
 (0)