Skip to content

Commit 87581f4

Browse files
committed
fixes for empty maps
empty maps never worked with block=False, which was never tested!
1 parent b80781a commit 87581f4

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

ipyparallel/client/asyncresult.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __init__(
8484

8585
self._return_exceptions = return_exceptions
8686

87-
if isinstance(children[0], string_types):
87+
if children and isinstance(children[0], string_types):
8888
self.msg_ids = children
8989
self._children = []
9090
else:
@@ -96,6 +96,15 @@ def __init__(
9696
self._targets = targets
9797
self.owner = owner
9898

99+
if not children:
100+
# empty result!
101+
self._ready = True
102+
self._success = True
103+
f = Future()
104+
f.set_result([])
105+
self._resolve_result(f)
106+
return
107+
99108
self._ready = False
100109
self._ready_event = Event()
101110
self._output_ready = False

ipyparallel/client/map.py

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def joinPartitions(self, listOfPartitions):
6666
return self.concatenate(listOfPartitions)
6767

6868
def concatenate(self, listOfPartitions):
69+
if len(listOfPartitions) == 0:
70+
return listOfPartitions
6971
testObject = listOfPartitions[0]
7072
# First see if we have a known array type
7173
if is_array(testObject):
@@ -88,6 +90,8 @@ def getPartition(self, seq, p, q, n=None):
8890
return seq[p:n:q]
8991

9092
def joinPartitions(self, listOfPartitions):
93+
if len(listOfPartitions) == 0:
94+
return listOfPartitions
9195
testObject = listOfPartitions[0]
9296
# First see if we have a known array type
9397
if is_array(testObject):

ipyparallel/client/remotefunction.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,17 @@ def __call__(self, *sequences, **kwargs):
244244

245245
if maxlen == 0:
246246
# nothing to iterate over
247-
return []
247+
if self.block:
248+
return []
249+
else:
250+
return AsyncMapResult(
251+
self.view.client,
252+
[],
253+
self.mapObject,
254+
fname=getname(self.func),
255+
ordered=self.ordered,
256+
return_exceptions=self.return_exceptions,
257+
)
248258

249259
# check that the length of sequences match
250260
if not _mapping and minlen != maxlen:

0 commit comments

Comments
 (0)