Skip to content

Commit

Permalink
Adding an untested map_column record rule
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-bunn committed Oct 31, 2017
1 parent 4129676 commit 11ab360
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions sandpaper/sandpaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,32 @@ def remove_column(self, record, column_name, **kwargs):
del record[column_name]
return record

@record_rule
def map_column(
self, record, from_column, to_column,
replace=False,
**kwargs
):
""" Maps an existing column to a new column.
:param collections.OrderedDict record: A record whose value within
``column`` should be normalized and returned
:param str from_column: The name of the column to remap
:param str to_column: The new name of the column to remap to
:param bool replace: Boolean which indicates if original column
should be removed
:param dict kwargs: Any named arguments
:returns: The record with the remapped column
"""

if from_column not in record:
return record

record[to_column] = record[from_column]
if replace:
del record[from_column]
return record

def apply(
self, from_glob,
max_workers=None, name_generator=None,
Expand Down

0 comments on commit 11ab360

Please sign in to comment.