Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 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 @@ -96,8 +96,6 @@ def _format_number(self, x: float) -> str:
width -= dot_pos
if width > 0:
result += s[dot_pos : dot_pos + width]
else:
result += s[: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