Skip to content

Commit aed6a25

Browse files
authored
fix: Incorrectly modified ScreenLogger (#512)
* fix: cells list -> deque * fix * fix * fix: deque -> list
1 parent 2bf4edd commit aed6a25

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

bayes_opt/logger.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import json
66
from contextlib import suppress
77
from pathlib import Path
8+
from typing import Any
89

910
import numpy as np
1011
from colorama import Fore, just_fix_windows_console
@@ -153,15 +154,16 @@ def _step(self, instance, colour=_colour_regular_message):
153154
-------
154155
A stringified, formatted version of the most recent optimization step.
155156
"""
156-
res = instance.res[-1]
157-
cells: list[str | None] = [None] * 4
157+
res: dict[str, Any] = instance.res[-1]
158+
keys: list[str] = instance.space.keys
159+
# iter, target, allowed [, *params]
160+
cells: list[str | None] = [None] * (3 + len(keys))
158161

159162
cells[:2] = self._format_number(self._iterations + 1), self._format_number(res["target"])
160163
if self._is_constrained:
161164
cells[2] = self._format_bool(res["allowed"])
162-
163-
for key in instance.space.keys:
164-
cells[3] = self._format_number(res["params"][key])
165+
params = res.get("params", {})
166+
cells[3:] = [self._format_number(params.get(key, float("nan"))) for key in keys]
165167

166168
return "| " + " | ".join(colour + x + self._colour_reset for x in cells if x is not None) + " |"
167169

@@ -177,14 +179,14 @@ def _header(self, instance):
177179
-------
178180
A stringified, formatted version of the most header.
179181
"""
180-
cells: list[str | None] = [None] * 4
182+
keys: list[str] = instance.space.keys
183+
# iter, target, allowed [, *params]
184+
cells: list[str | None] = [None] * (3 + len(keys))
181185

182186
cells[:2] = self._format_key("iter"), self._format_key("target")
183187
if self._is_constrained:
184188
cells[2] = self._format_key("allowed")
185-
186-
for key in instance.space.keys:
187-
cells[3] = self._format_key(key)
189+
cells[3:] = [self._format_key(key) for key in keys]
188190

189191
line = "| " + " | ".join(x for x in cells if x is not None) + " |"
190192
self._header_length = len(line)

0 commit comments

Comments
 (0)