Skip to content

Commit 916be28

Browse files
committed
simplify code and flake8
1 parent 1bd3936 commit 916be28

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

ConfigSpace/read_and_write/pcs_new.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -420,24 +420,22 @@ def read(pcs_string, debug=False):
420420
forbidden_value = int(tmp_list[2])
421421
elif isinstance(hp, FloatHyperparameter):
422422
forbidden_value = float(tmp_list[2])
423+
else:
424+
raise NotImplementedError
423425
if forbidden_value < hp.lower or forbidden_value > hp.upper:
424-
# TODO alternatively we could raise an warning and ignore this
425426
raise ValueError(f'forbidden_value is set out of the bound, it needs to'
426427
f' be set between [{hp.lower}, {hp.upper}]'
427428
f' but its value is {forbidden_value}')
428429
elif isinstance(hp, (CategoricalHyperparameter, OrdinalHyperparameter)):
429430
hp_values = hp.choices if isinstance(hp, CategoricalHyperparameter)\
430431
else hp.sequence
431-
forbidden_value_in_hp_values = False
432-
for hp_value in hp_values:
433-
if str(hp_value) == tmp_list[2]:
434-
forbidden_value = hp_value
435-
forbidden_value_in_hp_values = True
436-
break
437-
if not forbidden_value_in_hp_values:
438-
raise ValueError(f'forbidden_value is set out of the bound, it needs to'
439-
f' be set as one member of {hp_values}'
440-
f' but its value is {forbidden_value}')
432+
forbidden_value_in_hp_values = tmp_list[2] in hp_values
433+
if forbidden_value_in_hp_values:
434+
forbidden_value = tmp_list[2]
435+
else:
436+
raise ValueError(f'forbidden_value is set out of the allowed value '
437+
f'sets, it needs to be one member from {hp_values} '
438+
f'but its value is {forbidden_value}')
441439
else:
442440
raise ValueError('Unsupported Hyperparamter sorts')
443441

test/read_and_write/test_pcs_converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ def test_read_new_configuration_space_forbidden(self):
415415

416416
cat_hp_str_forbidden = ForbiddenAndConjunction(ForbiddenEqualsClause(cat_hp_str, 'a'))
417417
ord_hp_float_forbidden = ForbiddenAndConjunction(ForbiddenEqualsClause(ord_hp_str, 'a'))
418-
cs_with_forbidden.add_forbidden_clauses([int_hp_forbidden, float_hp_forbidden, cat_hp_str_forbidden,
419-
ord_hp_float_forbidden])
418+
cs_with_forbidden.add_forbidden_clauses([int_hp_forbidden, float_hp_forbidden,
419+
cat_hp_str_forbidden, ord_hp_float_forbidden])
420420

421421
complex_cs = list()
422422
complex_cs.append("int_hp integer [0,50] [30]")

0 commit comments

Comments
 (0)