Skip to content

fix: remove scipy from dependency #1518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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