Skip to content

Commit 18656a9

Browse files
committed
Fix TypeError in parameter space validation test for skopt dimensions
- Added explicit handling for `skopt.space.Categorical`, `Integer`, and `Real` objects in `_validate_parameter_space`. - Prevents `TypeError: 'Integer' object is not iterable` when Bayesian parameter spaces are encountered during grid search validation. - Ensures `reduced_grid` is correctly populated with boundary values for `Integer`/`Real` and categories for `Categorical`.
1 parent c32b4e2 commit 18656a9

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

tests/test_model_classes_param_spaces.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,19 @@ def _validate_parameter_space(self, classifier_class_def, module_name, is_bayes)
306306
elif not values:
307307
continue
308308
# Check if all values are numeric (int or float)
309-
is_numeric = all(isinstance(v, (int, float)) for v in values)
310-
if is_numeric and len(values) > 2:
311-
reduced_grid[param] = [min(values), max(values)]
309+
if isinstance(values, Categorical):
310+
reduced_grid[param] = values.categories
312311
else:
313-
# Keep all values for categorical or short lists
314-
reduced_grid[param] = values
312+
# Handle skopt Integer/Real that might leak into grid space definitions
313+
if isinstance(values, (Integer, Real)):
314+
reduced_grid[param] = [values.low, values.high]
315+
else:
316+
is_numeric = all(isinstance(v, (int, float)) for v in values)
317+
if is_numeric and len(values) > 2:
318+
reduced_grid[param] = [min(values), max(values)]
319+
else:
320+
# Keep all values for categorical or short lists
321+
reduced_grid[param] = values
315322

316323
if not reduced_grid:
317324
continue

0 commit comments

Comments
 (0)