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

TST make sklearn integration test compatible with 0.24 #3533

Merged
merged 10 commits into from
Nov 10, 2020

Conversation

glemaitre
Copy link
Contributor

Modify the integration test for scikit-learn. Some deprecations have been raised in 0.23 and the upcoming release of 0.24 will break this test.

@ghost
Copy link

ghost commented Nov 6, 2020

CLA assistant check
All CLA requirements met.

for check in _yield_all_checks(name, estimator):
check_name = check.func.__name__ if hasattr(check, 'func') else check.__name__
if check_name == 'check_estimators_nan_inf':
continue # skip test because LightGBM deals with nan
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be handled by the tag allow_nan.

check_name = check.func.__name__ if hasattr(check, 'func') else check.__name__
if check_name == 'check_estimators_nan_inf':
continue # skip test because LightGBM deals with nan
elif check_name == "check_no_attributes_set_in_init":
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be handle by the xfail that I added

@pytest.mark.skipif(
sk_version < "0.23.0", reason="scikit-learn version is less than 0.23"
)
@parametrize_with_checks(list(_tested_estimators()))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only the parametrize_with_checks was using _xfail in 0.23. It has the advantage to show all the test from _yield as with parametrize of pytest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However, it needs to be a pure function not embedded within a class

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.

@glemaitre Thank you very much for updating LightGBM to follow the most recent scikit-learn API changes! Really appreciate it!

Especially thanks a lot for preserving tests for old versions, because we try to target the most wide range of versions.

Generally LGTM! Just please consider checking a few my minor comments below.

tests/python_package_test/test_sklearn.py Outdated Show resolved Hide resolved
tests/python_package_test/test_sklearn.py Outdated Show resolved Hide resolved
Comment on lines +1164 to +1166
xfail_checks = estimator._get_tags()["_xfail_checks"]
check_name = check.__name__ if hasattr(check, "__name__") else check.func.__name__
if xfail_checks and check_name in xfail_checks:
Copy link
Collaborator

Choose a reason for hiding this comment

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

With get() it looks a bit safer.

Suggested change
xfail_checks = estimator._get_tags()["_xfail_checks"]
check_name = check.__name__ if hasattr(check, "__name__") else check.func.__name__
if xfail_checks and check_name in xfail_checks:
xfail_checks = estimator._get_tags().get("_xfail_checks", {})
check_name = check.__name__ if hasattr(check, "__name__") else check.func.__name__
if check_name in xfail_checks:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"_xfail_checks" is always defined because it is a default tag. At least, if there is a breaking change in the future, one could detect it with the failure. WDYT?

Copy link
Collaborator

@StrikerRUS StrikerRUS Nov 9, 2020

Choose a reason for hiding this comment

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

Ah, so _xfail_checks is defined (with empty dict?) in BaseEstimator, if I got it correctly? Then it makes sense!

Then another question. Why do we need if xfail_checks and ... guard?

UPD: Sorry, never mind! Just found the answer: https://github.com/scikit-learn/scikit-learn/blob/1864ed442e9df17007996080946fe86789c63b8f/sklearn/base.py#L35. Default value is False, not {} as I thought.

tests/python_package_test/test_sklearn.py Outdated Show resolved Hide resolved
@StrikerRUS
Copy link
Collaborator

Fixes #2947.

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.

Manny thanks @glemaitre !

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