facebookresearch / Kats

Kats, a kit to analyze time series data, a lightweight, easy-to-use, generalizable, and extendable framework to perform time series analysis, from understanding the key statistics and characteristics, detecting change points and anomalies, to forecasting future trends.
MIT License
4.89k stars 536 forks source link

Fix minimal installation on globalmodel import #196

Closed adamantike closed 2 years ago

adamantike commented 2 years ago

Since the introduction of globalmodel models, the Kats installation using MINIMAL_KATS=1 fails with the following error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/src/kats/__init__.py", line 7, in <module>
    from . import detectors  # noqa # usort: skip
  File "/src/kats/detectors/__init__.py", line 20, in <module>
    from .meta_learning import metalearning_detection_model  # noqa # usort: skip
  File "/src/kats/detectors/meta_learning/metalearning_detection_model.py", line 11, in <module>
    from kats.models.metalearner.metalearner_modelselect import MetaLearnModelSelect
  File "/src/kats/models/__init__.py", line 18, in <module>
    from . import globalmodel  # noqa
  File "/src/kats/models/globalmodel/__init__.py", line 5, in <module>
    from . import backtester  # noqa
  File "/src/kats/models/globalmodel/backtester.py", line 16, in <module>
    import torch
ModuleNotFoundError: No module named 'torch'

As the globalmodel/backtester.py file requires torch, it's needed to just warn about the absense of torch, and allow the imports to work for minimal installation.

This behavior was tested using the following imports:

python -c 'from kats.consts import TimeSeriesData'
python -c 'from kats.models.prophet import ProphetModel'
python -c 'from kats.detectors.cusum_detection import CUSUMDetector'
python -c 'from kats.tsfeatures.tsfeatures import TsFeatures'
michaelbrundage commented 2 years ago

Thanks, @adamantike , sorry, just now seeing this PR. I think we've already fixed it -- and added a Github action to test minimal install, so it shouldn't invisibly break again. Is the current code working for you?

michaelbrundage commented 2 years ago

Fixed in c501da1d49313c12616ff06297b221d80cd36f57