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] add type hints on cv() #5271

Merged
merged 4 commits into from
Jun 19, 2022
Merged

[python-package] add type hints on cv() #5271

merged 4 commits into from
Jun 19, 2022

Conversation

jameslamb
Copy link
Collaborator

Contributes to #3756.

This PR proposes adding type hints to lightgbm.cv(), to improve mypy's ability to catch issues.

params: Dict[str, Any],
train_set: Dataset,
num_boost_round: int = 100,
folds: Optional[Union[Iterable[Tuple[np.ndarray, np.ndarray]], _LGBMBaseCrossValidator]] = None,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

according to https://docs.python.org/3/library/typing.html#typing.Generator, it's ok to use Iterable[return_type] to document a generator or iterator. So it isn't necessary to use typing.Generator or typing.Iterator.

@@ -75,9 +75,9 @@ def __init__(self, *args, **kwargs):
from sklearn.utils.validation import assert_all_finite, check_array, check_X_y
try:
from sklearn.exceptions import NotFittedError
from sklearn.model_selection import GroupKFold, StratifiedKFold
from sklearn.model_selection import BaseCrossValidator, GroupKFold, StratifiedKFold
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sklearn.model_selection.BaseCrossValidator has been in scikit-learn for at least 7 years, so I don't think this will cause any portability issues.

https://github.com/scikit-learn/scikit-learn/blame/159cb46c5672b0ba87d0ba80c6b80ec1aa5fda32/sklearn/model_selection/__init__.py#L3

Copy link
Collaborator

@StrikerRUS StrikerRUS left a comment

Choose a reason for hiding this comment

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

Just two comments.

python-package/lightgbm/engine.py Outdated Show resolved Hide resolved
python-package/lightgbm/engine.py Outdated Show resolved Hide resolved
python-package/lightgbm/engine.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@StrikerRUS StrikerRUS left a comment

Choose a reason for hiding this comment

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

LGTM!

@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 19, 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