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] make scikit-learn estimator tags compatible with scikit-learn>=1.6.0dev #6651

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
13 changes: 13 additions & 0 deletions python-package/lightgbm/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,10 @@ def __init__(
self._n_classes: int = -1
self.set_params(**kwargs)

# scikit-learn 1.6 introduced an __sklearn__tags() method intended to replace _more_tags().
# _more_tags() can be removed whenever lightgbm's minimum supported scikit-learn version
# is >=1.6.
# ref: https://github.com/microsoft/LightGBM/pull/6651
def _more_tags(self) -> Dict[str, Any]:
return {
"allow_nan": True,
Expand All @@ -673,6 +677,15 @@ def _more_tags(self) -> Dict[str, Any]:
},
}

def __sklearn_tags__(self):
tags = super().__sklearn_tags__()
vnherdeiro marked this conversation as resolved.
Show resolved Hide resolved
more_tags = self._more_tags()
tags.input_tags.allow_nan = more_tags["allow_nan"]
tags.input_tags.sparse = "sparse" in more_tags["X_types"]
tags.target_tags.one_d_labels = "1dlabels" in more_tags["X_types"]
tags._xfail_checks = more_tags["_xfail_checks"]
return tags

def __sklearn_is_fitted__(self) -> bool:
return getattr(self, "fitted_", False)

Expand Down
Loading