Unverified Commit d8d6faea authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[ci] [python-package] tell mypy 'auto' has a special meaning for feature_name...

[ci] [python-package] tell mypy 'auto' has a special meaning for feature_name and categorical_feature (#5874)
parent 1c873af9
...@@ -12,7 +12,7 @@ from os import SEEK_END, environ ...@@ -12,7 +12,7 @@ from os import SEEK_END, environ
from os.path import getsize from os.path import getsize
from pathlib import Path from pathlib import Path
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union
import numpy as np import numpy as np
import scipy.sparse import scipy.sparse
...@@ -20,6 +20,9 @@ import scipy.sparse ...@@ -20,6 +20,9 @@ import scipy.sparse
from .compat import PANDAS_INSTALLED, concat, dt_DataTable, pd_CategoricalDtype, pd_DataFrame, pd_Series from .compat import PANDAS_INSTALLED, concat, dt_DataTable, pd_CategoricalDtype, pd_DataFrame, pd_Series
from .libpath import find_lib_path from .libpath import find_lib_path
if TYPE_CHECKING:
from typing import Literal
__all__ = [ __all__ = [
'Booster', 'Booster',
'Dataset', 'Dataset',
...@@ -49,8 +52,8 @@ _ctypes_float_array = Union[ ...@@ -49,8 +52,8 @@ _ctypes_float_array = Union[
_LGBM_EvalFunctionResultType = Tuple[str, float, bool] _LGBM_EvalFunctionResultType = Tuple[str, float, bool]
_LGBM_BoosterBestScoreType = Dict[str, Dict[str, float]] _LGBM_BoosterBestScoreType = Dict[str, Dict[str, float]]
_LGBM_BoosterEvalMethodResultType = Tuple[str, str, float, bool] _LGBM_BoosterEvalMethodResultType = Tuple[str, str, float, bool]
_LGBM_CategoricalFeatureConfiguration = Union[List[str], List[int], str] _LGBM_CategoricalFeatureConfiguration = Union[List[str], List[int], "Literal['auto']"]
_LGBM_FeatureNameConfiguration = Union[List[str], str] _LGBM_FeatureNameConfiguration = Union[List[str], "Literal['auto']"]
_LGBM_GroupType = Union[ _LGBM_GroupType = Union[
List[float], List[float],
List[int], List[int],
...@@ -688,7 +691,7 @@ def _data_from_pandas( ...@@ -688,7 +691,7 @@ def _data_from_pandas(
if categorical_feature == 'auto': # use cat cols from DataFrame if categorical_feature == 'auto': # use cat cols from DataFrame
categorical_feature = cat_cols_not_ordered categorical_feature = cat_cols_not_ordered
else: # use cat cols specified by user else: # use cat cols specified by user
categorical_feature = list(categorical_feature) categorical_feature = list(categorical_feature) # type: ignore[assignment]
if feature_name == 'auto': if feature_name == 'auto':
feature_name = list(data.columns) feature_name = list(data.columns)
_check_for_bad_pandas_dtypes(data.dtypes) _check_for_bad_pandas_dtypes(data.dtypes)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment