-
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
base: master
Are you sure you want to change the base?
Conversation
…nd add additional test
WalkthroughUpdates numeric sign handling and truncation in bayes_opt/logger.py to use the numeric value (x < 0) and to avoid replacing the leading digit when formatting small scientific-notation values; adds unit tests for 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, decide fixed or scientific)
alt scientific notation
L->>L: split into mantissa and exponent
L->>L: truncate mantissa to available width/precision
L->>L: append normalized exponent (e.g., e-05)
else
L->>L: truncate/round decimal part 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
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ 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). (10)
✨ 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #590 +/- ##
==========================================
- Coverage 97.80% 97.72% -0.09%
==========================================
Files 10 10
Lines 1186 1187 +1
==========================================
Hits 1160 1160
- Misses 26 27 +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.
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