Skip to content

Commit 34ee023

Browse files
authored
Update logger.py to reset color escape sequence in between values (#489)
* Update logger.py to reset color escape sequence in between values * Update target_space.py to reset colour after duplicate point warning * Default colour in logger messages is now Fore.RESET Also refer to colours via internal properties, _colour_new_max, _colour_regular_message, _colour_reset.
1 parent 3a5e56c commit 34ee023

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

bayes_opt/logger.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ class ScreenLogger(_Tracker):
4646

4747
_default_cell_size = 9
4848
_default_precision = 4
49-
49+
_colour_new_max = Fore.MAGENTA
50+
_colour_regular_message = Fore.RESET
51+
_colour_reset = Fore.RESET
52+
5053
def __init__(self, verbose=2, is_constrained=False):
5154
self._verbose = verbose
5255
self._is_constrained = is_constrained
@@ -136,7 +139,7 @@ def _format_key(self, key):
136139
return s[:self._default_cell_size - 3] + "..."
137140
return s
138141

139-
def _step(self, instance, colour=Fore.BLACK):
142+
def _step(self, instance, colour=_colour_regular_message):
140143
"""Log a step.
141144
142145
Parameters
@@ -145,7 +148,7 @@ def _step(self, instance, colour=Fore.BLACK):
145148
The instance associated with the event.
146149
147150
colour :
148-
(Default value = Fore.BLACK)
151+
(Default value = _colour_regular_message, equivalent to Fore.RESET)
149152
150153
Returns
151154
-------
@@ -163,7 +166,7 @@ def _step(self, instance, colour=Fore.BLACK):
163166
for key in instance.space.keys:
164167
cells.append(self._format_number(res["params"][key]))
165168

166-
return "| " + " | ".join([colour + cells[i] for i in range(len(cells))]) + " |"
169+
return "| " + " | ".join([colour + cells[i] + self._colour_reset for i in range(len(cells))]) + " |"
167170

168171
def _header(self, instance):
169172
"""Print the header of the log.
@@ -231,7 +234,7 @@ def update(self, event, instance):
231234
if self._verbose == 1 and not is_new_max:
232235
line = ""
233236
else:
234-
colour = Fore.MAGENTA if is_new_max else Fore.BLACK
237+
colour = self._colour_new_max if is_new_max else self._colour_regular_message
235238
line = self._step(instance, colour=colour) + "\n"
236239
elif event == Events.OPTIMIZATION_END:
237240
line = "=" * self._header_length + "\n"

bayes_opt/target_space.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def register(self, params, target, constraint_value=None):
302302
self.n_duplicate_points = self.n_duplicate_points + 1
303303

304304
print(Fore.RED + f'Data point {x} is not unique. {self.n_duplicate_points}'
305-
' duplicates registered. Continuing ...')
305+
' duplicates registered. Continuing ...' + Fore.RESET)
306306
else:
307307
raise NotUniqueError(f'Data point {x} is not unique. You can set'
308308
' "allow_duplicate_points=True" to avoid this error')

0 commit comments

Comments
 (0)