Skip to content

Commit 214a482

Browse files
committed
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 214a482

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
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',

sklearn/model_selection/_search.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,18 @@ def _check_param_grid(param_grid):
327327
param_grid = [param_grid]
328328

329329
for p in param_grid:
330-
for v in p.values():
330+
for name, v in p.items():
331331
if isinstance(v, np.ndarray) and v.ndim > 1:
332332
raise ValueError("Parameter array should be one-dimensional.")
333333

334334
check = [isinstance(v, k) for k in (list, tuple, np.ndarray)]
335335
if True not in check:
336-
raise ValueError("Parameter values should be a list.")
336+
raise ValueError("Parameter({0}) values should be a list."
337+
"".format(name))
337338

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

342343

343344
# XXX Remove in 0.20

0 commit comments

Comments
 (0)