Skip to content

Fix NumPy array handling for plot limits - #2000

Merged
janfb merged 1 commit into
sbi-dev:mainfrom
dhruvb2028:fix-numpy-plot-limits
Sep 2, 2026
Merged

janfb merged 1 commit into
sbi-dev:mainfrom
dhruvb2028:fix-numpy-plot-limits

Conversation

@dhruvb2028

@dhruvb2028 dhruvb2028 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

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.

AI assistance was used for implementation and test preparation, I reviewed and
validated the final change.

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
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.
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, the implementation, the affected functions, the regression test, issue reference, validation results, AI assistance, and checklist status. It also clearly reports…
Full details: Description check

Explanation

The description explains the problem, the implementation, the affected functions, the regression test, issue reference, validation results, AI assistance, and checklist status. It also clearly reports the three environment-related test failures and explains their cause.

  • 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
Contributor 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?

@janfb

janfb commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Hi @dhruvb2028 , thanks for the PR. Please follow our contribution guidelines and first comment under an issue to signal you want to work on it. this will avoid duplicate work like you already noticed with the existing comment by @BHARATH0153. And it will help us maintainers to coordinate work and distribute our resources in a sustainable way.

Please also disclose whether you used AI to create this fix (see contribution guidelines). The early line breaks in the PR description look like a typical Claude Code artifact.

@codecov

codecov Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.43%. Comparing base (900821d) to head (c246ef8).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2000   +/-   ##
=======================================
  Coverage   89.43%   89.43%           
=======================================
  Files         140      140           
  Lines       14312    14312           
=======================================
  Hits        12800    12800           
  Misses       1512     1512           
Flag Coverage Δ
fast 84.23% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sbi/analysis/plot.py 77.18% <100.00%> (ø)

@dhruvb2028

Copy link
Copy Markdown
Contributor Author

@janfb Thanks for the feedback, and sorry for not commenting on the issue before opening the PR. I have now updated the description to disclose the AI assistance used.
I also noticed @BHARATH0153’s earlier comment. Since the fix is already complete and has regression coverage, I wanted to ask whether you would be comfortable keeping this PR open for review. I understand if you would prefer to prioritize their work instead.
I’ll make sure to comment on an issue before starting future contributions.

@janfb janfb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix @dhruvb2028 and the concise PR. LGTM!

@janfb
janfb merged commit b402501 into sbi-dev:main Sep 2, 2026
17 checks passed
@dhruvb2028
dhruvb2028 deleted the fix-numpy-plot-limits branch September 2, 2026 18:05
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.

2 participants