Floor the log axis lower bound when an explicit margin is set - #389
Floor the log axis lower bound when an explicit margin is set#389Sanjays2402 wants to merge 1 commit into
Conversation
The explicit-margin log branch of _range() computed out_lo as 10.0 ** (transformed_lo - pad) with no floor, so a wide domain (e.g. 1e-300 to 1e10 with margin=0.1) drove the exponent below the smallest representable double and the padded lower bound underflowed to 0.0, leaving a log axis with a non-positive lower bound. Apply the same np.nextafter(0.0, 1.0) floor the default-margin branch already uses. The lo / 10.0 clamp is deliberately not applied here because it would override an authored margin. Adds a regression test with a pathological-but-legal log domain. Closes reflex-dev#350
📝 WalkthroughWalkthroughThe explicit-margin log-axis calculation now prevents the lower bound from underflowing to zero. A regression test covers extreme data magnitudes and verifies a positive, ordered y-range. ChangesLog-axis margin handling
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/test_figure.py`:
- Around line 1692-1698: The test
test_log_explicit_margin_keeps_lower_bound_positive should verify the exact
positive minimum-float floor, not just that lo is positive. Add an assertion
that lo equals np.nextafter(0.0, 1.0), while retaining the existing hi > lo
check.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: bdbb4482-c00e-46ff-a515-8ae15c8afb0f
📒 Files selected for processing (2)
python/xy/_figure.pytests/test_figure.py
| def test_log_explicit_margin_keeps_lower_bound_positive(): | ||
| """An authored margin must not pad the lower bound down to zero.""" | ||
| fig = Figure().scatter(np.array([0.0, 1.0]), np.array([1e-300, 1e10])) | ||
| fig.set_axis("y", type_="log", margin=0.1) | ||
| lo, hi = fig.y_range() | ||
| assert lo > 0.0 | ||
| assert hi > lo |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert the intended floor, not only positivity.
This test would also pass with the prohibited lo / 10.0 clamp. Assert that lo == np.nextafter(0.0, 1.0) (or otherwise verify lo < 1e-300) so the regression test proves the explicit-margin path uses the positive minimum-float floor.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/test_figure.py` around lines 1692 - 1698, The test
test_log_explicit_margin_keeps_lower_bound_positive should verify the exact
positive minimum-float floor, not just that lo is positive. Add an assertion
that lo equals np.nextafter(0.0, 1.0), while retaining the existing hi > lo
check.
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/test_figure.py">
<violation number="1" location="tests/test_figure.py:1697">
P3: This assertion only checks `lo > 0.0`, which would also pass under the rejected `lo / 10.0` clamp approach. To actually prove the explicit-margin path uses the `np.nextafter(0.0, 1.0)` floor rather than some other positive clamp, assert the exact expected value (e.g. `lo == np.nextafter(0.0, 1.0)`) or a tight upper bound like `lo < 1e-300`.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
| fig = Figure().scatter(np.array([0.0, 1.0]), np.array([1e-300, 1e10])) | ||
| fig.set_axis("y", type_="log", margin=0.1) | ||
| lo, hi = fig.y_range() | ||
| assert lo > 0.0 |
There was a problem hiding this comment.
P3: This assertion only checks lo > 0.0, which would also pass under the rejected lo / 10.0 clamp approach. To actually prove the explicit-margin path uses the np.nextafter(0.0, 1.0) floor rather than some other positive clamp, assert the exact expected value (e.g. lo == np.nextafter(0.0, 1.0)) or a tight upper bound like lo < 1e-300.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/test_figure.py, line 1697:
<comment>This assertion only checks `lo > 0.0`, which would also pass under the rejected `lo / 10.0` clamp approach. To actually prove the explicit-margin path uses the `np.nextafter(0.0, 1.0)` floor rather than some other positive clamp, assert the exact expected value (e.g. `lo == np.nextafter(0.0, 1.0)`) or a tight upper bound like `lo < 1e-300`.</comment>
<file context>
@@ -1689,6 +1689,15 @@ def test_log_autorange_uses_positive_zone_stats():
+ fig = Figure().scatter(np.array([0.0, 1.0]), np.array([1e-300, 1e10]))
+ fig.set_axis("y", type_="log", margin=0.1)
+ lo, hi = fig.y_range()
+ assert lo > 0.0
+ assert hi > lo
+
</file context>
| assert lo > 0.0 | |
| assert lo == np.nextafter(0.0, 1.0) |
Closes #350
The explicit-margin log branch of
Figure._range()computedout_lo = 10.0 ** (transformed_lo - pad)with no floor, so a wide-but-legal domain (1e-300to1e10withmargin=0.1) pushed the padded exponent past the smallest representable double and the lower bound underflowed to0.0, leaving a log axis with a non-positive lower bound. This applies the samenp.nextafter(0.0, 1.0)floor the default-margin branch already uses; thelo / 10.0clamp is deliberately not carried over, since it would override an authored margin.Regression test added in
tests/test_figure.pybesidetest_log_autorange_uses_positive_zone_stats; it fails onmain(assert np.float64(0.0) > 0.0) and passes with the fix.tests/test_figure.pyis otherwise baseline-identical (15 pre-existing failures locally, all headless-browser PNG export).This change was prepared with AI assistance; the regression test was run locally and fails without the fix.
Summary by CodeRabbit