2

Title says most of it but the object in question is:

>>> import dask.bag as db
>>> b = db.from_sequence([{'name': 'Alice',   'balance': 100},
...                       {'name': 'Bob',     'balance': 200},
...                       {'name': 'Charlie', 'balance': 300}],
...                      npartitions=2)

but when I try

>>> b.to_textfiles('*.json')

I get

AttributeError: 'dict' object has no attribute 'endswith'

Traceback
---------
  File "/Users/jlatmann/anaconda/envs/python3/lib/python3.5/site-packages/dask/async.py", line 267, in execute_task
    result = _execute_task(task, data)
  File "/Users/jlatmann/anaconda/envs/python3/lib/python3.5/site-packages/dask/async.py", line 249, in _execute_task
    return func(*args2)
  File "/Users/jlatmann/anaconda/envs/python3/lib/python3.5/site-packages/dask/bag/core.py", line 1025, in write
    if not (firstline.endswith(os.linesep) or firstline.endswith('\n')):

dask version: 0.9.0

sys.version

3.5.1 |Anaconda 4.0.0 (x86_64)| (default, Dec 7 2015, 11:24:55) [GCC 4.2.1 (Apple Inc. build 5577)]

thanks for looking!

JMann
  • 579
  • 4
  • 12

1 Answers1

1

The to_textfiles function assumes that the elements of the bag are strings. I recommend mapping str on your bag first

b.map(str).to_textfiles('*.json')

Or better yet, given that your output files are json, dump your data to json format explicitly

b.map(json.dumps).to_textfiles('*.json')
MRocklin
  • 55,641
  • 23
  • 163
  • 235
  • but thank-you. and thanks for dask. On review of docs, and despite how obvious it is in retrospect, I would humbly suggest an amendment. – JMann Jun 06 '16 at 18:26
  • Can I interest you in submitting a quick pull request with the change? – MRocklin Jun 07 '16 at 00:40
  • 1
    definitely. (I just need to nail this thing down - which I haven't done yet: got another, very related, problem...) – JMann Jun 07 '16 at 16:19