Skip to content

Commit

Permalink
fixes for empty maps
Browse files Browse the repository at this point in the history
empty maps never worked with block=False, which was never tested!
  • Loading branch information
minrk committed Aug 6, 2021
1 parent 060ac4a commit b5bbcf5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
11 changes: 10 additions & 1 deletion ipyparallel/client/asyncresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(

self._return_exceptions = return_exceptions

if isinstance(children[0], string_types):
if children and isinstance(children[0], string_types):
self.msg_ids = children
self._children = []
else:
Expand All @@ -96,6 +96,15 @@ def __init__(
self._targets = targets
self.owner = owner

if not children:
# empty result!
self._ready = True
self._success = True
f = Future()
f.set_result([])
self._resolve_result(f)
return

self._ready = False
self._ready_event = Event()
self._output_ready = False
Expand Down
4 changes: 4 additions & 0 deletions ipyparallel/client/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def joinPartitions(self, listOfPartitions):
return self.concatenate(listOfPartitions)

def concatenate(self, listOfPartitions):
if len(listOfPartitions) == 0:
return listOfPartitions
testObject = listOfPartitions[0]
# First see if we have a known array type
if is_array(testObject):
Expand All @@ -88,6 +90,8 @@ def getPartition(self, seq, p, q, n=None):
return seq[p:n:q]

def joinPartitions(self, listOfPartitions):
if len(listOfPartitions) == 0:
return listOfPartitions
testObject = listOfPartitions[0]
# First see if we have a known array type
if is_array(testObject):
Expand Down
12 changes: 11 additions & 1 deletion ipyparallel/client/remotefunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,17 @@ def __call__(self, *sequences, **kwargs):

if maxlen == 0:
# nothing to iterate over
return []
if self.block:
return []
else:
return AsyncMapResult(
self.view.client,
[],
self.mapObject,
fname=getname(self.func),
ordered=self.ordered,
return_exceptions=self.return_exceptions,
)

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

0 comments on commit b5bbcf5

Please sign in to comment.