framework icon indicating copy to clipboard operation
framework copied to clipboard

Make it possible to refer to fields with space in the name on steps.row_filter formula

Open aivuk opened this issue 3 years ago • 0 comments

Currently because of how row_filter is written:


            evalclass = simpleeval.EvalWithCompoundTypes
            function = lambda row: evalclass(names=row).eval(self.formula)

https://github.com/frictionlessdata/framework/blob/79c902b6bc7d6798f6e23bce1bdfd929a3998861/frictionless/steps/row/row_filter.py#L41

it's possible to refer to the fields names from a Resource in a formula passed to steps.row_filter, but if a field name has a space this make it impossible to refer to it. One simple solution would be to write:

function = lambda row: evalclass(names={c: row[c] if c != 'row' else row for c in row.flds +['row']})

and this way an user can use steps.row_filter(formula="field == '42'") or steps.row_filter(formula="row['field'] == '42'"). The first option (without row) will continue to work, but now the user has the option to refer to fields with space like in the second method.

aivuk avatar Nov 28 '22 14:11 aivuk