[python-package] [docs] complete type annotations for scikit-learn fit() methods #5816
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contributes to #3756.
Follow-up to #5757.
Adds type annotations on all remaining arguments to
fit()
methods in the scikit-learn interface.Replaces all remaining uses of "array" or "array-like" in
fit()
docs with specific types, following @StrikerRUS 's suggestion from #3756 (comment).This will hopefully make the docs a bit clearer for users, the code a bit easier to understand for contributors, and will improve
mypy
's ability to catch type issues (both in this project and in upstream projects that depend onlightgbm
).How I tested this
Added additional test cases in
test_sklearn.py
adding some other data types forinit_score
,sample_weight
, and all theeval_*
equivalents. Those tests don't cover every possible combination of all types for all arguments (that would be literally 1000s of tests), but every type in these type annotations is covered at least once by a test.e.g., there isn't a "
y
is a list andinit_score
is a numpy array" test, but there is at least one "y
is a list" test and at least one "init_score
is a numpy array" test.I also ran
mypy
to confirm that this PR does not add any new type-checking errors.