Support dask.bag reductions on no partitions#2324
Merged
mrocklin merged 3 commits intodask:masterfrom May 14, 2017
Merged
Conversation
e522bf5 to
67f3972
Compare
jcrist
reviewed
May 11, 2017
| return Item({b: task}, b) | ||
| else: | ||
| return Bag({(b, 0): task}, b, 1) | ||
|
|
Member
There was a problem hiding this comment.
I may be wrong, but I think this patch is equivalent, but doesn't special case certain numbers of partitions:
--- a/dask/bag/core.py
+++ b/dask/bag/core.py
@@ -731,11 +731,10 @@ class Bag(Base):
b = a
fmt = '%s-aggregate-%s' % (name or funcname(aggregate), token)
depth = 0
- while k > 1:
+ while k > split_every:
c = fmt + str(depth)
- is_last = k <= split_every
dsk2 = dict(((c, i), (empty_safe_aggregate, aggregate,
- [(b, j) for j in inds], is_last))
+ [(b, j) for j in inds], False))
for i, inds in enumerate(partition_all(split_every,
range(k))))
dsk.update(dsk2)
@@ -743,11 +742,14 @@ class Bag(Base):
b = c
depth += 1
+ dsk[(fmt, 0)] = (empty_safe_aggregate, aggregate,
+ [(b, j) for j in range(k)], True)
+
if out_type is Item:
- dsk[b] = dsk.pop((b, 0))
- return Item(merge(self.dask, dsk), b)
+ dsk[fmt] = dsk.pop((fmt, 0))
+ return Item(merge(self.dask, dsk), fmt)
else:
- return Bag(merge(self.dask, dsk), b, 1)
+ return Bag(merge(self.dask, dsk), fmt, 1)
def sum(self, split_every=None):
""" Sum all elements """Suggestion by jcrist
Member
Author
|
Merging this soon if there are no further comments |
Member
|
Looks good to me. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.