Skip to content

Add classes to all loo warnings - #417

Open
florence-bockting wants to merge 5 commits into
masterfrom
add-loo-warning-classes
Open

florence-bockting wants to merge 5 commits into
masterfrom
add-loo-warning-classes

Conversation

@florence-bockting

Copy link
Copy Markdown
Contributor

Description

This PR adds a class to each loo warning, following up on our corresponding work in the posteriorpackage: stan-dev/posterior#470.

  • Every warning has the class loo_warning and a class for its cause.
  • Diagnostic warnings have the class loo_warning_diagnostic.
  • The warning text is unchanged and, similar to posterior, a list of warning classes and messages is provided in R/loo-package.R
  • Adds rlang to Imports.
  • Deletes the unused throw_psis_r_eff_warning() and throw_loo_r_eff_warning() (this was dead code)

This PR is related to Issue #353 (but does not fully solve it).
The PR was assisted by an LLM.

@codecov-commenter

codecov-commenter commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.27273% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.92%. Comparing base (7ecc6bc) to head (c74db6b).

Files with missing lines Patch % Lines
R/loo_compare.psis_loo_ss_list.R 35.71% 9 Missing ⚠️
R/loo_subsample.R 0.00% 7 Missing ⚠️
R/psis_approximate_posterior.R 50.00% 2 Missing ⚠️
R/psislw.R 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #417      +/-   ##
==========================================
+ Coverage   92.65%   92.92%   +0.26%     
==========================================
  Files          31       31              
  Lines        3242     3251       +9     
==========================================
+ Hits         3004     3021      +17     
+ Misses        238      230       -8     

☔ View full report in Codecov by Harness.
📢 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.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if c74db6b is merged into master:

Status Name Current Incoming Interval
✔️ loo_matrix 1.4s 1.4s [-0.34%, +0.17%]
✔️ loo_function 1.28s 1.28s [-0.53%, +0.17%]

Further explanation regarding interpretation and methodology can be found in the documentation.

@florence-bockting
florence-bockting marked this pull request as ready for review November 3, 2026 06:15

@jgabry jgabry left a comment

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.

Looks good. I made a few suggestions, but pretty small.

Comment thread R/psis.R Resolved
Comment thread R/psis.R Resolved
Comment thread R/loo-package.R Resolved
Comment thread NEWS.md Resolved
Comment thread R/loo-package.R Resolved
Comment thread tests/testthat/test_warning_classes.R Resolved
Comment thread R/loo_subsample.R Resolved

@jgabry jgabry left a comment

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.

Looks good, this is basically ready. I made a few code formatting (indentation) comments and suggested an edit to the NEWS entry.

if (ref_loo[[1]]$loo_subsampling$estimator == "hh_pps" | compare_loo[[1]]$loo_subsampling$estimator == "hh_pps"){
warning("Hansen-Hurwitz estimator used. Naive diff SE is used.", call. = FALSE)
.warn_diagnostic("Hansen-Hurwitz estimator used. Naive diff SE is used.",
class = "loo_warning_subsample_naive_se")

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.

missing indentation on L55

Comment thread R/loo_subsample.R
} else {
warning("Negative estimate of SE, more subsampling obs. needed.", call. = FALSE)
.warn_diagnostic("Negative estimate of SE, more subsampling obs. needed.",
class = "loo_warning_subsample_negative_se")

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.

missing indentation on L1085

Comment thread R/loo_subsample.R
warning("Negative estimate of SE, more subsampling obs. needed.", call. = FALSE)
x$estimates["elpd_loo", "SE"] <- NaN
.warn_diagnostic("Negative estimate of SE, more subsampling obs. needed.",
class = "loo_warning_subsample_negative_se")

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.

missing indentation on L1096

Comment thread R/psislw.R
...) {
.Deprecated("psis")
.warn("'psislw' is deprecated.\nUse 'psis' instead.\nSee help(\"Deprecated\")",
class = c("loo_warning_deprecated", "deprecatedWarning"))

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.

weird indentation on L42

if (!is.null(log_q)) {
.Deprecated(msg = "psis_approximate_posterior() argument log_q has been changed to log_g")
.warn("psis_approximate_posterior() argument log_q has been changed to log_g",
class = c("loo_warning_deprecated", "deprecatedWarning"))

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.

weird indentation on L28

Comment thread NEWS.md
Comment on lines +14 to +16
* All warnings now have the class `loo_warning` and a class for each cause;
diagnostics warnings have the class `loo_warning_diagnostic`. The base warning
class is now `rlang_warning` by @florence-bockting in #417

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.

Suggested change
* All warnings now have the class `loo_warning` and a class for each cause;
diagnostics warnings have the class `loo_warning_diagnostic`. The base warning
class is now `rlang_warning` by @florence-bockting in #417
* All warnings now have the class `loo_warning` and a class for each cause,
and diagnostic warnings also have the class `loo_warning_diagnostic`. The base
warning class is now `rlang_warning` instead of `simpleWarning`. By
@florence-bockting in #417
* Fix `loo_subsample()` with the Hansen-Hurwitz estimator setting the
`elpd_loo` SE to `NaN` instead of the `p_loo` SE when the `p_loo` variance
estimate is negative by @florence-bockting in #417

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.

3 participants