Skip to content

fix: warn visibly about deprecated pairplot kwargs, drop a stray label under the legend - #2160

Open
dgedon wants to merge 5 commits into
sbi-dev:mainfrom
dgedon:fix/plot-deprecated-kwargs-warning
Open

dgedon wants to merge 5 commits into
sbi-dev:mainfrom
dgedon:fix/plot-deprecated-kwargs-warning

Conversation

@dgedon

@dgedon dgedon commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Passing old-style keyword arguments such as legend=True or samples_labels=[...] to pairplot or marginal_plot sends the whole call to the pre-v0.23 implementation (pairplot_dep, marginal_plot_dep). That path has three problems:

  1. Nobody sees the deprecation warning. Since Refactor Plotting functions #1631 (v0.26), the DeprecationWarning is raised inside a helper with stacklevel=2. It points into sbi/analysis/plot.py, so Python's default filters hide it, in scripts and in notebooks. It never named a removal version, and since Refactor Plotting functions #1631 it no longer lists the keys either.
  2. The old implementation silently drops newer arguments. It never receives lower, diag_kwargs, upper_kwargs, lower_kwargs, fig_kwargs, discrete_indices or the names of LabeledSamples. Advanced tutorial 19 mixes both styles in four cells, so it draws its contours at the old default of 68 % instead of the requested 95 % and 99 %, and ignores bins=100.
  3. PlotOffDiagOptions is still exported, but no style uses it. upper="plot" raises, and passing it as upper_kwargs crashes scatter and contour.

Moving tutorial 19 to the current implementation exposed a bug there, too. With fig_kwargs=dict(legend=True) and an empty lower triangle, the legend goes into the bottom-left cell, and that cell's x-label (e.g. "dim 1") is drawn under it. The cell got its label before it was turned off; _place_legend_in_empty_cell (#1830) turns it back on and hides its ticks and spines, but not its labels. Tutorial 17 shows the same stray label.

This PR:

  • raises a FutureWarning at the caller's line. It names the keys, says they will be removed in v0.29.0, and says where they go instead. If newer arguments were passed too, it names the ones that are ignored;
  • warns when pairplot_dep or marginal_plot_dep is called directly (Refactor pairplot function #1425 mentions doing that). They become thin wrappers around the unchanged bodies, now _pairplot_dep and _marginal_plot_dep. pairplot and marginal_plot call the bodies, so each call warns once;
  • warns when PlotOffDiagOptions is created. Importing it stays silent;
  • clears the axis labels of the cell that holds the legend;
  • moves tutorial 19's options into fig_kwargs, drops PlotOffDiagOptions from tutorial 17's list, and reruns both tutorials.

The old implementation itself doesn't change: calls that use it draw the same figures as before.

Evidence

What a plain script shows under Python's default warning filters:

call main this PR
pairplot(s, legend=True) nothing FutureWarning at the caller's line (text below)
pairplot(s, legend=True, diag="kde", diag_kwargs=...) nothing, and diag_kwargs is dropped the same, plus "This call uses the old implementation, which ignores ['diag_kwargs']."
pairplot(LabeledSamples(s, name="a"), legend=True) nothing, and the name is dropped from the legend the same, naming 'LabeledSamples names'
marginal_plot(s, legend=True) nothing FutureWarning
pairplot_dep(s), marginal_plot_dep(s) nothing FutureWarning
PlotOffDiagOptions() nothing FutureWarning
pairplot(s, fig_kwargs=dict(legend=True)) nothing nothing
script.py:22: FutureWarning: `pairplot` got the deprecated keyword arguments ['legend'].
They are deprecated since sbi v0.23.0 and will be removed in v0.29.0. Pass `FigOptions`
fields in `fig_kwargs` and plot styles in the `*_kwargs` arguments (see
`sbi.analysis.plotting_classes`).

python -W error::FutureWarning -c "import sbi.analysis" passes, so importing stays silent.

The legend fix changes only figures with a legend in the bottom-left cell. I rendered 9 cases: the legend in either empty triangle or on the diagonal, with and without background colours, no legend, the old implementation and marginal_plot. The 3 with a legend in the bottom-left cell change; the other 6 are pixel-identical to main.

Tutorials 17 and 19, rerun in full: tutorial 19's four cells now go through the current implementation. Its MAP figure shows the requested 95 % contour with 100 KDE bins, and its i.i.d. and guidance figures show the requested 99 % contours. The legend figures of both tutorials no longer show the stray label. Neither notebook has a seed, so the other outputs and the epoch counts change too. Outputs are stored as in the other docs notebooks: plots and printed output only (tests/strip_notebook_outputs.py), with consecutive prints merged and no execution timestamps.

Tests:

test_deprecated_plotting_warns_once_at_the_caller (8 cases): each deprecated
    entry point warns exactly once, names v0.29.0 and points at the caller   all 8 fail on main
test_pairplot_dep: now expects the FutureWarning                              fails on main
test_pairplot_legend_cell_has_no_axis_labels (2 cases): the cell that holds
    the legend has no axis labels                         the bottom-left case fails on main

tests/plot_test.py and tests/sbc_test.py::test_sbc_plotting pass (574 passed, 9 expected failures). None of the new warnings shows up in the pytest warnings summary, so sbi never triggers them itself. pyright sbi and pre-commit on the changed files pass. I did not run the full test suite locally.

Merge Danger

Door: two-way. The only signature change: pairplot_dep and marginal_plot_dep now take *args, **kwargs and forward them unchanged.

Blast Radius:

  • Code that uses the old keyword arguments, pairplot_dep, marginal_plot_dep or PlotOffDiagOptions now shows a FutureWarning. What it draws doesn't change.
  • Figures with a legend in the bottom-left cell no longer show that cell's x-label.
  • Tutorials 17 and 19 are rerun, so their figures change. Tutorial 19's now show what its code asks for.

Timing: this should ship in v0.28 so that the old path can go in v0.29. If it misses v0.28, the version numbers in the four warning texts and in the test need a bump.

For review: is v0.29 the right removal version? The old keyword arguments warned visibly in v0.23 to v0.25. pairplot_dep, marginal_plot_dep and PlotOffDiagOptions never warned before, so v0.29 gives them one release of notice. Moving any of them to v0.30 only changes the four warning texts and the test.

To remove in v0.29:

  • the **kwargs parameters and branches of pairplot and marginal_plot, and _warn_deprecated_kwargs;
  • pairplot_dep, marginal_plot_dep, their bodies _pairplot_dep and _marginal_plot_dep, and get_diag_func, which only those bodies use;
  • PlotOffDiagOptions and its export, the "plot" branches in get_offdiag_funcs and get_default_offdiag_kwargs, plt_plot_2d, and the "hist2d", "kde2d" and "contourf" aliases there. pairplot rejects all of these style names before they are reached.

_get_default_opts, _arrange_plots and update stay: conditional_pairplot and conditional_marginal_plot use them.

Related: #1084 added the old path, #1631 moved the warning into the helper, and #1830 added the legend placement. #2111 changes the sampling that tutorial 19's cells 26 and 28 show; whichever of the two merges second should rerun tutorial 19. #2154 edits sbi/utils/plotting_helpers.py, which this PR doesn't touch, and adds a test to tests/plot_test.py; the two merge without conflicts.

I used Claude Code for the analysis, the implementation, the tests and the tutorial reruns.

🤖 Generated with Claude Code

dgedon and others added 3 commits November 9, 2026 20:07
Passing old-style keyword arguments to `pairplot` or `marginal_plot` sends
the call to the pre-v0.23 implementation. Since sbi-dev#1631 the
DeprecationWarning pointed into sbi, so Python's default filters hid it. It
named no removal version, and the old implementation silently dropped the
newer arguments passed with it.

Raise a FutureWarning at the caller's line instead. It names the keys,
v0.29.0 and where the keys go, and lists the newer arguments that the call
ignores. `pairplot_dep`, `marginal_plot_dep` and `PlotOffDiagOptions` warn
too. The old implementation itself is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cells 16, 19, 26 and 28 of advanced tutorial 19 passed `legend`,
`samples_labels`, `points_labels`, `points_colors` and `points_offdiag`
directly to `pairplot`. That sent them to the old implementation, which
ignored their `diag_kwargs` and `upper_kwargs`. Pass these options in
`fig_kwargs` instead, so that the requested contour levels and KDE bins
are drawn.

Also drop the deprecated `PlotOffDiagOptions` from tutorial 17's list of
option classes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rerun advanced tutorial 19 so that its stored figures show what the cells
ask for: the 95 % contour and 100 KDE bins in the MAP figure, and the
99 % contours in the i.i.d. and guidance figures. Outputs are stored as
in the other docs notebooks: plots and printed output only, with
consecutive prints merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

Plotting functions now warn when callers use deprecated keyword arguments or entry points. PlotOffDiagOptions also emits a deprecation warning. Legend cells no longer retain axis labels.

Changes: Plotting API updates

Layer / File(s) Summary
Deprecation warnings and legacy routing
sbi/analysis/plot.py, sbi/analysis/plotting_classes.py, tests/plot_test.py
marginal_plot and pairplot report deprecated keyword arguments and ignored modern options before forwarding to private implementations. Deprecated entry points and PlotOffDiagOptions emit FutureWarnings. Documentation and tests cover the deprecation details.
Legend cell axis labels
sbi/analysis/plot.py, tests/plot_test.py
Legend placement clears the x- and y-axis labels of the selected cell. Tests check upper- and lower-triangle legend cells.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: abelaba, janfb

Pre-merge checks: Passed 5

Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
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 names the deprecated pairplot keyword warnings and the stray legend-cell label fix, which are central changes in the PR.
Description check Passed The description explains the changes, motivation, compatibility impact, tests, related issues, and open review question. It does not use the template’s exact section headings or include the checklist,…
Full details: Docstring Coverage

Explanation

Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 8 functions across 3 files.

Full details: Description check

Explanation

The description explains the changes, motivation, compatibility impact, tests, related issues, and open review question. It does not use the template’s exact section headings or include the checklist, but it provides enough substantive information to review the PR.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Review coverage is incomplete: 2 files could not be fully reviewed. Findings from completed review steps are included; see review info for details.

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b159c458-b3f7-4fd5-b4de-7c10eb30de17
Commits

Reviewing files that changed from the base of the PR and between 19b2836 and 1cb3ef6.

Files selected for processing: 4

  • docs/advanced_tutorials/17_plotting_functionality.ipynb
  • docs/advanced_tutorials/19_vector_field_methods.ipynb
  • sbi/analysis/plot.py
  • tests/plot_test.py
Files not fully reviewed because their changes were unavailable: 2

  • docs/advanced_tutorials/17_plotting_functionality.ipynb
  • docs/advanced_tutorials/19_vector_field_methods.ipynb

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.80%. Comparing base (cd8f131) to head (1cb3ef6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2160      +/-   ##
==========================================
+ Coverage   90.69%   90.80%   +0.11%     
==========================================
  Files         142      142              
  Lines       14855    14868      +13     
==========================================
+ Hits        13472    13501      +29     
+ Misses       1383     1367      -16     
Flag Coverage Δ
fast 86.99% <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 82.62% <100.00%> (+1.64%) ⬆️
sbi/analysis/plotting_classes.py 98.80% <100.00%> (+1.82%) ⬆️

dgedon and others added 2 commits November 10, 2026 10:51
With `fig_kwargs=dict(legend=True)` and an empty lower triangle, pairplot
puts the legend into the bottom-left cell. That cell got its x-label (e.g.
"dim 1") before it was turned off, and `_place_legend_in_empty_cell` (sbi-dev#1830)
turned it back on, hiding only its ticks and spines. Clear the labels too.

Only figures with a legend in the bottom-left cell change. The old
implementation never labels that cell, so it draws the same as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Their legend figures no longer show the stray x-label under the legend.
Outputs are stored as in the other docs notebooks: plots and printed
output only, consecutive prints merged, and no execution timestamps. This
also drops the timestamps that the previous rerun of tutorial 19 stored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dgedon dgedon changed the title fix: warn visibly about deprecated pairplot keyword arguments, removed in v0.29 fix: warn visibly about deprecated pairplot kwargs, drop a stray label under the legend Nov 10, 2026
@dgedon
dgedon requested a review from janfb November 10, 2026 10:27

This branch has not been deployed

No deployments
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