def test_split(): table = (('id', 'variable', 'value'), ('1', 'parad1', '12'), ('2', 'parad2', '15'), ('3', 'tempd1', '18'), ('4', 'tempd2', '19')) expectation = (('id', 'value', 'variable', 'day'), ('1', '12', 'para', '1'), ('2', '15', 'para', '2'), ('3', '18', 'temp', '1'), ('4', '19', 'temp', '2')) result = split(table, 'variable', 'd', ('variable', 'day')) ieq(expectation, result) ieq(expectation, result) # proper regex result = split(table, 'variable', '[Dd]', ('variable', 'day')) ieq(expectation, result) # integer field reference result = split(table, 1, 'd', ('variable', 'day')) ieq(expectation, result) expectation = (('id', 'variable', 'value', 'variable', 'day'), ('1', 'parad1', '12', 'para', '1'), ('2', 'parad2', '15', 'para', '2'), ('3', 'tempd1', '18', 'temp', '1'), ('4', 'tempd2', '19', 'temp', '2')) result = split(table, 'variable', 'd', ('variable', 'day'), include_original=True) ieq(expectation, result) # what about if no new fields? expectation = (('id', 'value'), ('1', '12', 'para', '1'), ('2', '15', 'para', '2'), ('3', '18', 'temp', '1'), ('4', '19', 'temp', '2')) result = split(table, 'variable', 'd') ieq(expectation, result)
def test_melt_and_split(): table = (('id', 'parad0', 'parad1', 'parad2', 'tempd0', 'tempd1', 'tempd2'), ('1', '12', '34', '56', '37.2', '37.4', '37.9'), ('2', '23', '45', '67', '37.1', '37.8', '36.9')) expectation = (('id', 'value', 'variable', 'day'), ('1', '12', 'para', '0'), ('1', '34', 'para', '1'), ('1', '56', 'para', '2'), ('1', '37.2', 'temp', '0'), ('1', '37.4', 'temp', '1'), ('1', '37.9', 'temp', '2'), ('2', '23', 'para', '0'), ('2', '45', 'para', '1'), ('2', '67', 'para', '2'), ('2', '37.1', 'temp', '0'), ('2', '37.8', 'temp', '1'), ('2', '36.9', 'temp', '2')) step1 = melt(table, key='id') step2 = split(step1, 'variable', 'd', ('variable', 'day')) ieq(expectation, step2)
def test_split_empty(): table = (('foo', 'bar'),) expect = (('foo', 'baz', 'qux'),) actual = split(table, 'bar', 'd', ('baz', 'qux')) ieq(expect, actual)
def test_split_empty(): table = (('foo', 'bar'), ) expect = (('foo', 'baz', 'qux'), ) actual = split(table, 'bar', 'd', ('baz', 'qux')) ieq(expect, actual)