From c1dbb10cd9e968158546d4ff4e06966ced4b21dc Mon Sep 17 00:00:00 2001 From: Utkarsh Date: Thu, 9 Apr 2026 00:30:52 +0530 Subject: [PATCH 1/3] fix missing drop = FALSE in nuts_params.CmdStanMCMC --- R/bayesplot-extractors.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/bayesplot-extractors.R b/R/bayesplot-extractors.R index 19c6df882..79f7966e7 100644 --- a/R/bayesplot-extractors.R +++ b/R/bayesplot-extractors.R @@ -175,7 +175,7 @@ nuts_params.list <- function(object, pars = NULL, ...) { nuts_params.CmdStanMCMC <- function(object, pars = NULL, ...) { arr <- object$sampler_diagnostics() if (!is.null(pars)) { - arr <- arr[,, pars] + arr <- arr[,, pars, drop = FALSE] } out <- reshape2::melt(arr) colnames(out)[colnames(out) == "variable"] <- "parameter" From d110c388a0ef02496ed621ddbfffa35d3659ce72 Mon Sep 17 00:00:00 2001 From: Utkarsh Date: Thu, 9 Apr 2026 00:32:00 +0530 Subject: [PATCH 2/3] update news.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index c8f7d131f..7525658eb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # bayesplot (development version) +* Fixed missing `drop = FALSE` in `nuts_params.CmdStanMCMC()`. * Replace `apply()` with `storage.mode()` for integer-to-numeric matrix conversion in `validate_predictions()`. * Fixed `is_chain_list()` to correctly reject empty lists instead of silently returning `TRUE`. * Added unit tests for `mcmc_areas_ridges_data()`, `mcmc_parcoord_data()`, and `mcmc_trace_data()`. From 037fef2833fcd5e24eca56148bf9c9b7ad3f92e5 Mon Sep 17 00:00:00 2001 From: jgabry Date: Wed, 8 Apr 2026 15:30:44 -0600 Subject: [PATCH 3/3] Add a test --- tests/testthat/test-extractors.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/testthat/test-extractors.R b/tests/testthat/test-extractors.R index 53e9862cc..355e14186 100644 --- a/tests/testthat/test-extractors.R +++ b/tests/testthat/test-extractors.R @@ -136,4 +136,12 @@ test_that("cmdstanr methods work", { ratio <- neff_ratio(fit) expect_named(head(ratio, 4), c("alpha", "beta[1]", "beta[2]", "beta[3]")) expect_true(all(ratio > 0)) + + # https://github.com/stan-dev/bayesplot/pull/535 + np_one <- nuts_params(fit, pars = "divergent__") + expect_identical(levels(np_one$Parameter), "divergent__") + expect_true(all(np_one$Parameter == "divergent__")) + expect_equal(range(np_one$Iteration), c(1, 500)) + expect_equal(range(np_one$Chain), c(1, 2)) + expect_true(all(np_one$Value == 0)) })