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
Lazy import of sklearn and xgboost #99
Conversation
Hi @yoavram, let me see if I've understood your issue. |
Yes it seems that when I import dtreeviz I get an error about bad xgboost install; when I moved the import (since I work with scikit learn) it works fine. |
I've checkout your PR and uninstalled xgboost. If we cannot install xgboost or have problems importing it, we still will have issues. If we switch the ShadowXGBDTree initialization block and we want to render scikit-learn visualizations, we will receive the "ModuleNotFoundError: No module named 'xgboost'" exception. Since get_shadow_tree() is called from any visualization methods.... I don't have an idea right now how to implement the "lazy" import. Any suggestions ? |
I believe I did lazy import somewhere. hang on. Yep, i've done this kinda stuff. would this be helpful?
|
No I think that’s an overkill. What I mean by “Lazy import” Is that you only import when you need it, not that you import if it hasn’t been imported. The latter is taken care of by Python automatically. |
@tlapusen I’ll take a closer look at what you wrote later. |
Meaning that the user has to do the import? isn't that the way it is now? |
hi @yoavram do you continue with this or should we close this PR ? |
@tlapusan I was thinking that we should do this conditional install that somebody fixed for me in https://github.com/parrt/tensor-sensor That fixes what is required to be installed. Still, inside the code we have to avoid using types that don't exist. We tweaked the code also. See https://github.com/parrt/tensor-sensor/blob/master/tsensor/analysis.py#L459 |
@yoavram my understanding is that those imports would slow things down but I'm not sure it matters, depending on how many times you call the function. I think it's easiest if we asked for the class names and module names to check for types. |
@parrt I'm gonna look on those conditional imports in the next days, thanks. |
I'm laughing because I had no idea you could do conditional pip installs... |
@parrt I've looked over conditional imports and found also pip docs about it. Like you said, we still need to check into code if the libraries are installed or not. I started to work on lightgbm implementation and I would like to work on this fix (#99) later. (happy if someone else could do this meanwhile) |
@tlapusan lightgbm is definitely more important :) |
I think all we need is something like the following in the set up (from tensor-sensor):
then check for the modules:
poking around the web, it looks like people do this for conditional imports:
But, we still need to use the class/module name instead of checking the type in the code. |
Sorry I fell off this issue. Hopefully someone can pick it up. |
Closing since I merged #115. |
Importing xgboost just before using it is needed is useful on systems where it is not installed.
Since installation of XGBoost can be tricky, I think this is a good idea.