Skip to content

Fix IndexError in mean-only Python BART with categorical covariates#411

Merged
andrewherren merged 2 commits into
mainfrom
fix-bart-categorical-mean-only-weights
Jun 17, 2026
Merged

Fix IndexError in mean-only Python BART with categorical covariates#411
andrewherren merged 2 commits into
mainfrom
fix-bart-categorical-mean-only-weights

Conversation

@andrewherren

Copy link
Copy Markdown
Collaborator

The "zero out excluded variable weights" step in BARTModel.sample ran outside the include_forest guards, while the weight arrays are only expanded to processed (post-preprocessing, e.g. one-hot) length inside those guards. A mean-only model with categorical covariates therefore indexed an unexpanded variable_weights_variance array with a processed-length boolean mask and raised IndexError. Guard each zero-out with its include_forest flag, matching the R implementation in R/bart.R.

Adds a regression test (mean-only BART on a categorical DataFrame) and a NEWS entry.

andrewherren and others added 2 commits June 16, 2026 22:05
The "zero out excluded variable weights" step in BARTModel.sample ran
outside the include_*_forest guards, while the weight arrays are only
expanded to processed (post-preprocessing, e.g. one-hot) length inside
those guards. A mean-only model with categorical covariates therefore
indexed an unexpanded variable_weights_variance array with a
processed-length boolean mask and raised IndexError. Guard each zero-out
with its include_*_forest flag, matching the R implementation in
R/bart.R.

Adds a regression test (mean-only BART on a categorical DataFrame) and a
NEWS entry.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@andrewherren andrewherren merged commit 7c75236 into main Jun 17, 2026
16 checks passed
@andrewherren andrewherren deleted the fix-bart-categorical-mean-only-weights branch June 17, 2026 05:16
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.

1 participant