Skip to content

is_chain_list: return FALSE for empty lists #517

Merged
jgabry merged 6 commits intostan-dev:masterfrom
utkarshpawade:refactor/sapply-to-vapply-type-safety
Mar 31, 2026
Merged

is_chain_list: return FALSE for empty lists #517
jgabry merged 6 commits intostan-dev:masterfrom
utkarshpawade:refactor/sapply-to-vapply-type-safety

Conversation

@utkarshpawade
Copy link
Copy Markdown
Contributor

Fixes #516

Summary

  • Replaces 9 uses of sapply() with vapply() across 5 files
  • vapply() enforces a declared return type, preventing silent list() returns on zero-length input that can cause hard to diagnose downstream failures
  • Two sapply(x, colnames) calls at helpers-mcmc.R:277,303 are intentionally unchanged, they rely on flexible return types to detect mismatched column names across chains

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.67%. Comparing base (5c1d015) to head (2ad7ef4).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #517   +/-   ##
=======================================
  Coverage   98.67%   98.67%           
=======================================
  Files          35       35           
  Lines        5903     5905    +2     
=======================================
+ Hits         5825     5827    +2     
  Misses         78       78           

☔ 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.

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.

Thanks. I don't actually think we need these replacements because most of the zero-length cases cannot possibly reach them. The one case I think is worth fixing is just erroring when is_chain_list is passed an empty list, but we can do that immediately before reaching sapply and without needing vapply (see review comment). The switch to vapply doesn't actually solve the problem in that case. So I would just make this PR into one fixing that one specific case.

@utkarshpawade utkarshpawade force-pushed the refactor/sapply-to-vapply-type-safety branch from 0bb70dd to f6cadb8 Compare March 30, 2026 20:39
@jgabry jgabry changed the title Replace sapply() with vapply() for type safety is_chain_list: return FALSE for empty lists Mar 30, 2026
@jgabry
Copy link
Copy Markdown
Member

jgabry commented Mar 30, 2026

I think I accidentally reverted your changes, so I just pushed again to restore your changes. I think it's ready now

@jgabry jgabry merged commit a86c556 into stan-dev:master Mar 31, 2026
6 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.

Replace sapply() with vapply() for type safety

3 participants