Skip to content

Fix df_with_chain2array() silently recycling data with unequal chain lengths#499

Merged
jgabry merged 3 commits intostan-dev:masterfrom
utkarshpawade:fix/df-with-chain2array-unequal-iterations
Mar 20, 2026
Merged

Fix df_with_chain2array() silently recycling data with unequal chain lengths#499
jgabry merged 3 commits intostan-dev:masterfrom
utkarshpawade:fix/df-with-chain2array-unequal-iterations

Conversation

@utkarshpawade
Copy link
Contributor

Fixes #498

Summary

  • Validate that all chains have the same number of iterations before constructing the 3-D array
  • Replace ceiling(nrow(a) / n_chain) with the validated per-chain count
  • Add regression test with unequal chain lengths

@codecov-commenter
Copy link

codecov-commenter commented Mar 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.70%. Comparing base (d15d028) to head (d1b7c77).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #499   +/-   ##
=======================================
  Coverage   98.70%   98.70%           
=======================================
  Files          35       35           
  Lines        5857     5864    +7     
=======================================
+ Hits         5781     5788    +7     
  Misses         76       76           

☔ 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
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 think this is good but the check and error should happen in validate_df_with_chain instead of df_with_chain2array. That's more consistent with how we handle checks for other input types.

Copy link
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, looks good! I just added a couple more things to make this a little more robust. If all tests pass we can merge.

@jgabry jgabry merged commit 042663b into stan-dev:master Mar 20, 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.

df_with_chain2array() silently corrupts data when chains have unequal iterations

3 participants