def test_unpack_nested_columns_as_rows_expanded(self): test_table = Table([{ 'id': 1, 'nested': { 'A': 1, 'B': 2, 'C': 3 }, 'extra': 'hi' }, { 'id': 2, 'nested': { 'A': 4, 'B': 5, 'I': 6 }, 'extra': 'hi' }, { 'id': 3, 'nested': 'string!', 'extra': 'hi' }, { 'id': 4, 'nested': None, 'extra': 'hi' }, { 'id': 5, 'nested': ['this!', 'is!', 'a!', 'list!'], 'extra': 'hi' }]) expanded = test_table.unpack_nested_columns_as_rows( 'nested', expand_original=True) # Check that the columns are as expected self.assertEqual(['uid', 'id', 'extra', 'nested', 'nested_value'], expanded.columns) # Check that the row count is as expected self.assertEqual(expanded.num_rows, 12) # Check that the uids are unique, indicating that each row is unique self.assertEqual(len({row['uid'] for row in expanded}), 12)
def test_unpack_nested_columns_as_rows(self): # A Table with mixed content test_table = Table([{ 'id': 1, 'nested': { 'A': 1, 'B': 2, 'C': 3 }, 'extra': 'hi' }, { 'id': 2, 'nested': { 'A': 4, 'B': 5, 'I': 6 }, 'extra': 'hi' }, { 'id': 3, 'nested': 'string!', 'extra': 'hi' }, { 'id': 4, 'nested': None, 'extra': 'hi' }, { 'id': 5, 'nested': ['this!', 'is!', 'a!', 'list!'], 'extra': 'hi' }]) standalone = test_table.unpack_nested_columns_as_rows('nested') # Check that the columns are as expected self.assertEqual(['uid', 'id', 'nested', 'value'], standalone.columns) # Check that the row count is as expected self.assertEqual(standalone.num_rows, 11) # Check that the uids are unique, indicating that each row is unique self.assertEqual(len({row['uid'] for row in standalone}), 11)