Dependencies#
Types of dependencies#
There are three types of dependencies in sktime:
* “core” dependencies
* “soft” dependencies
* “developer” dependencies
Note
A core dependency is required for sktime to install and run.
They are automatically installed whenever sktime is installed.
Example: pandas
Note
A soft dependency is a dependency that is only required to import
certain modules, but not necessary to use most functionality. A soft
dependency is not installed automatically when the package is
installed. Instead, users need to install it manually if they want to
use a module that requires a soft dependency.
Example: pmdarima
Note
A developer dependency is required for sktime developers, but not for typical
users of sktime.
Example: pytest
We try to keep the number of core dependencies to a minimum and rely on other packages as soft dependencies when feasible.
Adding a soft dependency#
Soft dependencies in sktime should usually be restricted to estimators.
When adding a new soft dependency or changing the version of an existing one, the following files need to be updated:
pyproject.toml, adding the dependency or version bounds in the
all_extrasdependency set. Following the PEP 621 convention, all dependencies including build time dependencies and optional dependencies are specified in this file.
Informative warnings or error messages for missing soft dependencies should be raised, in a situation where a user would need them.
This is handled through our _check_soft_dependencies utility
here.
There are specific conventions to add such warnings in estimators, as below. To add an estimator with a soft dependency, ensure the following:
imports of the soft dependency only happen inside the estimator, e.g., in
_fitor__init__methods of the estimator. In__init__, imports should happen only after calls tosuper(cls).__init__.the
python_dependenciestag of the estimator is populated with astr, or alistofstr, of import dependencies. Exceptions will automatically raised when constructing the estimator in an environment without the required packages.in the python module containing the estimator, the
_check_soft_dependenciesutility is called at the top of the module, withseverity="warning". This will raise an informative warning message already at module import. See hereIn a case where the package import differs from the package name, i.e.,
import package_stringis different frompip install different-package-string(usually the case for packages containing a dash in the name), the_check_soft_dependenciesutility should be used in__init__. Both the warning and constructor call should use thepackage_import_aliasargument for this.If the soft dependencies require specific python versions, the
python_versiontag should also be populated, with a PEP 440 compliant version specificationstrsuch as"<3.10"or">3.6,~=3.8".If including docstring examples that use soft dependencies, ensure to skip doctest. To do this add a
# doctest: +SKIPto the end of each line in the doctest to skip. Check out the arima estimator as as an example. If concerned that skipping the test will reduce test coverage, consider exposing the doctest example as a pytest test function instead, see below how to handle soft dependencies in pytest functions.”.Decorate all pytest tests that import soft dependencies with a
@pytest.mark.skipif(...)conditional on a check to_check_soft_dependenciesfor your new soft depenency. Be sure that all soft dependencies which are imported for testing are imported within the test funciton itself, rather than for the whole module! This decorator will then skip your test unless the system has the required packages installed. Doing this is helpful for any users runningcheck_estimatoron all estimators, or a full local pytest run without the required soft dependency. Again, see the tests for pydarima (in forecasting) for a concrete example.
Adding a core or developer dependency#
Core or developer dependencies can be added only by core developers after discussion in the core developer meeting.
When adding a new core dependency or changing the version of an existing one, the following files need to be updated:
pyproject.toml, adding the dependency or version bounds in the
dependenciesdependency set.
When adding a new developer dependency or changing the version of an existing one, the following files need to be updated:
pyproject.toml, adding the dependency or version bounds in the
devdependency set.