Commit 5af2cdf6 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: Check validity of recoding and parent-child value replacement rules

parent 5fa3ad2f
......@@ -113,6 +113,11 @@ class Expression(object):
return self.__origExpr
def __repr__(self):
"""Return the original string representation of the expression. """
return str(self)
def variables(self):
"""Return a list of all variables used in the expression. """
......@@ -37,6 +37,7 @@ use variable IDs.
import itertools as it
import functools as ft
import os.path as op
import re
import logging
......@@ -559,6 +560,31 @@ def loadVariableTable(datafiles,
# Merge clean options into variable table
mergeCleanFunctions(vartable, tytable, clean, typeClean, globalClean)
# Check where we can that the
# vartable contains valid rules
def checkLengths(col1, col2, row):
val1 = row[col1]
val2 = row[col2]
isna1 = pd.isna(val1)
isna2 = pd.isna(val2)
# ugh. if the value is a sequence, isna
# will return a sequence of bools
if not isinstance(isna1, bool): isna1 = False
if not isinstance(isna2, bool): isna2 = False
if isna1 and isna2:
if isna1 or isna2 or (len(val1) != len(val2)):
raise ValueError('Columns don\'t match [len({}) != '
'len({})]: {}'.format(val1, val2,
checkRecoding = ft.partial(checkLengths, 'RawLevels', 'NewLevels')
checkParentValues = ft.partial(checkLengths, 'RawLevels', 'NewLevels')
vartable.apply(checkRecoding, axis=1)
vartable.apply(checkParentValues, axis=1)
return vartable, unknownVars, uncleanVars
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment