12
12
13
13
from abc import ABCMeta , abstractmethod
14
14
from collections import defaultdict
8000
15
- from collections .abc import Mapping , Iterable
15
+ from collections .abc import Mapping , Sequence , Iterable
16
16
from functools import partial , reduce
17
17
from itertools import product
18
18
import numbers
@@ -94,7 +94,8 @@ class ParameterGrid:
94
94
def __init__ (self , param_grid ):
95
95
if not isinstance (param_grid , (Mapping , Iterable )):
96
96
raise TypeError (
97
- "Parameter grid is not a dict or a list ({!r})" .format (param_grid )
97
+ f"Parameter grid should be a dict or a list, got: { param_grid !r} of"
98
+ f" type { type (param_grid )} "
98
99
)
99
100
100
101
if isinstance (param_grid , Mapping ):
@@ -108,11 +109,23 @@ def __init__(self, param_grid):
108
109
raise TypeError ("Parameter grid is not a dict ({!r})" .format (grid ))
109
110
for key , value in grid .items ():
110
111
if isinstance (value , np .ndarray ) and value .ndim > 1 :
111
- raise ValueError ("Parameter array should be one-dimensional." )
112
- if not isinstance (grid [key ], Iterable ):
112
+ raise ValueError (
113
+ f"Parameter array for { key } should be one-dimensional, got:"
114
+ f" { value !r} with shape { value .shape } "
115
+ )
116
+ if isinstance (value , str ) or not isinstance (
117
+ value , (np .ndarray , Sequence )
118
+ ):
113
119
raise TypeError (
114
- "Parameter grid value is not iterable "
115
- "(key={!r}, value={!r})" .format (key , grid [key ])
120
+ f"Parameter grid for parameter { key !r} needs to be a list or a"
121
+ f" numpy array, but got { value !r} (of type { type (value )} )"
122
+ " instead. Single values need to be wrapped in a list with one"
123
+ " element."
124
+ )
125
+ if len (value ) == 0 :
126
+ raise ValueError (
127
+ f"Parameter grid for parameter { key !r} need "
128
+ f"to be a non-empty sequence, got: { value !r} "
116
129
)
117
130
118
131
self .param_grid = param_grid
0 commit comments