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] change types in sklearn.py initializations #5718

Merged
merged 3 commits into from
Feb 24, 2023

Conversation

jameslamb
Copy link
Collaborator

Contributes to #3756.
Contributes to #3867.

Follow-up to #5672 (thanks @IdoKendo for starting this discussion again!)

Fixes the following errors from mypy.

python-package/lightgbm/sklearn.py:897: error: Incompatible return value type (got "None", expected "int")  [return-value]
python-package/lightgbm/sklearn.py:904: error: Incompatible return value type (got "None", expected "int")  [return-value]
python-package/lightgbm/sklearn.py:918: error: Incompatible return value type (got "Optional[int]", expected "int")  [return-value]

See my description in #5672 (comment) for the reasoning behind this proposed change.

How I tested this

Besides just running mypy and the unit tests, I wanted to also confirm that there wasn't any other code relying on the attributes _n_features, _n_features_in, and _best_iteration being initialized to None.

Since those are private attributes of a class inside lightgbm, it's sufficient just to check this repository for such references.

git grep '_n_features'
git grep '_best_iteration'

I didn't see any places relying specifically on those attributes being initialized to None, so I think changing them to be initialized to -1 is safe.

@jameslamb
Copy link
Collaborator Author

I'll wait to merge this one until you have a chance to also review, @jmoralez (no rush!)

@jameslamb jameslamb merged commit af82fc9 into master Feb 24, 2023
@jameslamb jameslamb deleted the ci/mypy-sklearn branch February 24, 2023 16:07
@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.

3 participants