Skip to content

Groupby aggregations fail with string[pyarrow] and p2p shuffle #9477

Closed

Description

@jrbourbeau

@rjzamora and I saw today that using the new shuffle-based groupby-aggregation algorithm with p2p shuffling and string[pyarrow] dtypes runs into issues. See the reproducer below:

from dask.datasets import timeseries
from distributed import Client


if __name__ == "__main__":
    with Client():
        ddf = timeseries(dtypes={"x": float, "y": str})
        ddf = ddf.astype({"y": "string[pyarrow]"})

        ddf.groupby("y").agg({"x": "mean"}, shuffle="p2p").compute()

fails with

...
...
  File "/Users/james/projects/dask/distributed/distributed/shuffle/shuffle_extension.py", line 352, in _get_shuffle
    schema=pa.Schema.from_pandas(empty).serialize().to_pybytes()
  File "pyarrow/types.pxi", line 1690, in pyarrow.lib.Schema.from_pandas
  File "/Users/james/mambaforge/envs/dask/lib/python3.10/site-packages/pyarrow/pandas_compat.py", line 544, in dataframe_to_types
    type_ = pa.array(c.head(0), from_pandas=True).type
AttributeError: 'Index' object has no attribute 'head'
Full traceback:
2022-09-08 14:57:15,593 - distributed.worker - WARNING - Compute Failed
Key:       ('shuffle_transfer-2766e99ad1002468f827e3a647a7caf4', 0)
Function:  subgraph_callable-b461f7cf-7f41-4bf3-8f42-3ca9ddba
args:      (        count-x-caf6abc2c5c9c7a4c1b06ad5806fad59  sum-x-9f523534b383db420c8cfd35ee5a7c27  _partitions
y
Xavier                                      3294                              -27.045405            2
Oliver                                      3300                              -53.233624            2
Hannah                                      3378                              -23.227861            2
Laura                                       3314                               41.832917            1
Yvonne                                      3395                               27.688311            1
...                                          ...                                     ...          ...
Edith                                       3384                              -16.384580            2
Xavier                                      3350                               41
kwargs:    {}
Exception: 'AttributeError("\'Index\' object has no attribute \'head\'")'

Traceback (most recent call last):
  File "/Users/james/projects/dask/dask/test.py", line 10, in <module>
    ddf.groupby("y").agg({"x": "mean"}, shuffle="p2p").compute()
  File "/Users/james/projects/dask/dask/dask/base.py", line 315, in compute
    (result,) = compute(self, traverse=False, **kwargs)
  File "/Users/james/projects/dask/dask/dask/base.py", line 600, in compute
    results = schedule(dsk, keys, **kwargs)
  File "/Users/james/projects/dask/distributed/distributed/client.py", line 3052, in get
    results = self.gather(packed, asynchronous=asynchronous, direct=direct)
  File "/Users/james/projects/dask/distributed/distributed/client.py", line 2226, in gather
    return self.sync(
  File "/Users/james/projects/dask/distributed/distributed/utils.py", line 339, in sync
    return sync(
  File "/Users/james/projects/dask/distributed/distributed/utils.py", line 406, in sync
    raise exc.with_traceback(tb)
  File "/Users/james/projects/dask/distributed/distributed/utils.py", line 379, in f
    result = yield future
  File "/Users/james/mambaforge/envs/dask/lib/python3.10/site-packages/tornado/gen.py", line 762, in run
    value = future.result()
  File "/Users/james/projects/dask/distributed/distributed/client.py", line 2089, in _gather
    raise exception.with_traceback(traceback)
  File "/Users/james/projects/dask/dask/dask/optimization.py", line 990, in __call__
    return core.get(self.dsk, self.outkey, dict(zip(self.inkeys, args)))
  File "/Users/james/projects/dask/dask/dask/core.py", line 149, in get
    result = _execute_task(task, cache)
  File "/Users/james/projects/dask/dask/dask/core.py", line 119, in _execute_task
    return func(*(_execute_task(a, cache) for a in args))
  File "/Users/james/projects/dask/dask/dask/utils.py", line 71, in apply
    return func(*args, **kwargs)
  File "/Users/james/projects/dask/distributed/distributed/shuffle/shuffle.py", line 42, in shuffle_transfer
    get_ext().add_partition(input, id, npartitions=npartitions, column=column)
  File "/Users/james/projects/dask/distributed/distributed/shuffle/shuffle_extension.py", line 286, in add_partition
    shuffle = self.get_shuffle(
  File "/Users/james/projects/dask/distributed/distributed/shuffle/shuffle_extension.py", line 389, in get_shuffle
    return sync(
  File "/Users/james/projects/dask/distributed/distributed/utils.py", line 406, in sync
    raise exc.with_traceback(tb)
  File "/Users/james/projects/dask/distributed/distributed/utils.py", line 379, in f
    result = yield future
  File "/Users/james/mambaforge/envs/dask/lib/python3.10/site-packages/tornado/gen.py", line 762, in run
    value = future.result()
  File "/Users/james/projects/dask/distributed/distributed/shuffle/shuffle_extension.py", line 352, in _get_shuffle
    schema=pa.Schema.from_pandas(empty).serialize().to_pybytes()
  File "pyarrow/types.pxi", line 1690, in pyarrow.lib.Schema.from_pandas
  File "/Users/james/mambaforge/envs/dask/lib/python3.10/site-packages/pyarrow/pandas_compat.py", line 544, in dataframe_to_types
    type_ = pa.array(c.head(0), from_pandas=True).type
AttributeError: 'Index' object has no attribute 'head'

Package versions:

  • dask: main branch
  • distributed: main branch
  • pyarrow: 9.0.0

Activity

  1. added
    bug
    on Sep 8, 2022
  2. ian-r-rose commented on Sep 8, 2022

    @ian-r-rose
    Collaborator

    I believe this is a duplicate of dask/distributed#6927 .

  3. jrbourbeau commented on Sep 8, 2022

    @jrbourbeau
    MemberAuthor

    Ah, indeed. I missed that because it was over in dask/distributed. Will close this issue in favor of that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdataframe

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions