Skip to content

FIX Fix HGB binning on features with only missing values - #35216

Merged
lesteve merged 6 commits into
scikit-learn:mainfrom
cakedev0:fix/hgb-all-missing-feature
Nov 3, 2026
Merged

lesteve merged 6 commits into
scikit-learn:mainfrom
cakedev0:fix/hgb-all-missing-feature

Conversation

@cakedev0

@cakedev0 cakedev0 commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Reference Issues/PRs

Fixes #35164

What does this implement/fix? Explain your changes.

Fitting a HGB model on data with a feature that has no non-missing values crashes in _find_binning_thresholds:

It's a regression from 1.9.0: #29641 replaced the midpoints computation with sliding_window_view, which fails on an empty array, and #34248 later moved the failure to distinct_mask[0] = True. The same happens when all non-missing values of a feature have zero weight.

The fix treats an empty column like a constant one: no thresholds, so all values go to the missing values bin (same as 1.8).

AI usage disclosure

I used AI assistance for:

  • Code generation
  • Test generation

@cakedev0 cakedev0 added the Quick Review For PRs that are quick to review label Oct 23, 2026
@cakedev0
cakedev0 requested a review from AnneBeyer October 23, 2026 14:05

@FrancoisPgm FrancoisPgm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LTGM thanks.

I have nothing to complain about, plus I learned the existence np.searchsorted and that numpy can sort NaNs :)

@cakedev0 cakedev0 added the Waiting for Second Reviewer First reviewer is done, need a second one! label Oct 26, 2026
@lesteve lesteve added this to the 1.10 milestone Nov 3, 2026
@lesteve

lesteve commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Thanks for the PR! Can you add a non-regression test 🙏?

Since it appears to be a regression I added the milestone 1.10 so that we merge this one before the release.

Comment on lines +235 to +237
if with_missing_values:
# only zero-weighted non-missing values: no threshold for this feature
X[sw != 0, -1] = np.nan

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lesteve this is the non regression test ^^ (with this change, the test crashes on main)

@lesteve lesteve Nov 3, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right, I missed this one, I was probably expecting a new test function and/or I read to quickly 😅 ...

