Skip to content

Commit 6eeca73

Browse files
authored
change: remove scipy from dependencies (#1518)
1 parent 614fe7e commit 6eeca73

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

doc/conf.py

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ def __getattr__(cls, name):
4040
"tensorflow.python.framework",
4141
"tensorflow_serving",
4242
"tensorflow_serving.apis",
43-
"scipy",
44-
"scipy.sparse",
4543
]
4644
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
4745

doc/requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
sphinx==2.2.2
22
numpy
3-
scipy
43
requests==2.20

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def read_version():
3737
"boto3>=1.13.6",
3838
"numpy>=1.9.0",
3939
"protobuf>=3.1",
40-
"scipy>=0.19.0",
4140
"protobuf3-to-dict>=0.1.5",
4241
"smdebug-rulesconfig==0.1.2",
4342
"importlib-metadata>=1.4.0",
@@ -53,6 +52,7 @@ def read_version():
5352
"PyYAML>=5.3, <6", # PyYAML version has to match docker-compose requirements
5453
],
5554
"tensorflow": ["tensorflow>=1.3.0"],
55+
"scipy": ["scipy>=0.19.0"],
5656
}
5757
# Meta dependency groups
5858
extras["all"] = [item for group in extras.values() for item in group]

src/sagemaker/amazon/common.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
from __future__ import absolute_import
1515

1616
import io
17+
import logging
1718
import struct
1819
import sys
1920

2021
import numpy as np
21-
from scipy.sparse import issparse
2222

2323
from sagemaker.amazon.record_pb2 import Record
24+
from sagemaker.utils import DeferredError
2425

2526

2627
class numpy_to_record_serializer(object):
@@ -171,8 +172,16 @@ def write_spmatrix_to_sparse_tensor(file, array, labels=None):
171172
array:
172173
labels:
173174
"""
174-
175-
if not issparse(array):
175+
try:
176+
import scipy
177+
except ImportError as e:
178+
logging.warning(
179+
"scipy failed to import. Sparse matrix functions will be impaired or broken."
180+
)
181+
# Any subsequent attempt to use scipy will raise the ImportError
182+
scipy = DeferredError(e)
183+
184+
if not scipy.sparse.issparse(array):
176185
raise TypeError("Array must be sparse")
177186

178187
# Validate shape of array and labels, resolve array and label types

0 commit comments

Comments
 (0)