Skip to content

Accept posterior::draws objects in PPC/PPD functions#543

Merged
jgabry merged 4 commits intostan-dev:masterfrom
ishaan-arora-1:fix/ppc-accept-draws-objects-542
Apr 15, 2026
Merged

Accept posterior::draws objects in PPC/PPD functions#543
jgabry merged 4 commits intostan-dev:masterfrom
ishaan-arora-1:fix/ppc-accept-draws-objects-542

Conversation

@ishaan-arora-1
Copy link
Copy Markdown
Contributor

Closes #542

Summary

  • validate_predictions() now checks for posterior::draws objects and coerces them to a plain matrix before the existing validation logic runs
  • This mirrors what prepare_mcmc_array() already does on the MCMC side, so PPC/PPD functions now accept the same input formats as MCMC functions
  • All existing ppc_* and ppd_* functions benefit since they all go through validate_predictions()

Changes

  • R/helpers-ppc.R: added a posterior::is_draws() check at the top of validate_predictions(), coercing via as_draws_matrix() + unclass()
  • tests/testthat/test-helpers-ppc.R: added tests for draws_matrix, draws_array, draws_df, and draws_rvars inputs, plus end-to-end tests with ppc_dens_overlay, ppc_hist, and ppc_stat

Test plan

  • All existing PPC tests pass (510 pass, 0 fail)
  • New tests cover all four draws formats
  • End-to-end tests confirm plots are produced from draws input

validate_predictions() now coerces posterior::draws objects (draws_matrix,
draws_array, draws_df, draws_rvars) to a plain matrix before validation,
matching the pattern already used by prepare_mcmc_array() on the MCMC side.

This lets users pass draws objects directly to ppc_* and ppd_* functions
without manually calling as.matrix() first.
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.15%. Comparing base (44c3e5c) to head (c3fc6f2).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #543   +/-   ##
=======================================
  Coverage   99.15%   99.15%           
=======================================
  Files          35       35           
  Lines        5920     5923    +3     
=======================================
+ Hits         5870     5873    +3     
  Misses         50       50           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jgabry
Copy link
Copy Markdown
Member

jgabry commented Apr 15, 2026

Thanks! Yes we should allow posterior::draws objects. I'll try to review this later, I'm a bit short on time right this moment.

Copy link
Copy Markdown
Member

@jgabry jgabry left a comment

Choose a reason for hiding this comment

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

I ended up having a moment to look at this now. Thanks for this. Just one change to make: I think the documentation for the yrep argument should be updated in man-roxygen/args-y-yrep.R.

I made some updates to the tests to make them more directly test what we care about. Otherwise this looks good aside from updating the doc.

Copy link
Copy Markdown
Member

@jgabry jgabry left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@jgabry jgabry merged commit d1e452e into stan-dev:master Apr 15, 2026
8 of 11 checks passed
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.

PPC/PPD functions don't accept posterior::draws objects as yrep/ypred

3 participants