Skip to content

Fix NumPy array handling for plot limits - #2000

Open
dhruvb2028 wants to merge 1 commit into
sbi-dev:mainfrom
dhruvb2028:fix-numpy-plot-limits
Open

Fix NumPy array handling for plot limits#2000
dhruvb2028 wants to merge 1 commit into
sbi-dev:mainfrom
dhruvb2028:fix-numpy-plot-limits

Conversation

@dhruvb2028

Copy link
Copy Markdown

What does this PR do?

prepare_for_plot() currently checks for empty limits using limits == [].
For NumPy arrays, this performs an element-wise comparison and can raise a
broadcasting error.

This PR replaces that comparison with a length check, updates the pairplot()
and marginal_plot() type hints to include NumPy arrays, and adds a regression
test verifying that NumPy limits are applied to the correct plot axes.

Does this close any issues?

Addresses the NumPy limits item in #1978.

Anything else we should know?

Validation performed:

  • uv run pytest tests/plot_test.py: 496 passed, 9 xfailed.
  • Ruff check and formatting checks passed for the changed files.
  • uv run pyright sbi: 0 errors.
  • Pre-commit hooks passed for the changed files.
  • The non-slow, non-GPU suite completed with 6601 passed, 38 skipped, 120
    xfailed, and three environment-related PyTensor failures. Those three tests
    passed when rerun using PyTensor's Python fallback instead of the incompatible
    local MinGW compiler.

Checklist

  • I have read the contributing guide.
  • uv run pytest -n auto -m "not slow and not gpu" passes.
  • uv run pre-commit run --all-files passes (ruff and formatting).
  • uv run pyright sbi passes.
  • I added or updated tests for the changed behavior.
  • I used Google-style docstrings for new or changed public functions.
  • (If applicable) I reported how long new tests run and marked slow ones
    with pytest.mark.slow.

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3b42b5cd-8631-4b72-a5ba-84f0899a032f

📥 Commits

Reviewing files that changed from the base of the PR and between 900821d and c246ef8.

📒 Files selected for processing (2)
  • sbi/analysis/plot.py
  • tests/plot_test.py

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Changes

NumPy plot limits

Layer / File(s) Summary
Accept and validate NumPy limits
sbi/analysis/plot.py, tests/plot_test.py
marginal_plot and pairplot accept NumPy array limits. prepare_for_plot checks empty limits by length. A regression test verifies diagonal and off-diagonal axis bounds.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to c246e

This localized change fixes NumPy plot-limit handling and adds regression coverage; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: janfb

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing NumPy array handling for plot limits.
Description check ✅ Passed The description explains the problem, solution, affected functions, issue reference, regression test, validation results, and checklist status. It also documents the three environment-related test fai…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem, solution, affected functions, issue reference, regression test, validation results, and checklist status. It also documents the three environment-related test failures and their fallback reruns.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dhruvb2028

Copy link
Copy Markdown
Author

I noticed after opening this PR that @BHARATH0153 had already described a fix for item 1 in #1978. I’m sorry I missed that comment. I couldn’t find a linked PR or public branch for the change, so could you confirm whether that work is still active?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant