Repository navigation
Conversation
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>
Walkthrough
Pre-merge checks:
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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>
Summary
Passing old-style keyword arguments such as
legend=Trueorsamples_labels=[...]topairplotormarginal_plotsends the whole call to the pre-v0.23 implementation (pairplot_dep,marginal_plot_dep). That path has three problems:DeprecationWarningis raised inside a helper withstacklevel=2. It points intosbi/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.lower,diag_kwargs,upper_kwargs,lower_kwargs,fig_kwargs,discrete_indicesor the names ofLabeledSamples. 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 ignoresbins=100.PlotOffDiagOptionsis still exported, but no style uses it.upper="plot"raises, and passing it asupper_kwargscrashesscatterandcontour.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:
FutureWarningat 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;pairplot_depormarginal_plot_depis called directly (Refactor pairplot function #1425 mentions doing that). They become thin wrappers around the unchanged bodies, now_pairplot_depand_marginal_plot_dep.pairplotandmarginal_plotcall the bodies, so each call warns once;PlotOffDiagOptionsis created. Importing it stays silent;fig_kwargs, dropsPlotOffDiagOptionsfrom 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:
mainpairplot(s, legend=True)FutureWarningat the caller's line (text below)pairplot(s, legend=True, diag="kde", diag_kwargs=...)diag_kwargsis droppedpairplot(LabeledSamples(s, name="a"), legend=True)'LabeledSamples names'marginal_plot(s, legend=True)FutureWarningpairplot_dep(s),marginal_plot_dep(s)FutureWarningPlotOffDiagOptions()FutureWarningpairplot(s, fig_kwargs=dict(legend=True))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 tomain.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:
tests/plot_test.pyandtests/sbc_test.py::test_sbc_plottingpass (574 passed, 9 expected failures). None of the new warnings shows up in the pytest warnings summary, so sbi never triggers them itself.pyright sbiandpre-commiton the changed files pass. I did not run the full test suite locally.Merge Danger
Door: two-way. The only signature change:
pairplot_depandmarginal_plot_depnow take*args, **kwargsand forward them unchanged.Blast Radius:
pairplot_dep,marginal_plot_deporPlotOffDiagOptionsnow shows aFutureWarning. What it draws doesn't change.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_depandPlotOffDiagOptionsnever 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:
**kwargsparameters and branches ofpairplotandmarginal_plot, and_warn_deprecated_kwargs;pairplot_dep,marginal_plot_dep, their bodies_pairplot_depand_marginal_plot_dep, andget_diag_func, which only those bodies use;PlotOffDiagOptionsand its export, the"plot"branches inget_offdiag_funcsandget_default_offdiag_kwargs,plt_plot_2d, and the"hist2d","kde2d"and"contourf"aliases there.pairplotrejects all of these style names before they are reached._get_default_opts,_arrange_plotsandupdatestay:conditional_pairplotandconditional_marginal_plotuse 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 totests/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