Skip to content

[python-package] feature_names_in_ spaces replaced by underlines incompatible with sklearn#7337

Open
ThibaultDECO wants to merge 19 commits into
lightgbm-org:mainfrom
ThibaultDECO:patch-1
Open

[python-package] feature_names_in_ spaces replaced by underlines incompatible with sklearn#7337
ThibaultDECO wants to merge 19 commits into
lightgbm-org:mainfrom
ThibaultDECO:patch-1

Conversation

@ThibaultDECO

@ThibaultDECO ThibaultDECO commented Jun 19, 2026

Copy link
Copy Markdown

Fixes issue #7338

FIX feature_names_in_ whitespace replaced by underlines is incompatible with sklearn

…le with sklearn

FIX feature_names_in_ whitespace replaced by underlines is incompatible with sklearn
@jameslamb jameslamb marked this pull request as draft June 19, 2026 19:56
@ThibaultDECO ThibaultDECO changed the title FIX feature_names_in_ whitespace replaced by underlines is incompatib… [python-package] [FIX] feature_names_in_ whitespace replaced by underlines is incompatib… Jun 19, 2026
@ThibaultDECO ThibaultDECO changed the title [python-package] [FIX] feature_names_in_ whitespace replaced by underlines is incompatib… [python-package] [FIX] feature_names_in_ spaces replaced by underlines incompatible with sklearn Jun 19, 2026
@jameslamb jameslamb changed the title [python-package] [FIX] feature_names_in_ spaces replaced by underlines incompatible with sklearn [python-package] feature_names_in_ spaces replaced by underlines incompatible with sklearn Jun 20, 2026
@jameslamb jameslamb added the fix label Jun 20, 2026

@jameslamb jameslamb 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.

Thanks for your interest in LightGBM and for taking the time to open a PR.

I've started CI for you without reviewing the changes closely yet, let's see what that says.

At a glance, I'll say I'm not very excited about having to track the original feature names everywhere. This is new complexity and that means new opportunity for bugs and maintenance burden 😫

I will review more closely once we've release v4.7.0 (#7129), that is my primary focus right now.

@jameslamb

Copy link
Copy Markdown
Member

Because you're a first-time contributor, every CI run requires one of us to click a button. You may find it faster to run the tests locally.

cmake -B build -S .
cmake --build build --target _lightgbm -4
sh build-python.sh install --precompile
pytest tests/python_package_test/

@ThibaultDECO

Copy link
Copy Markdown
Author

@jameslamb Thank you James, I will run the tests locally.
With regards to your pushback, I understand that it adds complexity but I don't see any other way around at this time.
Thank you for your review!

@jameslamb

jameslamb commented Jun 21, 2026

Copy link
Copy Markdown
Member

I don't see any other way around at this time.

Other options might be:

  • raise an informative error closer to the boundary of the scikit-learn interface if any feature names have spaces (i.e. simply don't allow them)
  • remove the normalization of feature names completely in Dataset construction (i.e. allow spaces)
  • make the feature name normalization configurable via a new parameter, and have scikit-learn interface explicitly opt out of that when it constructs a Dataset
  • stop supporting feature_names_in_ in the scikit-learn interface entirely (maybe it is just not worth it, we keep tripping over it here)

I think evaluating this will require coming up with a specific answer for the question "why does LightGBM remove spaces from feature names at all?", which will require looking through some project history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants