Skip to content

[python-package] Booster.refit() raises a misleading warning when using categorical features #6793

@jameslamb

Description

@jameslamb

Description

Seeing this warning in Python unit tests:

tests/python_package_test/test_engine.py::test_linear_trees
/Users/runner/miniforge/envs/test-env/lib/python3.12/site-packages/lightgbm/basic.py:2137: UserWarning: categorical_feature keyword has been found in params and will be ignored.
Please use categorical_feature argument of the Dataset constructor to pass this parameter.
_log_warning(

That test case is not directly passing categorical_feature through params... that might be happening internal to lightgbm, and therefore something that users cannot avoid.

Reproducible example

I haven't not narrowed it down further yet, but can reliably reproduce it via running the tests.

pytest 'tests/python_package_test/test_engine.py::test_linear_trees'

Environment info

LightGBM version or commit hash: 226e7f7

Command(s) you used to install LightGBM

cmake -B build -S . -DUSE_OPENMP=OFF
cmake --build build --target _lightgbm -j4
sh build-python.sh install --precompile

Additional Comments

I suspect that maybe this is a result of categorical_feature being treated as both a "param" here:

if self.params is not None:
# no min_data, nthreads and verbose in this function
dataset_params = _ConfigAliases.get(
"bin_construct_sample_cnt",
"categorical_feature",

But also being a keyword argument to Dataset.__init__():

categorical_feature: _LGBM_CategoricalFeatureConfiguration = "auto",

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions