From 2cde3badad1e1b3d2f90c0e490c501b6dcd775f2 Mon Sep 17 00:00:00 2001 From: Jeremy Carbaugh Date: Fri, 9 Oct 2009 17:28:41 -0400 Subject: [PATCH] add keep_records parameter on FieldMerger to prevent it from removing merged fields --- saucebrush/filters.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/saucebrush/filters.py b/saucebrush/filters.py index cdb87a3..1d5ba3a 100644 --- a/saucebrush/filters.py +++ b/saucebrush/filters.py @@ -169,14 +169,18 @@ class FieldMerger(Filter): column bacon that is the result of spam+eggs """ - def __init__(self, mapping, merge_func): + def __init__(self, mapping, merge_func, keep_fields=False): super(FieldMerger, self).__init__() self._field_mapping = mapping self._merge_func = merge_func + self._keep_fields = keep_fields def process_record(self, record): for to_col, from_cols in self._field_mapping.iteritems(): - values = [record.pop(col, None) for col in from_cols] + if self._keep_fields: + values = [record.get(col, None) for col in from_cols] + else: + values = [record.pop(col, None) for col in from_cols] record[to_col] = self._merge_func(*values) return record