Skip to content

Fix merge_ebms crash when every feature is categorical - #701

Open
flyingdoubleG wants to merge 1 commit into
interpretml:mainfrom
flyingdoubleG:fix-merge-all-categorical
Open

flyingdoubleG wants to merge 1 commit into
interpretml:mainfrom
flyingdoubleG:fix-merge-all-categorical

Conversation

@flyingdoubleG

@flyingdoubleG flyingdoubleG commented Oct 29, 2026 •

Copy link
Copy Markdown

merge_ebms crashes when every feature in the models is categorical:

import numpy as np, pandas as pd
from interpret.glassbox import ExplainableBoostingRegressor, merge_ebms

rng = np.random.default_rng(0)
X = pd.DataFrame({"c1": rng.choice(list("abcd"), 400), "c2": rng.choice(list("xyz"), 400)})
y = (X["c1"] == "a") + rng.normal(0, 0.1, 400)
ebm1 = ExplainableBoostingRegressor().fit(X[:200], y[:200])
ebm2 = ExplainableBoostingRegressor().fit(X[200:], y[200:])
merge_ebms([ebm1, ebm2])
# AttributeError: 'ExplainableBoostingRegressor' object has no attribute 'feature_bounds_'

A fitted EBM always has feature_bounds_, with NaN rows for categorical features. merge_ebms combines the input bounds with nanmin/nanmax, but it only assigns ebm.feature_bounds_ when at least one merged bound is not NaN. With only categorical features every bound is NaN, so the attribute is never set. The _harmonize_tensor calls further down then read ebm.feature_bounds_ and raise.

The fix always assigns the merged bounds, keeping the NaN rows the same way fit does. _harmonize_tensor only reads the bounds for continuous features, so the NaN rows aren't used anywhere. Models with at least one continuous feature get exactly the same result as before.

test_merge_ebms_all_categorical merges two regressors trained on disjoint halves of an all-categorical dataset, with a categorical pair term. It checks that the merged bounds are NaN and that the merged model predicts the bag-weighted average of the two input models, (3 * ebm1 + 5 * ebm2) / 8 for 3 and 5 outer bags.

Testing (Windows, Python 3.14, running the checkout with the prebuilt libebm from the 0.7.8 wheel, since I can't build libebm here):

  • tests/glassbox/ebm/test_merge_ebms.py: 10 passed. With main's _merge_ebms.py, the new test fails with the AttributeError above.
  • tests/glassbox/ebm/test_ebm.py -m "not slow and not selenium": 244 passed, 44 skipped, 1 failed. The failure is test_quantile_regression ("Unrecognized objective type"), because the quantile objective is newer than the 0.7.8 library. It is unrelated to this change.
  • For a classifier, the merged logits equal the bag-weighted average to 7e-15.
  • ruff format --check passes on both files.

AI usage: I used Claude Code. It found this while cross-checking merge_ebms against bag-weighted averages of the input models, then wrote the fix and the test. I reviewed the change.

merge_ebms only set feature_bounds_ on the merged model when some bound was
not NaN. With only categorical features every bound is NaN, so the attribute
was never set and the later _harmonize_tensor calls raised AttributeError.
Fitted EBMs keep NaN bounds for categoricals, so do the same here.

Signed-off-by: flyingdoubleG <53119724+flyingdoubleG@users.noreply.github.com>

@rahul05ranjan rahul05ranjan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Traced the fix against the PR branch — the premise and crash chain check out:

  • A fitted EBM always sets feature_bounds_ (glassbox/_ebm.py:1759), and the documented semantics state categorical features have min/max NaN (docs at _ebm.py:3982-3984). So an all-categorical fitted model has the attribute with all-NaN rows.
  • Pre-fix, the any(not isnan(val) ...) guard skipped the assignment when every feature is categorical in every model, so the merged EBM came out without feature_bounds_ at all. The attribute is then read directly at the three _harmonize_tensor call sites in _merge_ebms.py (lines 698, 737, 750), so the merge crashes with AttributeError before producing a model — matching the issue title.
  • Post-fix, the merged model matches the fitted-model contract (np.isnan(merged.feature_bounds_).all()), and the new test also pins the bag-weighted prediction average, which is a nice invariant to lock in.

I tried to reproduce end-to-end on this machine but the current interpret-core wheel ships a 32-bit libebm.so, so the native core won't load on arm64 and the verification is static. The test itself looks faithful to the crash scenario (two categorical-only regressors with different bag counts).

One thing the diff doesn't change that might be worth a look in a follow-up: when none of the input models expose feature_bounds_ (e.g. the DP path), len(min_feature_vals) == 0 still skips the assignment, so the merged model can still lack the attribute — that's the pre-existing contract, just noting it's now the only remaining way to hit it.

@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.76%. Comparing base (4a492be) to head (d8dd415).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #701      +/-   ##
==========================================
- Coverage   67.80%   67.76%   -0.04%     
==========================================
  Files          77       77              
  Lines       11893    11892       -1     
==========================================
- Hits         8064     8059       -5     
- Misses       3829     3833       +4     
Flag Coverage Δ
bdist_linux_311_python 67.52% <100.00%> (-0.02%) ⬇️
bdist_linux_312_python ?
bdist_linux_313_python ?
bdist_linux_314_python 67.43% <100.00%> (-0.02%) ⬇️
bdist_linuxarm_311_python 67.54% <100.00%> (-0.02%) ⬇️
bdist_linuxarm_312_python ?
bdist_linuxarm_313_python ?
bdist_linuxarm_314_python 67.46% <100.00%> (-0.01%) ⬇️
bdist_mac_311_python 67.70% <100.00%> (-0.01%) ⬇️
bdist_mac_312_python ?
bdist_mac_313_python ?
bdist_mac_314_python 67.59% <100.00%> (-0.04%) ⬇️
bdist_win_311_python 67.71% <100.00%> (-0.01%) ⬇️
bdist_win_312_python ?
bdist_win_313_python ?
bdist_win_314_python 67.62% <100.00%> (-0.01%) ⬇️
sdist_linux_311_python ?
sdist_linux_312_python ?
sdist_linux_313_python ?
sdist_linux_314_python ?
sdist_linuxarm_311_python ?
sdist_linuxarm_312_python ?
sdist_linuxarm_313_python ?
sdist_linuxarm_314_python ?
sdist_mac_311_python ?
sdist_mac_312_python ?
sdist_mac_313_python ?
sdist_mac_314_python ?
sdist_win_311_python ?
sdist_win_312_python ?
sdist_win_313_python ?
sdist_win_314_python ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Development

Successfully merging this pull request may close these issues.

2 participants