From 04aa45246aa58214b1986c9faceda558ee9216cd 2013-08-15 04:13:34 From: Min RK Date: 2013-08-15 04:13:34 Subject: [PATCH] Merge pull request #4021 from samuela/master Fix parallel.client.View map() on numpy arrays closes #4020 --- diff --git a/IPython/parallel/client/remotefunction.py b/IPython/parallel/client/remotefunction.py index 07e9327..4b31a0b 100644 --- a/IPython/parallel/client/remotefunction.py +++ b/IPython/parallel/client/remotefunction.py @@ -232,7 +232,8 @@ class ParallelFunction(RemoteFunction): for seq in sequences: part = self.mapObject.getPartition(seq, index, nparts, maxlen) args.append(part) - if not any(args): + + if sum([len(arg) for arg in args]) == 0: continue if self._mapping: diff --git a/IPython/parallel/tests/test_view.py b/IPython/parallel/tests/test_view.py index 7a3540e..42ac54e 100644 --- a/IPython/parallel/tests/test_view.py +++ b/IPython/parallel/tests/test_view.py @@ -342,8 +342,20 @@ class TestView(ClusterTestCase, ParametricTestCase): arr = range(101) # ensure it will be an iterator, even in Python 3 it = iter(arr) - r = view.map_sync(lambda x:x, arr) + r = view.map_sync(lambda x: x, it) self.assertEqual(r, list(arr)) + + @skip_without('numpy') + def test_map_numpy(self): + """test map on numpy arrays (direct)""" + import numpy + from numpy.testing.utils import assert_array_equal + + view = self.client[:] + # 101 is prime, so it won't be evenly distributed + arr = numpy.arange(101) + r = view.map_sync(lambda x: x, arr) + assert_array_equal(r, arr) def test_scatter_gather_nonblocking(self): data = range(16)