Skip to content

Commit 38cbe2c

Browse files
eiccaYannCabanesrtavenar
authored
[MRG] Fix import error when torch is not installed. (#463)
Co-authored-by: Yann Cabanes <[email protected]> Co-authored-by: Romain Tavenard <[email protected]>
1 parent 9be9c7d commit 38cbe2c

8 files changed

+314
-261
lines changed

CHANGELOG.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@ and this project adheres to
88

99
Changelogs for this project are recorded in this file since v0.2.0.
1010

11-
## [Towards v0.6]
11+
12+
13+
## [Towards v0.6.2]
14+
15+
## [v0.6.1]
16+
17+
### Fixed
18+
19+
* Fixed an import error when `torch` is not installed. This error appeared in tslearn v0.6.
20+
`PyTorch` is now an optional dependency.
21+
22+
## [v0.6.0]
1223

1324
### Added
1425

azure-pipelines.yml

+41
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,43 @@ jobs:
1414
python.version: '3.8'
1515
Python39:
1616
python.version: '3.9'
17+
variables:
18+
OMP_NUM_THREADS: '2'
19+
NUMBA_NUM_THREADS: '2'
20+
PIP_PREFER_BINARY: 'true'
21+
22+
steps:
23+
- task: UsePythonVersion@0
24+
inputs:
25+
versionSpec: '$(python.version)'
26+
displayName: 'Use Python $(python.version)'
27+
28+
- script: |
29+
set -xe
30+
python --version
31+
python -m pip install --upgrade pip
32+
python -m pip install -r requirements.txt
33+
python -m pip install torch
34+
displayName: 'Install dependencies'
35+
36+
- script: |
37+
set -xe
38+
python -m pip install -e .
39+
displayName: 'Install tslearn'
40+
41+
- script: |
42+
set -xe
43+
python -m pip install pytest pytest-azurepipelines
44+
python -m pip install scikit-learn==1.0
45+
python -m pip install tensorflow==2.9.0
46+
python -m pytest -v tslearn/ --doctest-modules
47+
displayName: 'Test'
48+
49+
- job: 'linux_without_torch'
50+
pool:
51+
vmImage: 'ubuntu-latest'
52+
strategy:
53+
matrix:
1754
Python310:
1855
python.version: '3.10'
1956
variables:
@@ -32,6 +69,7 @@ jobs:
3269
python --version
3370
python -m pip install --upgrade pip
3471
python -m pip install -r requirements.txt
72+
python -m pip uninstall torch
3573
displayName: 'Install dependencies'
3674
3775
- script: |
@@ -72,6 +110,7 @@ jobs:
72110
python --version
73111
python -m pip install --upgrade pip
74112
python -m pip install -r requirements.txt
113+
python -m pip install torch
75114
displayName: 'Install dependencies'
76115
77116
- script: |
@@ -124,6 +163,7 @@ jobs:
124163
export OPENBLAS=$(brew --prefix openblas)
125164
python -m pip install --upgrade pip
126165
python -m pip install -r requirements.txt
166+
python -m pip install torch
127167
displayName: 'Install dependencies'
128168
129169
- script: |
@@ -169,6 +209,7 @@ jobs:
169209
python --version
170210
python -m pip install --upgrade pip
171211
python -m pip install -r requirements_nocast.txt
212+
python -m pip install torch
172213
displayName: 'Install dependencies'
173214
174215
- script: |

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ scipy
44
scikit-learn
55
joblib>=0.12
66
tensorflow>=2
7-
torch
87
pandas
98
cesium
109
h5py

requirements_nocast.txt

-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ scipy
44
scikit-learn
55
joblib>=0.12
66
tensorflow>=2
7-
torch
87
h5py

tslearn/backend/__init__.py

-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44
"""
55

66
from .backend import Backend, instantiate_backend, select_backend
7-
from .numpy_backend import NumPyBackend
8-
from .pytorch_backend import PyTorchBackend
97

108
__all__ = [
119
"Backend",
1210
"instantiate_backend",
1311
"select_backend",
14-
"NumPyBackend",
15-
"PyTorchBackend",
1612
]

0 commit comments

Comments
 (0)