Repository navigation
Dataframe tree reductions - #1663
Conversation
| while k > split_every: | ||
| b = prefix + str(depth) | ||
| for part_i, inds in enumerate(partition_all(split_every, range(k))): | ||
| conc = (_concat, (list, [(a, i) for i in inds])) |
There was a problem hiding this comment.
We may no longer need the explicit call to (list, ...)
|
|
||
| @derived_from(pd.Series) | ||
| def nlargest(self, n=5): | ||
| def nlargest(self, n=5, split_every=None): |
There was a problem hiding this comment.
We will probably eventually want to put in some defaults for these. For operations like nlargest I suspect it'll be in the tens and for operations like value_counts or some of the groupby computations I suspect it'll be around 10.
|
FWIW the times when this has come up it has always been about groupby-aggregations. If quantiles or covariance end up being tricky I would recommend putting them off until after groupby-aggregations. |
|
That's only if you find yourself under time pressure. I'm not sure how hard these things are. |
|
We should think about defaults. These seem to largely depend on the size of the intermediates. Presumably scalar-valued intermediates like sum, min, max can use @jreback if you have experience here with many-grouped groupbys and have the hardware to perform a fast benchmark on a small range of values (e.g. |
|
The When can you set these defaults? meaning at the start of the computation do we know the number of groups that this will generate? (so that can give you an idea of the size of the intermediates) |
The If we have 16 partitions and use If we have 16 partitions and use The lower the number is the safer (fewer intermediate partitions get concat-ed into one task) but also the more overhead there is. |
Just a quick clarification: the default of |
|
Ah, thanks for clarifying |
|
So just to give some real-world (on the previous impl). I was effectively having I suppose this could somehow be dynamically calculated based on the sizes with some sort of cut-off (memory and/or intermediate size)? |
|
You were getting Dynamic calculation of the ideal value here would be very hard. I'm more inclined to use a default value that works well in the many-grouped partitions case, and swallow the overhead in the few-grouped partitions case. |
|
ok sure. I can give this a try. To clarify, I would need to install this PR on: workers, scheduler, notebookenv? (all 3 or just on notebook)? |
|
All |
|
I c. ok will give a try tomorrow then (of course free to merge when ready) |
659af94 to
d53c5fc
Compare
|
Ok, this is ready for review. I'd prefer to finish the A sensible default is still needed. Right now the default is 8 for all operations, and lives in |
|
Waiting on cov / corr / quantile sounds good to me. If you raised this as an issue with the introductory label and gave pointers to a similar problem (like var?) then this seems like the kind of task that might be picked up by a new developer. The default of 8 seems sensible to me. We can tweak in the future if we need to. |
|
Sounds good. I've fixed the failing test (due to a bug in pandas 0.18.0 that has since been fixed). Was there anything else that should be done here, or is everything else future work? I'm not sure if the cov/corr stuff is a beginner issue, but I'll file an issue anyway. I might be able to get to it later this week. |
|
It seems like an moderate-to-expert pandas issue but a beginner dask.dataframe issue perhaps? I might be overly optimistic here. |
|
I'd like to request that we change the default to |
ae421ef to
0816f9c
Compare
|
Done. All scalar reductions (defined as operations that have scalars as intermediates) now have |
mrocklin
left a comment
There was a problem hiding this comment.
I think that we should also use split_every=False in cases where the intermediates are series/dataframes of a fixed small number of rows.
|
|
||
| @derived_from(pd.DataFrame) | ||
| def sum(self, axis=None, skipna=True): | ||
| def sum(self, axis=None, skipna=True, split_every=None): |
There was a problem hiding this comment.
Should this be split_every=False?
There was a problem hiding this comment.
Was assuming only for scalar intermediates, this is a row intermediate. Fixed.
| return super(Series, self).sum(axis=axis, skipna=skipna) | ||
| def sum(self, axis=None, skipna=True, split_every=False): | ||
| return super(Series, self).sum(axis=axis, skipna=skipna, | ||
| split_every=None) |
There was a problem hiding this comment.
This should probably be split_every=split_every
| def nunique(self): | ||
| return self.drop_duplicates().count() | ||
| def nunique(self, split_every=None): | ||
| return self.drop_duplicates(split_every=None).count() |
Not integrated with rest of codebase yet, but added option to aca.
Except for ``cov``, ``corr``, and ``quantile``, all methods are supported.
Still need to add tests.
Due to a bug in pandas 0.18.0, certain series groupby operations lose the series name. Since this is fixed in 0.18.1 and 0.19.0, we'll keep our code the same and just ignore the name checks in the test.
0816f9c to
bc5111d
Compare
|
Addressed all comments, and rebased to fix merge conflicts with the renaming PR. |
|
+1 to merge from me |
|
so trying the tree-reduction PR: 0816f9c (most recent about 1 hr ago, doesn't include the very recent fix). on my big dataset, about 1.5B rows, 50M result set (grouping on a non-categorized text column). was about 37min (before tree-reduction) with split_every (default) -> 15min I am doing 18min |
|
cc @hussainsultan I think you asked about this earlier |
|
Thanks for the benchmark Jeff, that's a nice speedup :). |
This adds tree reductions to
dask.dataframe, allowing for more efficient reductions on dataframes with many partitions. All relevant methods now include an optional keywordsplit_every, which indicates the max number of intermediates to bring together before reducing. The default is 8. Thereductionmethod (and the less publicly usedapply_concat_applyfunction) also take an optionalcombinefunction, to do the intermediate aggregations, before passing toaggregatefor the final reduction.Fixes #1658.
Todo:
groupbysupport tree reductions[ ]cov_corrsupports tree reductions[ ](to be done later, see #1672)quantilesupports tree reductions