Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci] [python-package] fix mypy errors in Booster.refit() #5853

Merged
merged 2 commits into from
Apr 25, 2023

Conversation

jameslamb
Copy link
Collaborator

@jameslamb jameslamb commented Apr 25, 2023

Contributes to #3867.

Fixes the following errors from mypy.

python-package/lightgbm/basic.py:4198: error: Item "List[Any]" of "Union[ndarray[Any, Any], Any, List[Any]]" has no attribute "shape"  [union-attr]
python-package/lightgbm/basic.py:4228: error: Item "List[Any]" of "Union[ndarray[Any, Any], Any, List[Any]]" has no attribute "reshape"  [union-attr]

These errors come from the fact that mypy thinks it's possible for _InnerPredictor.predict() to return a List but in the lines those errors are reported on, the code uses the output of _InnerPredictor.predict() as numpy array unconditionally.

mypy doesn't know that when pred_leaf=True, the output of that function will never be a list.

@jameslamb jameslamb merged commit ef5acfb into master Apr 25, 2023
@jameslamb jameslamb deleted the ci/mypy-booster-refit branch April 25, 2023 19:33
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants