dask / dask-expr

BSD 3-Clause "New" or "Revised" License
79 stars 18 forks source link

Better split_out choice in groupby operations #1031

Open phofl opened 2 months ago

phofl commented 2 months ago

Currently, we set the default of split_out automatically based on the number of partitions to make the system more reliable and not squash everything into a single partition. This is not great for low cardinality, since we do an unnecessary shuffle.

We don't have cardinality information at the moment and there is no easy way to get access to them, but we still can do better than what we currently have through looking at the IO partition count/row_count/... of the grouping columns

Assume the following example:

df_left = 1k partitions
df_right = 1 partition

result = df_left.merge(df_right)

result.groupby(columns from right).sum()

Our current default would use 1000 / 15 as the output partition count, but we can infer information about the cardinality that would make split_out=1 a sensible choice. The column originates in a. DataFrame with one partition, which means that cardinality will be low enough to fit into a single partition.