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

Filter Node error #382

Closed dainiervg1988 closed 4 years ago

dainiervg1988 commented 4 years ago

I'm testing the Node bonobo.Filter, and trough the following error:

() takes 0 positional arguments but 5 were given It is a basic example. I'm just starting with Bonobo ### My example ```python import bonobo import bonobo_sqlalchemy import sqlalchemy def get_graph(**options): graph = bonobo.Graph( bonobo_sqlalchemy.Select(query='SELECT * FROM data', engine='sqlalchemy.engine'), bonobo.Filter(lambda **row: row['id'] > 8), bonobo.PrettyPrinter() ) return graph def get_services(**options): """ This function builds the services dictionary, which is a simple dict of names-to-implementation used by bonobo for runtime injection. It will be used on top of the defaults provided by bonobo (fs, http, ...). You can override those defaults, or just let the framework define them. You can also define your own services and naming is up to you. :return: dict """ return { 'sqlalchemy.engine': sqlalchemy.create_engine('sqlite:///db.db'), } # The __main__ block actually execute the graph. if __name__ == '__main__': parser = bonobo.get_argument_parser() with bonobo.parse_args(parser) as options: bonobo.run( get_graph(**options), services=get_services(**options) ) ``` ## Versions * Bonobo version: bonobo v.0.7.0rc2 * Python version: 3.6.5 * Platform: Ubuntu 18.04
hartym commented 4 years ago

Hello,

This is happening because your lambda only takes keyword arguments (**) while the previous node sends positionnal arguments.

You can either use positional arguments in your lambda or use the use_raw_input decorator to retrieve only one argument containing the row in the lambda (then defined as ˋlambda row: ...ˋ).

Hope that helps, I usually tend to prefer stackoverflow for questions, posting the SO link here or in slack is ok, and allows to build a knowledge base that people can use on the long term.

Kind regards

dainiervg1988 commented 4 years ago

Thanks, problem solved, and suggestion about questions booked. Regards,