Repository navigation
[python-package] fix mypy error about pandas categorical features - #6253
Conversation
| categorical_feature: _LGBM_CategoricalFeatureConfiguration, | ||
| pandas_categorical: Optional[List[List]] | ||
| ) -> Tuple[np.ndarray, List[str], List[str], List[List]]: | ||
| ) -> Tuple[np.ndarray, List[str], Union[List[str], List[int]], List[List]]: |
There was a problem hiding this comment.
This hint was wrong.
categorical_feature can be a list of integers (indicating 0-based column positions).
And it's passed back out of this function unmodified if it's provided like that.
| if categorical_feature == 'auto': | ||
| categorical_feature = cat_cols_not_ordered | ||
| else: # use cat cols specified by user | ||
| categorical_feature = list(categorical_feature) # type: ignore[assignment] |
There was a problem hiding this comment.
categorical_feature can only be a list of strings, a list of integers, or the literal string 'auto'.
So I don't think this else: clause is helpful. When it's reached, under correctly-provided inputs it's just calling list() on something that's already a list, which has no effect.
I guess this could be providing a small bit of help for cases where some other type like a tuple was passed in, but if we want to support that then:
- it should be done at all public interfaces that support
categorical_feature - it shouldn't be buried inside a
pandas-specific function
I think this can and should be removed, in the interest of further simplifying the flow of pandas data through the library.
|
This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
Contributes to #3756.
Contributes to #3867.
Fixes the following error from
mypy: