def _calculate_value(self, calculation, values):
"""
Parse and perform a calculation using a dict of fields
Using either a dict of values to field names
Returns a NaN if the calculation cannot be performed, e.g.
incorrect field names.
"""
nsp = NumericStringParser()
field_regex = r'\{(.+?)\}'
interpolated_calculation = re.sub(field_regex, self._replace_fields(values), calculation)
try:
result = nsp.eval(interpolated_calculation)
except ParseException:
return None
return result
评论列表
文章目录