Skip to content

SPARK-1917: fix PySpark import of scipy.special functions #866

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

Closed
wants to merge 2 commits into from
Closed
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: 1 addition & 1 deletion python/pyspark/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ def _change_cell_value(cell, newval):
Note: These can never be renamed due to client compatibility issues"""

def _getobject(modname, attribute):
mod = __import__(modname)
mod = __import__(modname, fromlist=[attribute])
return mod.__dict__[attribute]

def _generateImage(size, mode, str_rep):
Expand Down
24 changes: 24 additions & 0 deletions python/pyspark/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
from pyspark.files import SparkFiles
from pyspark.serializers import read_int

_have_scipy = False
try:
import scipy.sparse
_have_scipy = True
except:
# No SciPy, but that's okay, we'll skip those tests
pass


SPARK_HOME = os.environ["SPARK_HOME"]

Expand Down Expand Up @@ -359,5 +367,21 @@ def test_single_script_on_cluster(self):
self.assertIn("[2, 4, 6]", out)


@unittest.skipIf(not _have_scipy, "SciPy not installed")
class SciPyTests(PySparkTestCase):
"""General PySpark tests that depend on scipy """

def test_serialize(self):
from scipy.special import gammaln
x = range(1, 5)
expected = map(gammaln, x)
observed = self.sc.parallelize(x).map(gammaln).collect()
self.assertEqual(expected, observed)


if __name__ == "__main__":
if not _have_scipy:
print "NOTE: Skipping SciPy tests as it does not seem to be installed"
unittest.main()
if not _have_scipy:
print "NOTE: SciPy tests were skipped as it does not seem to be installed"