cakedev0 added a commit to cakedev0/my-scikit-learn-backlog that referenced this pull request Nov 3, 2026
done: Maintenance: get [sklearn#35304](scikit-learn/scikit-learn#35304) merged (replace the deprecated `np.isfortran`, fixes [sklearn#35289](scikit-learn/scikit-learn#35289))
todo: move [sklearn#35216](scikit-learn/scikit-learn#35216) from Waiting to Now: add the non-regression test lesteve asks for
add: Upstream: dpnp reports [IntelPython/dpnp#3149](IntelPython/dpnp#3149) (slow `X @ w` on C-contiguous tall matrices) and [IntelPython/dpnp#3148](IntelPython/dpnp#3148) (scalar operands synchronize the queue)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@lesteve lesteve left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I pushed a commit tweaking the tests. I am not 100% sure this is absolutely needed, but since I am not super familiar with the code, I'd rather keep three separate cases: no missing values, some missing values, some missing values where all non-zero sample weights are for missing values.

If both of @cakedev0 and @FrancoisPgm are happy with this I will merge this PR!

@FrancoisPgm

Copy link
Copy Markdown
Member

I'm ok with the tweak. From my understanding the third case introduced with "some" is not strictly necessary regarding the fix, but it could eventually detect a regression in the future that the 2 other cannot.

@cakedev0

cakedev0 commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

I like it! Not too verbose but good coverage. Thanks!

@lesteve lesteve changed the title FIX Don't crash in HGB binning on features with only missing values FIX Fix HGB binning on features with only missing values Nov 3, 2026
@lesteve
lesteve enabled auto-merge (squash) November 3, 2026 12:59
@lesteve
lesteve disabled auto-merge November 3, 2026 12:59
@lesteve
lesteve enabled auto-merge (squash) November 3, 2026 12:59
@lesteve

lesteve commented Nov 3, 2026

Copy link
Copy Markdown
Member

OK thanks for your feed-back, I enabled auto-merge.

@lesteve
lesteve merged commit b8de23f into scikit-learn:main Nov 3, 2026
39 of 40 checks passed
cakedev0 added a commit to cakedev0/my-scikit-learn-backlog that referenced this pull request Nov 3, 2026
todo: move [sklearn#35216](scikit-learn/scikit-learn#35216) from Now to Waiting, the test was already there, approved by lesteve with auto-merge
add: Trees: get [sklearn#34554](scikit-learn/scikit-learn#34554) merged (recursion PDP on categorical features; approved)
add: Threads: review [sklearn#34729](scikit-learn/scikit-learn#34729) (inference methods don't modify the estimator; ev-br on the SplineTransformer mutation)
todo: lucyleeow approved [sklearn#35215](scikit-learn/scikit-learn#35215)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cakedev0 added a commit to cakedev0/my-scikit-learn-backlog that referenced this pull request Nov 3, 2026
done: HGB: get [sklearn#35216](scikit-learn/scikit-learn#35216) merged (binning crash on all-missing features, fixes [sklearn#35164](scikit-learn/scikit-learn#35164)), merged before I removed it
done: Trees: get [sklearn#34554](scikit-learn/scikit-learn#34554) merged (recursion PDP on categorical features)
drop: Threads: answer lesteve on [sklearn#35105](scikit-learn/scikit-learn#35105) (RFC deprecate `pre_dispatch`)
drop: Maintenance: follow up on [sklearn#35209](scikit-learn/scikit-learn#35209) (newton-cg test failing on the macOS x86_64 wheels)
drop: Benchmarks: review [benchmarks#142](probabl-ai/scikit-learn-benchmarks#142) (cuML benchmark config)
drop: Threads: review [sklearn#34729](scikit-learn/scikit-learn#34729) (inference methods don't modify the estimator)
drop: Linear: [sklearn#34793](scikit-learn/scikit-learn#34793) (Ridge centering trick for cholesky), benchmarks in [benchmarks#115](probabl-ai/scikit-learn-benchmarks#115) and [benchmarks#31](probabl-ai/scikit-learn-benchmarks#31)
drop: Upstream: sklearnex reports [sklearnex#3402](uxlfoundation/scikit-learn-intelex#3402), [sklearnex#3377](uxlfoundation/scikit-learn-intelex#3377), [sklearnex#3220](uxlfoundation/scikit-learn-intelex#3220)
drop: Upstream: [data-apis/array-api#976](data-apis/array-api#976) (why `stable=True` is the default for `xp.sort`)
drop: Upstream: dpnp reports [IntelPython/dpnp#3149](IntelPython/dpnp#3149) and [IntelPython/dpnp#3148](IntelPython/dpnp#3148)
drop: Threads: [sklearn#34736](scikit-learn/scikit-learn#34736) (oversubscription in `pairwise_distances`), out of the reported findings item
drop: KMeans: benchmarks [benchmarks#154](probabl-ai/scikit-learn-benchmarks#154), [benchmarks#160](probabl-ai/scikit-learn-benchmarks#160), [OpenBLAS#6105](OpenMathLib/OpenBLAS#6105) and [sklearn#17334](scikit-learn/scikit-learn#17334), out of the [sklearn#35193](scikit-learn/scikit-learn#35193) item
todo: move [joblib#1899](joblib/joblib#1899), [sklearn#35261](scikit-learn/scikit-learn#35261) and [sklearn#35053](scikit-learn/scikit-learn#35053) from Reviews to Now, [sklearn#35181](scikit-learn/scikit-learn#35181) to the top of Waiting (by hand in 03835dd)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:ensemble Quick Review For PRs that are quick to review size/S Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: HGB threshold extraction raises IndexError on valid all-missing support

3 participants