python-bonobo / bonobo

Extract Transform Load for Python 3.5+
https://www.bonobo-project.org/
Apache License 2.0
1.59k stars 146 forks source link

CsvWriter writes every field from a tuple into a new line #284

Closed Ooxie closed 5 years ago

Ooxie commented 6 years ago

Bonobo version: 0.6.2 + #282 Python version: 3.5.2 Platform: Linux 4.15.0-30 - Ubuntu 16.04.5

Given the input file 'input.csv':

x,y
aaa,bbb
ccc,ddd

And this minimal code:

#!/usr/bin/env python
# -*- coding: utf_8 -*-

import bonobo

@bonobo.config.use_raw_input
def bag_to_tuple(row):
    yield tuple(v for k, v in row._asdict().items())

def get_graph():
    graph = bonobo.Graph()
    graph.add_chain(
        bonobo.CsvReader(path='input.csv'),
        bag_to_tuple,
        bonobo.CsvWriter(path='output.csv'),
    )
    return graph

if __name__ == '__main__':
    bonobo.run(get_graph())

Every field from the simple tuple is written into a new line in the output file 'output.csv':

aaa
bbb
ccc
ddd

All the fields from a tuple should belong to the same line, like below:

aaa,bbb
ccc,ddd
hartym commented 5 years ago

Solved by #295, thanks to @josteinl