Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bayes_opt/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _format_number(self, x: float) -> str:
result = ""
width = self._default_cell_size
# Keep negative sign, exponent, and as many decimal places as possible
if "-" in s:
if x < 0:
result += "-"
width -= 1
s = s[1:]
Expand All @@ -97,7 +97,8 @@ def _format_number(self, x: float) -> str:
if width > 0:
result += s[dot_pos : dot_pos + width]
else:
result += s[:width]
head = s[:e_pos] if "e" in s else s
result += head[:width]
if "e" in s:
result += end
result = result.ljust(self._default_cell_size)
Expand Down
9 changes: 8 additions & 1 deletion tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ def test_format_number():
assert len(formatted) == logger._default_cell_size
assert formatted == "1.234e+13"

# Test negative scientific notation truncation
sci_float = 1.11111111e-5
formatted = logger._format_number(sci_float)
assert formatted == "1.111e-05"

sci_float_neg = -1.11111111e-5
formatted = logger._format_number(sci_float_neg)
assert formatted == "-1.11e-05"

sci_float = -12345678901234.5678901234
formatted = logger._format_number(sci_float)
assert len(formatted) == logger._default_cell_size
Expand Down