Skip to content

Add tsfresh into optional dependencies #1246

Merged
merged 10 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/docs-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0 # TODO: remove after poetry fix
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/docs-unstable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0 # TODO: remove after poetry fix
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0 # TODO: remove after poetry fix
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install dependencies
run: |
poetry install -E "all release jupyter" -vv
poetry run pip install tsfresh==0.19.0
poetry run pip install protobuf==3.20.1
poetry install -E "all release jupyter classification" -vv
- name: Notebook runner
run: |
poetry run python -m scripts.notebook_runner
7 changes: 0 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0 # TODO: remove after poetry fix
virtualenvs-create: true
virtualenvs-in-project: true

Expand Down Expand Up @@ -89,7 +88,6 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0 # TODO: remove after poetry fix
virtualenvs-create: true
virtualenvs-in-project: true

Expand Down Expand Up @@ -129,7 +127,6 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0 # TODO: remove after poetry fix
virtualenvs-create: true
virtualenvs-in-project: true

Expand Down Expand Up @@ -169,15 +166,12 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0 # TODO: remove after poetry fix
virtualenvs-create: true
virtualenvs-in-project: true

- name: Install dependencies
run: |
poetry install -E "all tests" -vv
poetry run pip install tsfresh==0.19.0
poetry run pip install protobuf==3.20.1
- name: PyTest ("experimental")
run: |
Expand Down Expand Up @@ -209,7 +203,6 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0 # TODO: remove after poetry fix
virtualenvs-create: true
virtualenvs-in-project: true

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-
- Fix warning during creation of `ResampleWithDistributionTransform` ([#1230](https://github.com/tinkoff-ai/etna/pull/1230))
- Add deep copy for copying attributes of `TSDataset` ([#1241](https://github.com/tinkoff-ai/etna/pull/1241))
-
- Add `tsfresh` into optional dependencies, remove instruction about `pip install tsfresh` ([#1246](https://github.com/tinkoff-ai/etna/pull/1246))
-

## [2.0.0] - 2023-04-11
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from etna import SETTINGS

if SETTINGS.tsfresh_required:
if SETTINGS.classification_required:
from tsfresh import extract_features
from tsfresh.feature_extraction.settings import MinimalFCParameters

Expand Down
11 changes: 9 additions & 2 deletions etna/experimental/classification/feature_extraction/weasel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@

import numpy as np
from numpy.lib.stride_tricks import sliding_window_view
from pyts.approximation import SymbolicFourierApproximation
from pyts.transformation import WEASEL
from scipy.sparse import coo_matrix
from scipy.sparse import csr_matrix
from scipy.sparse import hstack
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_selection import chi2
from typing_extensions import Literal

from etna import SETTINGS
from etna.experimental.classification.feature_extraction.base import BaseTimeSeriesFeatureExtractor
from etna.experimental.classification.utils import padd_single_series

if SETTINGS.classification_required:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we ok with this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't get how it works, if user don't have pyts, what happens when he try to instantiate WEASEL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the same logic with NNs, look at models/base.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworked importing logic. Probably, it will work better and more clear.

from pyts.approximation import SymbolicFourierApproximation
from pyts.transformation import WEASEL
else:
from unittest.mock import Mock

WEASEL = Mock # type: ignore


class CustomWEASEL(WEASEL):
"""Improved version of WEASEL transform to work with the series of different length."""
Expand Down
19 changes: 9 additions & 10 deletions etna/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ def _is_prophet_available():
return False


def _is_tsfresh_available():
if _module_available("tsfresh"):
def _is_classification_available():
true_case = _module_available("pyts") & _module_available("tsfresh")
if true_case:
return True
else:
warnings.warn(
"`tsfresh` is not available, to install it, run `pip install tsfresh==0.19.0 && pip install protobuf==3.20.1`"
)
warnings.warn("etna[classification] is not available, to install it, run `pip install etna[classification]`")
return False


Expand All @@ -83,7 +82,7 @@ def __init__( # noqa: D107
torch_required: Optional[bool] = None,
prophet_required: Optional[bool] = None,
wandb_required: Optional[bool] = None,
tsfresh_required: Optional[bool] = None,
classification_required: Optional[bool] = None,
):
# True – use the package
# None – use the package if available
Expand All @@ -101,10 +100,10 @@ def __init__( # noqa: D107
_is_prophet_available,
"etna[prophet] is not available, to install it, run `pip install etna[prophet]`.",
)
self.tsfresh_required: bool = _get_optional_value(
tsfresh_required,
_is_tsfresh_available,
"`tsfresh` is not available, to install it, run `pip install tsfresh==0.19.0 && pip install protobuf==3.20.1`",
self.classification_required: bool = _get_optional_value(
classification_required,
_is_classification_available,
"etna[classification] is not available, to install it, run `pip install etna[classification]`.",
)

@staticmethod
Expand Down
234 changes: 99 additions & 135 deletions examples/classification.ipynb

Large diffs are not rendered by default.

Loading