Repository navigation
Closed
Labels
bugSomething is broken
Description
I was experimenting with some p2p shuffle workloads, and ran into the following failure when the index is a pandas extension dtype (e.g., the new-ish python[string] dtype).
import distributed
import dask.datasets
cluster = distributed.LocalCluster()
client = distributed.Client(cluster)
ddf = dask.datasets.timeseries()
ddf.index = ddf.index.astype("string[python]")
ddf.shuffle("name", shuffle="p2p").compute()Produces:
Details
AttributeError Traceback (most recent call last)
Input In [45], in <cell line: 10>()
7 ddf = dask.datasets.timeseries()
8 ddf.index = ddf.index.astype("string[python]")
---> 10 ddf.shuffle("name", shuffle="p2p").compute()
File ~/dask/dask/dask/base.py:315, in DaskMethodsMixin.compute(self, **kwargs)
291 def compute(self, **kwargs):
292 """Compute this dask collection
293
294 This turns a lazy Dask collection into its in-memory equivalent.
(...)
313 dask.base.compute
314 """
--> 315 (result,) = compute(self, traverse=False, **kwargs)
316 return result
File ~/dask/dask/dask/base.py:600, in compute(traverse, optimize_graph, scheduler, get, *args, **kwargs)
597 keys.append(x.__dask_keys__())
598 postcomputes.append(x.__dask_postcompute__())
--> 600 results = schedule(dsk, keys, **kwargs)
601 return repack([f(r, *a) for r, (f, a) in zip(results, postcomputes)])
File ~/dask/distributed/distributed/client.py:3036, in Client.get(self, dsk, keys, workers, allow_other_workers, resources, sync, asynchronous, direct, retries, priority, fifo_timeout, actors, **kwargs)
3034 should_rejoin = False
3035 try:
-> 3036 results = self.gather(packed, asynchronous=asynchronous, direct=direct)
3037 finally:
3038 for f in futures.values():
File ~/dask/distributed/distributed/client.py:2210, in Client.gather(self, futures, errors, direct, asynchronous)
2208 else:
2209 local_worker = None
-> 2210 return self.sync(
2211 self._gather,
2212 futures,
2213 errors=errors,
2214 direct=direct,
2215 local_worker=local_worker,
2216 asynchronous=asynchronous,
2217 )
File ~/dask/distributed/distributed/utils.py:338, in SyncMethodMixin.sync(self, func, asynchronous, callback_timeout, *args, **kwargs)
336 return future
337 else:
--> 338 return sync(
339 self.loop, func, *args, callback_timeout=callback_timeout, **kwargs
340 )
File ~/dask/distributed/distributed/utils.py:405, in sync(loop, func, callback_timeout, *args, **kwargs)
403 if error:
404 typ, exc, tb = error
--> 405 raise exc.with_traceback(tb)
406 else:
407 return result
File ~/dask/distributed/distributed/utils.py:378, in sync.<locals>.f()
376 future = asyncio.wait_for(future, callback_timeout)
377 future = asyncio.ensure_future(future)
--> 378 result = yield future
379 except Exception:
380 error = sys.exc_info()
File ~/miniconda3/envs/dask/lib/python3.8/site-packages/tornado/gen.py:769, in Runner.run(self)
766 exc_info = None
768 try:
--> 769 value = future.result()
770 except Exception:
771 exc_info = sys.exc_info()
File ~/dask/distributed/distributed/client.py:2073, in Client._gather(self, futures, errors, direct, local_worker)
2071 exc = CancelledError(key)
2072 else:
-> 2073 raise exception.with_traceback(traceback)
2074 raise exc
2075 if errors == "skip":
File ~/dask/dask/dask/optimization.py:990, in __call__()
988 if not len(args) == len(self.inkeys):
989 raise ValueError("Expected %d args, got %d" % (len(self.inkeys), len(args)))
--> 990 return core.get(self.dsk, self.outkey, dict(zip(self.inkeys, args)))
File ~/dask/dask/dask/core.py:149, in get()
147 for key in toposort(dsk):
148 task = dsk[key]
--> 149 result = _execute_task(task, cache)
150 cache[key] = result
151 result = _execute_task(out, cache)
File ~/dask/dask/dask/core.py:119, in _execute_task()
115 func, args = arg[0], arg[1:]
116 # Note: Don't assign the subtask results to a variable. numpy detects
117 # temporaries by their reference count and can execute certain
118 # operations in-place.
--> 119 return func(*(_execute_task(a, cache) for a in args))
120 elif not ishashable(arg):
121 return arg
File ~/dask/dask/dask/utils.py:71, in apply()
40 """Apply a function given its positional and keyword arguments.
41
42 Equivalent to ``func(*args, **kwargs)``
(...)
68 >>> dsk = {'task-name': task} # adds the task to a low level Dask task graph
69 """
70 if kwargs:
---> 71 return func(*args, **kwargs)
72 else:
73 return func(*args)
File ~/dask/distributed/distributed/shuffle/shuffle.py:42, in shuffle_transfer()
36 def shuffle_transfer(
37 input: pd.DataFrame,
38 id: ShuffleId,
39 npartitions: int | None = None,
40 column: str | None = None,
41 ) -> None:
---> 42 get_ext().add_partition(input, id, npartitions=npartitions, column=column)
File ~/dask/distributed/distributed/shuffle/shuffle_extension.py:286, in add_partition()
279 def add_partition(
280 self,
281 data: pd.DataFrame,
(...)
284 column: str | None = None,
285 ) -> None:
--> 286 shuffle = self.get_shuffle(
287 shuffle_id, empty=data, npartitions=npartitions, column=column
288 )
289 shuffle.add_partition(data=data)
File ~/dask/distributed/distributed/shuffle/shuffle_extension.py:389, in get_shuffle()
382 def get_shuffle(
383 self,
384 shuffle_id: ShuffleId,
(...)
387 npartitions: int | None = None,
388 ) -> Shuffle:
--> 389 return sync(
390 self.worker.loop, self._get_shuffle, shuffle_id, empty, column, npartitions
391 )
File ~/dask/distributed/distributed/utils.py:405, in sync()
403 if error:
404 typ, exc, tb = error
--> 405 raise exc.with_traceback(tb)
406 else:
407 return result
File ~/dask/distributed/distributed/utils.py:378, in f()
376 future = asyncio.wait_for(future, callback_timeout)
377 future = asyncio.ensure_future(future)
--> 378 result = yield future
379 except Exception:
380 error = sys.exc_info()
File ~/miniconda3/envs/dask/lib/python3.8/site-packages/tornado/gen.py:769, in run()
766 exc_info = None
768 try:
--> 769 value = future.result()
770 except Exception:
771 exc_info = sys.exc_info()
File ~/dask/distributed/distributed/shuffle/shuffle_extension.py:352, in _get_shuffle()
348 except KeyError:
349 try:
350 result = await self.worker.scheduler.shuffle_get(
351 id=shuffle_id,
--> 352 schema=pa.Schema.from_pandas(empty).serialize().to_pybytes()
353 if empty is not None
354 else None,
355 npartitions=npartitions,
356 column=column,
357 )
358 except KeyError:
359 # Even the scheduler doesn't know about this shuffle
360 # Let's hand this back to the scheduler and let it figure
361 # things out
362 logger.info(
363 "Worker Shuffle unable to get information from scheduler, rescheduling"
364 )
File ~/miniconda3/envs/dask/lib/python3.8/site-packages/pyarrow/types.pxi:1492, in pyarrow.lib.Schema.from_pandas()
1490 """
1491 from pyarrow.pandas_compat import dataframe_to_types
-> 1492 names, types, metadata = dataframe_to_types(
1493 df,
1494 preserve_index=preserve_index
File ~/miniconda3/envs/dask/lib/python3.8/site-packages/pyarrow/pandas_compat.py:529, in dataframe_to_types()
527 type_ = pa.array(c, from_pandas=True).type
528 elif _pandas_api.is_extension_array_dtype(values):
--> 529 type_ = pa.array(c.head(0), from_pandas=True).type
530 else:
531 values, type_ = get_datetimetz_type(values, c.dtype, None)
AttributeError: 'Index' object has no attribute 'head'This is seemingly due to the same upstream bug in pyarrow as dask/dask#9186
I opened an upstream bug report in pyarrow over here a couple of months ago, but it hasn't gotten too much attention. Perhaps @jorisvandenbossche knows if there is anyone who could take a look?
In the meantime, a workaround is to fall back on the old "object" dtype for strings.
Metadata
Metadata
Assignees
Labels
bugSomething is broken
Activity
jrbourbeau commentedon Sep 8, 2022
Another example of this issue dask/dask#9477
jrbourbeau commentedon Sep 9, 2022
Pushed up a fix in apache/arrow#14080
jrbourbeau commentedon Sep 21, 2022
I just tried this example (and the one in dask/dask#9477) with the nightly release of
pyarrowthat contains apache/arrow#14080 and both pass. Going to close this issue as resolved (thanks again @jorisvandenbossche!)