Skip to content

[BUG] Fails to parse type of optional num_iteration parameter for LightGBM's predict method #20

@neverfox

Description

@neverfox

Describe the bug

Fails to parse type of optional num_iteration parameter for LightGBM's predict method

INFO:[2024-10-24 10:47:23.863] - Analyzing arguments in <bound method Booster.predict of <lightgbm.basic.Booster object at 0x106d97230>>.
WARNING:[2024-10-24 10:47:23.863] - For model predict argument writes not supported type typing.Union[str, pathlib._local.Path, numpy.ndarray, pandas.core.frame.DataFrame, lightgbm.compat.dt_DataTable, scipy.sparse._matrix.spmatrix, lightgbm.compat.pa_Table]. Skip added validation
WARNING:[2024-10-24 10:47:23.863] - For model predict argument writes not supported type typing.Optional[int]. Skip added validation
WARNING:[2024-10-24 10:47:23.863] - Found unpacked argument: FullArgSpec(args=['self', 'data', 'start_iteration', 'num_iteration', 'raw_score', 'pred_leaf', 'pred_contrib', 'data_has_header', 'validate_features'], varargs=None, varkw='kwargs', defaults=(0, None, False, False, False, False, False), kwonlyargs=[], kwonlydefaults=None, annotations={'return': typing.Union[numpy.ndarray, scipy.sparse._matrix.spmatrix, typing.List[scipy.sparse._matrix.spmatrix]], 'data': typing.Union[str, pathlib._local.Path, numpy.ndarray, pandas.core.frame.DataFrame, lightgbm.compat.dt_DataTable, scipy.sparse._matrix.spmatrix, lightgbm.compat.pa_Table], 'start_iteration': <class 'int'>, 'num_iteration': typing.Optional[int], 'raw_score': <class 'bool'>, 'pred_leaf': <class 'bool'>, 'pred_contrib': <class 'bool'>, 'data_has_header': <class 'bool'>, 'validate_features': <class 'bool'>, 'kwargs': typing.Any}). Skip argument
INFO:[2024-10-24 10:47:23.863] - X argument in predict method not found. For predict data use first argument with name "data".
INFO:[2024-10-24 10:47:23.863] - Time to load model settings: 0.001.
INFO:[2024-10-24 10:47:23.863] - Run load Web application
WARNING:[2024-10-24 10:47:23.864] - Field "num_iteration" has not a type. Please write type for field. Supported types int, float, bool, str, list.

To Reproduce

Steps to reproduce the behavior:

  1. Modify example-config.yaml to load example lightgbm-binary_cls_model.pckl
  2. Run from_config.py
  3. See warning
  4. Open API documentation and see that num_iteration has a default value of "string"

Expected behavior

It should detect that num_iteration is type int but optional. Being optional, the example request in the API docs should not include num_iteration and should correctly indicate that it is an optional int.

Environment (please complete the following information):

  • Python version 3.12.7
  • Version PyMLup 0.2.2
  • LightGBM 4.5.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomers

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions