functime icon indicating copy to clipboard operation
functime copied to clipboard

rework missing import mechanism?

Open baggiponte opened this issue 1 year ago • 2 comments

Currently we deal with ImportErrors like this:

try:
    from .lance import ann
except ImportError:
    msg = "Missing ann extras: `pip install functime[ann]`"
    ann = ImportError(msg)

try:
    from .automl import auto_lightgbm
    from .lightgbm import flaml_lightgbm, lightgbm
except ImportError:
    msg = "Missing lightgbm extras: `pip install functime[lgb]`"
    auto_lightgbm = ImportError(msg)
    flaml_lightgbm = ImportError(msg)
    lightgbm = ImportError(msg)

try:
    from .catboost import catboost
except ImportError:
    catboost = ImportError("Missing catboost extras: `pip install functime[cat]`")

try:
    from .xgboost import xgboost
except ImportError:
    xgboost = ImportError("Missing xgboost extras: `pip install functime[xgb]`")

This is clever but means that the issue is raised "lazily" and can lead to issues such as #190 . I think we should revert this.

baggiponte avatar Apr 16 '24 19:04 baggiponte

In scikit-lego we have a little more sophisticated version of such error which can help to point at which version to install (proof).

In general there is a tradeoff between:

  • what the user has immediately available
  • the number of packages required to be installed

Personally, as the base/core dependencies of the functime are already quite broad, I would not add them all 😇 my two cents

FBruzzesi avatar Apr 16 '24 20:04 FBruzzesi

+1 on that. I would actually like to remove as many dependencies as I can (I am looking at you, cloudpickle). I need to improve on the lazy imports though. Polars does too.

baggiponte avatar Apr 17 '24 08:04 baggiponte