Skip to content

Commit

Permalink
change: remove scipy from dependencies (#1518)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuyang-deng committed Jun 1, 2020
1 parent 614fe7e commit 6eeca73
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 0 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def __getattr__(cls, name):
"tensorflow.python.framework",
"tensorflow_serving",
"tensorflow_serving.apis",
"scipy",
"scipy.sparse",
]
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)

Expand Down
1 change: 0 additions & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
sphinx==2.2.2
numpy
scipy
requests==2.20
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def read_version():
"boto3>=1.13.6",
"numpy>=1.9.0",
"protobuf>=3.1",
"scipy>=0.19.0",
"protobuf3-to-dict>=0.1.5",
"smdebug-rulesconfig==0.1.2",
"importlib-metadata>=1.4.0",
Expand All @@ -53,6 +52,7 @@ def read_version():
"PyYAML>=5.3, <6", # PyYAML version has to match docker-compose requirements
],
"tensorflow": ["tensorflow>=1.3.0"],
"scipy": ["scipy>=0.19.0"],
}
# Meta dependency groups
extras["all"] = [item for group in extras.values() for item in group]
Expand Down
15 changes: 12 additions & 3 deletions src/sagemaker/amazon/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
from __future__ import absolute_import

import io
import logging
import struct
import sys

import numpy as np
from scipy.sparse import issparse

from sagemaker.amazon.record_pb2 import Record
from sagemaker.utils import DeferredError


class numpy_to_record_serializer(object):
Expand Down Expand Up @@ -171,8 +172,16 @@ def write_spmatrix_to_sparse_tensor(file, array, labels=None):
array:
labels:
"""

if not issparse(array):
try:
import scipy
except ImportError as e:
logging.warning(
"scipy failed to import. Sparse matrix functions will be impaired or broken."
)
# Any subsequent attempt to use scipy will raise the ImportError
scipy = DeferredError(e)

if not scipy.sparse.issparse(array):
raise TypeError("Array must be sparse")

# Validate shape of array and labels, resolve array and label types
Expand Down

0 comments on commit 6eeca73

Please sign in to comment.