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

[python-package] Fix mypy errors for predict() method #5678

Merged
merged 1 commit into from
Jan 19, 2023
Merged

[python-package] Fix mypy errors for predict() method #5678

merged 1 commit into from
Jan 19, 2023

Conversation

IdoKendo
Copy link
Contributor

Contributes to #3867.
Moved from #5672.
mypy currently raises the following errors regarding predict() method:

python-package\lightgbm\dask.py:1224: error: Signature of "predict" incompatible with supertype "LGBMClassifier"  [override]
python-package\lightgbm\dask.py:1224: note:      Superclass:
python-package\lightgbm\dask.py:1224: note:          def predict(self, X: Any, raw_score: bool = ..., start_iteration: int = ..., num_iteration: Optional[int] = ..., pred_leaf: bool = ..., pred_contrib: bool = ..., validate_features: bool = ..., **kwargs: Any) -> Any
python-package\lightgbm\dask.py:1224: note:      Subclass:
python-package\lightgbm\dask.py:1224: note:          def predict(self, X: Union[Any, Any], **kwargs: Any) -> Any
python-package\lightgbm\dask.py:1224: error: Signature of "predict" incompatible with supertype "LGBMModel"  [override]
python-package\lightgbm\dask.py:1224: note:          def predict(self, X: Any, raw_score: bool = ..., start_iteration: int = ..., num_iteration: Optional[int] = ..., pred_leaf: bool = ..., pred_contrib: bool = ..., validate_features: bool = ..., **kwargs: Any) -> Any
python-package\lightgbm\dask.py:1224: note:          def predict(self, X: Union[Any, Any], **kwargs: Any) -> Any
python-package\lightgbm\dask.py:1397: error: Signature of "predict" incompatible with supertype "LGBMModel"  [override]
python-package\lightgbm\dask.py:1397: note:      Superclass:
python-package\lightgbm\dask.py:1397: note:          def predict(self, X: Any, raw_score: bool = ..., start_iteration: int = ..., num_iteration: Optional[int] = ..., pred_leaf: bool = ..., pred_contrib: bool = ..., validate_features: bool = ..., **kwargs: Any) -> Any
python-package\lightgbm\dask.py:1397: note:      Subclass:
python-package\lightgbm\dask.py:1397: note:          def predict(self, X: Union[Any, Any], **kwargs: Any) -> Any
python-package\lightgbm\dask.py:1555: error: Signature of "predict" incompatible with supertype "LGBMModel"  [override]
python-package\lightgbm\dask.py:1555: note:      Superclass:
python-package\lightgbm\dask.py:1555: note:          def predict(self, X: Any, raw_score: bool = ..., start_iteration: int = ..., num_iteration: Optional[int] = ..., pred_leaf: bool = ..., pred_contrib: bool = ..., validate_features: bool = ..., **kwargs: Any) -> Any
python-package\lightgbm\dask.py:1555: note:      Subclass:
python-package\lightgbm\dask.py:1555: note:          def predict(self, X: Union[Any, Any], **kwargs: Any) -> Any

Notes for Reviewers

This was tested by running mypy as documented in #3867.

mypy \
    --exclude='python-package/compile/|python-package/build' \
    --ignore-missing-imports \
    python-package/

Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks!

I think the slight added maintenance burden of keeping this in sync with the interface in lightgbm.sklearn is worth it in exchange for mypy being better-able to walk through the Dask*.predict() methods' code (which wouldn't be the case if we instead resolved these particular warnings with # type: ignore comments).

And once mypy checks are fully enabled and cause CI failures, that tool will even alert on issues of the form "hey you changed the lightgbm.sklearn.LGBMClassifier.predict() signature but didn't make the same changes on the Dask side".

@jameslamb jameslamb merged commit 7af85ce into microsoft:master Jan 19, 2023
@IdoKendo IdoKendo deleted the python-package/fix-mypy-predict-errors branch March 9, 2023 15:20
@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