-
Notifications
You must be signed in to change notification settings - Fork 1.6k
correct the formatting for positive numbers with negative exponents and add additional test #590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…nd add additional test
WalkthroughChange numeric sign handling and truncation in bayes_opt/logger.py to use the numeric value (x < 0) and avoid replacing the leading digit for small scientific-notation values; add unit tests covering positive and negative small-magnitude scientific notation. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Caller
participant L as logger._format_number
Note over L: High-level formatting flow
C->>L: _format_number(x, width, prec)
alt x < 0
L->>L: sign = "-"
L->>L: mag = abs(x)
L->>L: width = width - 1
else
L->>L: sign = ""
L->>L: mag = x
end
L->>L: fmt = format(mag, choose fixed or scientific)
alt scientific notation (has "e")
L->>L: split into mantissa and exponent
L->>L: truncate mantissa only when decimal point present
L->>L: append exponent (normalized, e.g., e-05)
else
L->>L: handle decimal rounding/truncation as before
end
L->>L: result = sign + formatted(mantissa [+ exponent])
L->>L: pad result to requested width
L-->>C: formatted string
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Assessment against linked issues
Pre-merge checks (5 passed)✅ Passed checks (5 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #590 +/- ##
==========================================
+ Coverage 97.80% 97.89% +0.08%
==========================================
Files 10 10
Lines 1186 1185 -1
==========================================
Hits 1160 1160
+ Misses 26 25 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
bayes_opt/logger.py (1)
93-103
: Avoid potential exponent duplication when no decimal point exists.If
s
contains'e'
but no'.'
(rare, but possible withstr(x)
),result += s[:width]
followed byresult += end
can duplicate the exponent. Minor guard below keeps only the mantissa before appendingend
.- else: - result += s[:width] + else: + # Use only the mantissa when no decimal point is present to avoid duplicating the exponent. + head = s[:e_pos] if "e" in s else s + result += head[:width]tests/test_logger.py (1)
90-93
: Great regression test covering the reported bug.This precisely guards against the false-negative formatting for positive numbers with negative exponents. Consider also adding the negative counterpart for symmetry.
sci_float = 1.11111111e-5 formatted = logger._format_number(sci_float) assert formatted == "1.111e-05" + + # Symmetric negative case + sci_float_neg = -1.11111111e-5 + formatted = logger._format_number(sci_float_neg) + assert formatted == "-1.111e-05"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
bayes_opt/logger.py
(1 hunks)tests/test_logger.py
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/test_logger.py (1)
bayes_opt/logger.py (1)
_format_number
(66-106)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Python 3.12 - numpy >=1.25,<2
- GitHub Check: Python 3.9 - numpy >=2
- GitHub Check: Python 3.11 - numpy >=1.25,<2
- GitHub Check: Python 3.10 - numpy >=2
- GitHub Check: Python 3.9 - numpy >=1.25,<2
- GitHub Check: Python 3.11 - numpy >=2
- GitHub Check: Python 3.13 - numpy >=2
- GitHub Check: Python 3.12 - numpy >=2
- GitHub Check: Python 3.10 - numpy >=1.25,<2
🔇 Additional comments (1)
bayes_opt/logger.py (1)
85-89
: Correct fix for false negatives from exponent substrings.Switching to
x < 0
removes the accidental sign detection from'e-XX'
and resolves the reported formatting bug. Looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be fine with merging this as-is, but maybe check if the clanker had some nitpicks worth considering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I think it makes sense to add coverage of this little bit of added code.
Fixing #589 (comment)
I was checking whether a minus sign was present, the formatter will now check that the number is negative when formatting for a negative number
Summary by CodeRabbit
Bug Fixes
Tests