Skip to content

Commit 56ff0b5

Browse files
committed
correct the formatting for positive numbers with negative exponents and add additional test
1 parent 14786ff commit 56ff0b5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

bayes_opt/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _format_number(self, x: float) -> str:
8282
result = ""
8383
width = self._default_cell_size
8484
# Keep negative sign, exponent, and as many decimal places as possible
85-
if "-" in s:
85+
if x < 0:
8686
result += "-"
8787
width -= 1
8888
s = s[1:]

tests/test_logger.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ def test_format_number():
8787
assert len(formatted) == logger._default_cell_size
8888
assert formatted == "1.234e+13"
8989

90+
sci_float = 1.11111111e-5
91+
formatted = logger._format_number(sci_float)
92+
assert formatted == "1.111e-05"
93+
9094
# Test negative scientific notation truncation
9195
sci_float = -12345678901234.5678901234
9296
formatted = logger._format_number(sci_float)

0 commit comments

Comments
 (0)