Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add computed field with callable #70

Open
akariv opened this issue Feb 1, 2019 · 1 comment
Open

Add computed field with callable #70

akariv opened this issue Feb 1, 2019 · 1 comment

Comments

@akariv
Copy link
Member

akariv commented Feb 1, 2019

Add a computed field that is computed using a Python callable
This is very useful and can be reused. It might make sense to merge with dataflows.add_computed_field.
h/t @shevron

def add_computed_field_callable(name, type, callback, **options):
    def func(package):
        # Alter the schema to add a field
        for resource in package.pkg.descriptor['resources']:
            resource['schema']['fields'].append(dict(name=name, type=type, **options))
        yield package.pkg
        
        def value_setter(rows):
            for row in rows:
                row[name] = callback(row)
                yield row

        for resource in package:
            yield value_setter(resource)

    return func
@akariv
Copy link
Member Author

akariv commented Apr 6, 2019

Fixed via #78

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant