Encode numeric categorical columns with a numpy ordinal encoder - #1263
Open
Innixma wants to merge 3 commits into
Open
Encode numeric categorical columns with a numpy ordinal encoder#1263Innixma wants to merge 3 commits into
Innixma wants to merge 3 commits into
Conversation
The ordinal step ran sklearn's OrdinalEncoder, which spends most of a call on input validation; on a small table that dwarfed the encoding itself, and the step fits once per ensemble member. Numeric arrays now go through a numpy encoder with the same output, categories and NaN and unknown-value handling. Object arrays keep sklearn's. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ELdutHiUqkvynzEP7EnPsi
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ELdutHiUqkvynzEP7EnPsi
Innixma
added this pull request to stack #1264
September 11, 2026 22:14
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9be1cba. Configure here.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ELdutHiUqkvynzEP7EnPsi
Innixma
removed this pull request from stack #1264
September 12, 2026 04:47
Innixma
added this pull request to stack #1266
September 12, 2026 04:47
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.

Stacked on #1255.
EncodeCategoricalFeaturesStep's ordinal path wrapped sklearn'sOrdinalEncoder. On a small table almost all of a call is sklearn's input validation rather than the encoding, and the step fits once per ensemble member, so on a categorical-heavy table of a few hundred rows the step was the largest single CPU cost offit. Profiled on a 598 x 31 table with 25 categorical columns and 88 ensemble preprocessing pipelines: 0.54 s of a 0.85 s fit, about 6 ms per pipeline, of which the encoder's own arithmetic is well under a millisecond.Numeric arrays now go through
NumericOrdinalEncoder, aOneToOneFeatureMixintransformer that does onenp.uniqueand onenp.searchsortedper column and validates nothing. It gives the same output asOrdinalEncoder(handle_unknown="use_encoded_value", unknown_value=np.nan): sorted distinct values become0..k-1as float64, NaN stays NaN, a value unseen at fit becomes NaN, andcategories_lists NaN last for a column that had NaN at fit so the per-column category count that theordinal_shuffledpermutation reads is unchanged. Object arrays keep sklearn's encoder. TheColumnTransformerwrapper, output names, schema carry-over and the one-hot path are untouched.On the table above the step goes from 3.97 ms to 1.20 ms per
fit_transformand from 1.59 ms to 0.27 ms pertransform; preprocessed outputs are identical. Tests compare the new encoder with sklearn's on plain, missing-value, unknown-at-transform, float32, all-NaN and constant columns, check the encoder choice by dtype, and check the whole step's output, including the shuffled variant, against the step with sklearn's encoder inside. The fourtest_sklearn_estimator_checksfailures forKDITransformerWithNaNin this environment are present on the base branch as well.🤖 Generated with Claude Code
https://claude.ai/code/session_01ELdutHiUqkvynzEP7EnPsi