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

[ci] [python-package] fix missing import, test that lightgbm can be imported with only required dependencies (fixes #5631) #5632

Merged
merged 6 commits into from
Dec 29, 2022

Conversation

jameslamb
Copy link
Collaborator

Fixes #5631.

#5271 added an import from scikit-learn but didn't add the corresponding empty import in compat.py to handle the case where scikit-learn is not installed.

As a result, I believe that using the Python package without scikit-learn has been broken for the last 4 months.

This PR proposes the following:

  • fix that specific import issue
  • add a check in CI to prevent issues like this in the future

@jameslamb
Copy link
Collaborator Author

I initially just pushed the CI changes, and can see that they DO catch the exact error reported in #5631 🎉

ImportError: cannot import name '_LGBMBaseCrossValidator' from 'lightgbm.compat'

And only on the regular task, as intended

Now that there's evidence that that check would catch this, I'll push a fix for the specific issue.

@jameslamb jameslamb changed the title WIP: [ci] [python-package] fix missing import, test that lightgbm can be imported with only required dependencies (fixes #5631) [ci] [python-package] fix missing import, test that lightgbm can be imported with only required dependencies (fixes #5631) Dec 24, 2022
@jameslamb jameslamb marked this pull request as ready for review December 24, 2022 02:56
@jameslamb jameslamb requested a review from guolinke December 24, 2022 02:56
python-package/lightgbm/compat.py Outdated Show resolved Hide resolved
@jmoralez
Copy link
Collaborator

Do you think it'd be worth (maybe in a separate PR) to run the tests as well without the required dependencies? It could help us avoid issues like #4638.

@jameslamb
Copy link
Collaborator Author

jameslamb commented Dec 28, 2022

Do you think it'd be worth (maybe in a separate PR) to run the tests as well without the required dependencies?

Yeah I think that could be helpful for catching other issues like the one you linked and like #5631! Could you write up an issue describing it?

I'd also love to see us take on tests like the following:

@jameslamb jameslamb merged commit 7f4dbc8 into master Dec 29, 2022
@jameslamb jameslamb deleted the fix/scikit-learn branch December 29, 2022 02:16
@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 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[python-package] cannot import name '_LGBMBaseCrossValidator' from 'lightgbm.compat'
2 participants