Skip to content

Writing CSV to disk hangs if the DataFrame is large-ish with a string (object) index (no errors in logs, not out of memory) #7848

Closed

Description

@bsesar

What happened:
Dask hangs when writing a large-ish DataFrame to the disk in CSV format. There are no errors reported in logs and running out of memory does not seem to be an issue.

What you expected to happen:
The DataFrame should have been saved to the disk.

Minimal Complete Verifiable Example:

import multiprocessing.popen_spawn_win32
from dask.distributed import Client
import dask.dataframe as dd
import pandas as pd
from shutil import rmtree
import numpy as np

client = Client()

# create two DataFrames, one with a string index and one without it
Nrows = 83345093
df = pd.DataFrame(np.random.randn(Nrows, 2), columns=list('AB'), index=pd.util.testing.rands_array(16, Nrows, dtype='O'))
df2 = pd.DataFrame(np.random.randn(Nrows, 2), columns=list('AB'))

# create two Dask DataFrames
ddf = dd.from_pandas(df, npartitions=240)
ddf2 = dd.from_pandas(df2, npartitions=240)

# dump the DataFrame without the string index (this works)
ddf2.to_csv('output')
rmtree('output')
ddf2.to_csv('output')
rmtree('output')

# dump the DataFrame with the string index, but one partition at a time (this works)
for partition_id in range(240):
   print(partition_id)
   ax = ddf.get_partition(partition_id)
   _ = ax.to_csv('output')
   rmtree('output')

# dump the DataFrame with the string index, all partitions (this hangs at some point)
ddf.to_csv('output')
rmtree('output')
ddf.to_csv('output')
rmtree('output')

Anything else we need to know?:

Posted this issue also on github page for distributed (dask/distributed#4990).

The above example fully works with 2021.3.0, but it reports the following error message:

distributed.worker - ERROR - ('waiting', 'executing')
Traceback (most recent call last):
  File "C:\Users\--\Anaconda3\envs\work2\lib\site-packages\distributed\worker.py", line 2689, in execute
    await self.ensure_computing()
  File "C:\Users\--\Anaconda3\envs\work2\lib\site-packages\distributed\worker.py", line 2561, in ensure_computing
    self.transition(ts, "executing")
  File "C:\Users\--\Anaconda3\envs\work2\lib\site-packages\distributed\worker.py", line 1553, in transition
    func = self._transitions[start, finish]
KeyError: ('waiting', 'executing')
tornado.application - ERROR - Exception in callback functools.partial(<bound method IOLoop._discard_future_result of <tornado.platform.asyncio.AsyncIOLoop object at 0x000002775BDC6F70>>, <Task finished name='Task-10810' coro=<Worker.execute() done, defined at C:\Users\--\Anaconda3\envs\work2\lib\site-packages\distributed\worker.py:2570> exception=KeyError(('waiting', 'executing'))>)
Traceback (most recent call last):
  File "C:\Users\--\Anaconda3\envs\work2\lib\site-packages\tornado\ioloop.py", line 741, in _run_callback
    ret = callback()
  File "C:\Users\--\Anaconda3\envs\work2\lib\site-packages\tornado\ioloop.py", line 765, in _discard_future_result
    future.result()

The above example does not work on later versions.

Environment:

  • Dask version: 2021.6.2
  • Numpy version: 1.20.3
  • Pandas version: 1.2.5
  • Python version: 3.9.4
  • Operating System: Windows Server 2016 64 bits
  • Install method (conda, pip, source): conda

Activity

  1. bsesar commented on Jul 31, 2021

    @bsesar
    Author

    Closed by dask/distributed#5128. Thanks, @fjetter! :-)

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions