MNT Remove dead negative-value-as-missing convention for categorical features in HGB - #34663
Open
cakedev0 wants to merge 2 commits into
Open
Conversation
…features in HGB The internal `_BinMapper`/`TreePredictor` classes used to treat negative values of numeric-encoded categorical features as missing, following a LightGBM convention. Since 1.4, categorical preprocessing in the public estimators always goes through an internal OrdinalEncoder that remaps categories to dense non-negative codes, so this branch has been unreachable dead code for a while. This removes it and updates the tests that pinned it, replacing them with tests documenting the current, intentional behavior (only categories unseen at fit time -- regardless of sign -- are treated as missing).
cakedev0
commented
Aug 6, 2026
| assert_array_equal(bin_mapper.transform(X), expected_trans) | ||
|
|
||
|
|
||
| def test_categorical_feature_negative_missing(): |
Contributor
Author
There was a problem hiding this comment.
This can't happen so it's not worth testing. IMO, having this test is just confusing.
adam2392
reviewed
Sep 3, 2026
adam2392
left a comment
Member
There was a problem hiding this comment.
Does this need a documentation update on the behavior change? Lmk if this was already addressed in previous PR.
Otherwise LGTM.
Contributor
Author
|
The doc update was addressed in #34553 |
Member
|
Oh missed that. Then LGTM. Thanks! |
adam2392
approved these changes
Sep 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
Not tied to an open issue.
Follows up on:
There are other clean-ups to do because of this behavior change.
Note: I'm not trying to revert the behavioral change, and I don't to. I think it's a better behavior this way, even though it's different from LightGBM.
What does this implement/fix? Explain your changes.
This PR:
is_categorical and data[i] < 0branch in_binning.pyxand the analogousdata_val < 0branch in_predictor.pyx.is_categoricalparameter from_map_to_bins/_map_col_to_bins(and updates its one call site).Any other comments?
AI usage disclosure
I used AI assistance for: