Skip to content

test: comprehensive tests for combine_plots (fixes #236)#438

Open
jinukuntlaakhilakumargoud-web wants to merge 2 commits intoarviz-devs:mainfrom
jinukuntlaakhilakumargoud-web:fix/combine-plots-tests-issue-236
Open

test: comprehensive tests for combine_plots (fixes #236)#438
jinukuntlaakhilakumargoud-web wants to merge 2 commits intoarviz-devs:mainfrom
jinukuntlaakhilakumargoud-web:fix/combine-plots-tests-issue-236

Conversation

@jinukuntlaakhilakumargoud-web
Copy link
Copy Markdown

@jinukuntlaakhilakumargoud-web jinukuntlaakhilakumargoud-web commented Feb 27, 2026

Summary

Added comprehensive test suite for combine_plots which previously had zero tests. This addresses issue #236 ("User test and improve combine_plots").

Tests added (9 total)

Test What it validates
test_combine_basic_column Default expand="column" layout
test_combine_basic_row expand="row" layout
test_combine_custom_plot_names Custom names appear as coords
test_combine_sample_dims_forwarded sample_dims reaches child plots
test_combine_invalid_expand ValueError on bad expand value
test_combine_multiple_plots Three plots in one figure
test_combine_with_kwargs Child plot kwargs forwarded
test_combine_ppc_plots PPC plots with group="posterior_predictive"
test_combine_with_forest_xfail Documents plot_forest incompatibility

Key findings

  1. sample_dims forwarding - Already fixed in the current codebase (line 156 of combine.py)
    1. no_artist_kwargs incompatibility - combine_plots internally calls child plots with backend="none", so the no_artist_kwargs test fixture cannot be used
    1. Grid-based plot incompatibility (bug) - plot_forest, plot_ridge, plot_ess, and plot_trace fail when used with combine_plots because their internal grid dimensions conflict with combine_plots's column/row expand dimension, causing backend_from_object() to receive an xarray object instead of a plotting target

Bug details

The render() function in combine.py calls backend_from_object(target) which inspects target.__module__ to determine the backend. When grid-based plots (forest, ridge, ess, trace) are combined, the PlotCollection.map() call may resolve target to an xarray DataArray instead of a matplotlib Axes, causing a ValueError.

This is documented via an xfail test (test_combine_with_forest_xfail).

@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented Feb 27, 2026

Documentation build overview

📚 arviz-plots | 🛠️ Build #31590746 | 📁 Comparing 23bf57d against latest (0c9bb34)


🔍 Preview build

Show files changed (65 files in total): 📝 65 modified | ➕ 0 added | ➖ 0 deleted
File Status
gallery/add_reference_bands.html 📝 modified
gallery/add_reference_lines.html 📝 modified
gallery/combine_plots.html 📝 modified
gallery/plot_autocorr.html 📝 modified
gallery/plot_bf.html 📝 modified
gallery/plot_compare.html 📝 modified
gallery/plot_convergence_dist.html 📝 modified
gallery/plot_dgof.html 📝 modified
gallery/plot_dgof_dist.html 📝 modified
gallery/plot_dist_ecdf.html 📝 modified
gallery/plot_dist_hist.html 📝 modified
gallery/plot_dist_kde.html 📝 modified
gallery/plot_dist_models.html 📝 modified
gallery/plot_dist_qds.html 📝 modified
gallery/plot_ecdf_coverage.html 📝 modified
gallery/plot_ecdf_pit.html 📝 modified
gallery/plot_energy.html 📝 modified
gallery/plot_ess_evolution.html 📝 modified
gallery/plot_ess_local.html 📝 modified
gallery/plot_ess_models.html 📝 modified
gallery/plot_ess_quantile.html 📝 modified
gallery/plot_forest.html 📝 modified
gallery/plot_forest_ess.html 📝 modified
gallery/plot_forest_models.html 📝 modified
gallery/plot_forest_pp_obs.html 📝 modified
gallery/plot_forest_shade.html 📝 modified
gallery/plot_khat.html 📝 modified
gallery/plot_khat_aesthetics.html 📝 modified
gallery/plot_khat_facet_cols.html 📝 modified
gallery/plot_khat_facet_grid.html 📝 modified
gallery/plot_lm.html 📝 modified
gallery/plot_loo_pit.html 📝 modified
gallery/plot_mcse.html 📝 modified
gallery/plot_pair.html 📝 modified
gallery/plot_pair_distribution.html 📝 modified
gallery/plot_pair_focus.html 📝 modified
gallery/plot_pair_focus_distribution.html 📝 modified
gallery/plot_parallel.html 📝 modified
gallery/plot_pava_calibration.html 📝 modified
gallery/plot_ppc_censored.html 📝 modified
gallery/plot_ppc_coverage.html 📝 modified
gallery/plot_ppc_dist.html 📝 modified
gallery/plot_ppc_interval.html 📝 modified
gallery/plot_ppc_pava_residuals.html 📝 modified
gallery/plot_ppc_pit.html 📝 modified
gallery/plot_ppc_rootogram.html 📝 modified
gallery/plot_ppc_tstat.html 📝 modified
gallery/plot_prior_posterior.html 📝 modified
gallery/plot_psense.html 📝 modified
gallery/plot_psense_quantities.html 📝 modified
gallery/plot_rank.html 📝 modified
gallery/plot_rank_dist.html 📝 modified
gallery/plot_ridge.html 📝 modified
gallery/plot_ridge_multiple.html 📝 modified
gallery/plot_trace.html 📝 modified
gallery/plot_trace_dist.html 📝 modified
_modules/arviz_plots/plot_collection.html 📝 modified
_modules/arviz_plots/visuals.html 📝 modified
api/generated/arviz_plots.PlotCollection.generate_aes_dt.html 📝 modified
api/generated/arviz_plots.plot_dist.html 📝 modified
api/generated/arviz_plots.plot_ppc_dist.html 📝 modified
api/generated/arviz_plots.visuals.point_estimate_text.html 📝 modified
_modules/arviz_plots/plots/dist_plot.html 📝 modified
_modules/arviz_plots/plots/ppc_dist_plot.html 📝 modified
_modules/arviz_plots/plots/utils.html 📝 modified

@OriolAbril
Copy link
Copy Markdown
Member

OriolAbril commented Feb 27, 2026

Thanks for the PR, we are a bit swamped right now so expect reviews to take at least several days. Also note that unit tests and hypothesis tests are generally welcome even if there is no specific issue (I'd have to review what issues we have open around that) but neither of these two things will close #236

@jinukuntlaakhilakumargoud-web
Copy link
Copy Markdown
Author

Thanks for the PR, we are a bit swamped right now so expect reviews to take at least several days. Also note that unit tests and hypothesis tests are generally welcome even if there is no specific issue (I'd have to review what issues we have open around that) but neither of these two things will close #236

Thank you for the feedback and for taking the time to respond! I understand the team is busy and I'm happy to wait for the review.

Could you please guide me on what would be needed to close #236? I'd love to work on it and contribute meaningfully to the project. I'll also go through the issue in detail in the meantime.

Thanks again for the warm response!

- Remove 'none' backend (combine_plots calls render() which needs a real backend)
- Remove no_artist_kwargs fixture (internal backend='none' calls need kwargs)
- Replace plot_trace combos with plot_dist variants (plot_trace has internal
  grid dimensions that conflict with combine_plots)
- Add xfail test documenting plot_forest incompatibility bug
- Add tests for: column/row expand, custom names, sample_dims forwarding,
  invalid expand error, multiple plots, kwargs, PPC plots

Ref: arviz-devs#236
@jinukuntlaakhilakumargoud-web jinukuntlaakhilakumargoud-web changed the title test: add tests for combine_plots (closes #236) test: comprehensive tests for combine_plots (fixes #236) Feb 27, 2026
Copy link
Copy Markdown
Member

@OriolAbril OriolAbril left a comment

Choose a reason for hiding this comment

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

I would include these tests in test_plots, within the TestPlots class with the exception of the test for the exclude error which should go elsewhere.

I am not completely sure where though, the main two options that come to mind are as a function in test_plots like the test_plot_dist_kind_auto function or in a new test_plot_errors file. Any opinions on that @aloctavodia ?

class TestCombinePlots:
"""Test suite for combine_plots (issue #236)."""

def test_combine_basic_column(self, datatree, backend):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this can be combined with the test for row below using a function specific pytest.mark.parametrize

assert isinstance(pc, PlotCollection)
assert "figure" in pc.viz.data_vars

def test_combine_invalid_expand(self, datatree, backend):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we don't have many (or any) tests explicitly checking for errors but it would be nice. The main comment on this is we always make sure errors are raised as soon as possible, which in the vast majority of cases means before much of the processing and before any plotting happens. Therefore there is no point in parametrizing this test with backend. It should use "none" if possible, otherwise "matplotlib" explicitly and be outside the TestPlots class.

Comment on lines +99 to +125
def test_combine_multiple_plots(self, datatree, backend):
"""Three plots can be combined in a single figure."""
pc = combine_plots(
datatree,
plots=[
(plot_dist, {}),
(plot_dist, {"kind": "ecdf"}),
(plot_dist, {"kind": "hist"}),
],
backend=backend,
)
assert isinstance(pc, PlotCollection)
assert "figure" in pc.viz.data_vars
assert pc.viz["plot"].sizes["column"] == 3

def test_combine_with_kwargs(self, datatree, backend):
"""Extra kwargs are forwarded to individual plot functions."""
pc = combine_plots(
datatree,
plots=[
(plot_dist, {"kind": "ecdf"}),
(plot_dist, {"kind": "hist"}),
],
backend=backend,
)
assert isinstance(pc, PlotCollection)
assert "figure" in pc.viz.data_vars
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

these two are redundant with the basic tests

),
strict=False,
)
def test_combine_with_forest_xfail(self, datatree, backend):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think it is worth adding xfail tests unless we have a very clear reason too. In this case it is very clear functions like plot_forest, plot_energy, plot_trace_dist won't work with combine_plots at a conceptual level.

Comment on lines +4 to +7
``combine_plots`` internally renders child plots with ``backend='none'`` before
mapping them onto a real grid, so the outer backend must be a real plotting
backend (matplotlib, bokeh, plotly) and the ``no_artist_kwargs`` fixture must be
omitted.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we actually want either of these two things. It is pointless but we can "rerender" the plot with the none backend again and it should work. And if we are triggering the no_artist_kwargs check through the combine_plots testing that is definitely something to double check.

@OriolAbril
Copy link
Copy Markdown
Member

Could you please guide me on what would be needed to close #236?

The issue is about user testing. We need people to, from the role of ArviZ users, play around with combine_plots in order to find limitations in the design and interesting edge cases to add unit tests for. We should have unit tests form combine_plots too like the ones you are adding, but those can't find design flaws with the function nor highlight interesting combination patterns that are not supported by the function but we then see they should be.

I will update the issue description to be clearer, this is one of the reasons the "good first issue" label can be misleading. This is an extremely easy issue for an ArviZ user as it doesn't require opening a PR or learning about the contributing workflow, but extremely difficult for someone who is not an ArviZ user (even if they are a pro at contributing, PRs, CI...) because it requires first becoming an ArviZ user, then working on the issue.

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