Skip to content

Commit 193075d

Browse files
committed
make verbosity level check explicit
1 parent 6e4f33d commit 193075d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

bayes_opt/logger.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,10 @@ def log_optimization_step(
258258
"""
259259
is_new_max = self._is_new_max(current_max)
260260
self._update_tracker(current_max)
261+
if self._verbose == 0:
262+
return
261263

262-
if self._verbose != 1 or is_new_max:
264+
if self._verbose == 2 or is_new_max:
263265
colour = self._colour_new_max if is_new_max else self._colour_regular_message
264266
line = self._print_step(result, keys, params_config, colour=colour) + "\n"
265267
if self._verbose:

tests/test_logger.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def test_log_optimization_step(mock_stdout):
243243

244244
# Create logger with verbose=1 specifically, as this is the only verbose level
245245
# that doesn't print for non-max points according to the implementation:
246-
# if self._verbose != 1 or is_new_max:
246+
# if self._verbose == 2 or is_new_max:
247247
logger.verbose = 1
248248

249249
# Clear any output that might have happened
@@ -274,6 +274,18 @@ def test_log_optimization_step(mock_stdout):
274274
assert max_output != "" # Something printed for new max point with verbose=1
275275
assert "4.0" in max_output # Should show target value
276276

277+
# Test with verbose=2 (should print even for non-max points)
278+
logger.verbose = 2
279+
optimizer.register(params={"p1": 1, "p2": 1}, target=1)
280+
mock_stdout.truncate(0)
281+
mock_stdout.seek(0)
282+
logger.log_optimization_step(
283+
optimizer._space.keys, optimizer._space.res()[-1], optimizer._space.params_config, optimizer.max
284+
)
285+
non_max_output = mock_stdout.getvalue()
286+
assert non_max_output != "" # Something printed for non-max point with verbose=2
287+
assert "1.0" in non_max_output # Should show target value
288+
277289

278290
@patch("sys.stdout", new_callable=io.StringIO)
279291
def test_log_optimization_end(mock_stdout):

0 commit comments

Comments
 (0)