Skip to content

Scalar Resolution with Regression Test#8103

Open
AdishreeB wants to merge 4 commits intopymc-devs:mainfrom
AdishreeB:scalar_fix_clean
Open

Scalar Resolution with Regression Test#8103
AdishreeB wants to merge 4 commits intopymc-devs:mainfrom
AdishreeB:scalar_fix_clean

Conversation

@AdishreeB
Copy link
Contributor

Description

This PR fixes an IndexError that occurs when using model.debug() on scalar variables.

The issue was that the debug function attempted to index scalar variables using values[mask], which fails because scalars are 0-dimensional and cannot be indexed.

The fix adds a dimension check (values.ndim == 0) before indexing:

  • For scalar variables: handles the mask as a single boolean value
  • For array variables: uses the original indexing logic

This ensures the debug function works correctly for both scalar and array random variables.

A regression test is included to prevent this bug from reappearing.

Related Issue

Checklist

  • Checked that the pre-commit linting/style checks pass
  • Included tests that prove the fix is effective or that the new feature works
  • Added necessary documentation (docstrings and/or example notebooks)
  • If you are a pro: each commit corresponds to a relevant logical change

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

@github-actions github-actions bot added the bug label Feb 10, 2026
@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.92%. Comparing base (a375fd1) to head (429d157).
⚠️ Report is 38 commits behind head on main.

Files with missing lines Patch % Lines
pymc/model/core.py 0.00% 5 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8103      +/-   ##
==========================================
- Coverage   88.76%   86.92%   -1.84%     
==========================================
  Files         116      123       +7     
  Lines       18971    19525     +554     
==========================================
+ Hits        16840    16973     +133     
- Misses       2131     2552     +421     
Files with missing lines Coverage Δ
pymc/model/core.py 75.03% <0.00%> (-18.28%) ⬇️

... and 61 files with indirect coverage changes

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

pm.Normal("x", 0, 1)

try:
model.debug(fn="dlogp")
Copy link
Member

@ricardoV94 ricardoV94 Feb 11, 2026

Choose a reason for hiding this comment

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

test the output directly, instead of just testing it doesn't raise. You can use capsys to capture it.

Also would be nice to test a case that has an error and one that doesn't. Both presumably failed before, but we are still not testing one of them.

You just need to give a negative sigma to the Normal to get a case that fails (at least the logp, not sure about the dlgop).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debug message for scalar values fails

2 participants