Skip to content

Commit

Permalink
Added a try/except in case the bounds_transformer is not the correct …
Browse files Browse the repository at this point in the history
…type + test coverage
  • Loading branch information
Albert Alonso authored and fmfn committed Jul 13, 2020
1 parent e32b1fb commit 35a966a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bayes_opt/bayesian_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ def __init__(self, f, pbounds, random_state=None, verbose=2,
self._verbose = verbose
self._bounds_transformer = bounds_transformer
if self._bounds_transformer:
self._bounds_transformer.initialize(self._space)
try:
self._bounds_transformer.initialize(self._space)
except (AttributeError, TypeError):
raise AssertionError('The transformer must be instance of'
'DomainTransformer')

super(BayesianOptimization, self).__init__(events=DEFAULT_EVENTS)

Expand Down
8 changes: 8 additions & 0 deletions tests/test_bayesian_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def test_prime_subscriptions():
])

test_subscriber = "test_subscriber"

def test_callback(event, instance):
pass

Expand Down Expand Up @@ -291,6 +292,13 @@ def reset(self):
assert tracker.end_count == 3


def test_define_wrong_transformer():
with pytest.raises(AssertionError):
optimizer = BayesianOptimization(target_func, PBOUNDS,
random_state=np.random.RandomState(1),
bounds_transformer=3)


if __name__ == '__main__':
r"""
CommandLine:
Expand Down

0 comments on commit 35a966a

Please sign in to comment.