Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Aggregation with mixed reduction datatypes (array, scalar, etc) fails on Dask backend #2820

Merged
merged 2 commits into from
Jun 14, 2021

Conversation

timothydijamco
Copy link
Contributor

Problem

Using .aggregate() with a reduction that outputs an array + a reduction that outputs a scalar fails on the Dask backend.

@udf.reduction(
    input_type=[dt.int64],
    output_type=dt.int64,
)
def sum_udf(v):
    return np.sum(v)

@udf.reduction(
    input_type=[dt.int64],
    output_type=dt.Array(dt.int64),
)
def collect_udf(v):
    return np.array(v)

t = t.aggregate(
    sum_col=sum_udf(t['int_col']),
    arr_col=collect_udf(t['int_col'])
)
t.execute()
~/miniconda3/envs/ibis-dev/lib/python3.9/site-packages/dask/dataframe/multi.py in concat(dfs, axis, join, interleave_partitions, ignore_unknown_divisions, **kwargs)
   1138             return concat_unindexed_dataframes(dfs, **kwargs)
   1139         else:
-> 1140             raise ValueError(
   1141                 "Unable to concatenate DataFrame with unknown "
   1142                 "division specifying axis=1"

ValueError: Unable to concatenate DataFrame with unknown division specifying axis=1

When executing .aggregate(), Dask computes the individual reductions, then concatenates them together to form a single DataFrame.

In this case, Dask does not want to concatenate the results of the two reductions because one has known divisions, and the other has unknown divisions:

  1. The non-array reduction UDF results in a delayed object with unknown divisions. This is due to the way we are using dd.from_delayed in coerce_to_output: util.py#L128-L130
  2. The array reduction UDF results in a delayed object with known divisions, due to coerce_to_output using dd.from_pandas: util.py#L134-L136.

Solution

In this PR, we change our use of dd.from_delayed in coerce_to_output to manually specify the divisions. Since the divisions are now always known, Dask will be able to concatenate the results of the individual reductions together.

Copy link
Contributor

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just this is probably worth a release note

@timothydijamco
Copy link
Contributor Author

Thanks, added a release note

@jreback jreback added dask The Dask backend bug Incorrect behavior inside of ibis labels Jun 14, 2021
@jreback jreback added this to the Next release milestone Jun 14, 2021
@jreback jreback merged commit a60a04d into ibis-project:master Jun 14, 2021
@jreback
Copy link
Contributor

jreback commented Jun 14, 2021

thanks @timothydijamco

@cpcloud cpcloud removed this from the Next release milestone Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior inside of ibis dask The Dask backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants