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
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