Beispiel #1
0
    def test_coalesce_columns(self):
        # Test coalescing into an existing column
        test_raw = [
            {
                'first': 'Bob',
                'last': 'Smith',
                'lastname': None
            },
            {
                'first': 'Jane',
                'last': '',
                'lastname': 'Doe'
            },
            {
                'first': 'Mary',
                'last': 'Simpson',
                'lastname': 'Peters'
            },
        ]
        tbl = Table(test_raw)
        tbl.coalesce_columns('last', ['last', 'lastname'])

        expected = Table([
            {
                'first': 'Bob',
                'last': 'Smith'
            },
            {
                'first': 'Jane',
                'last': 'Doe'
            },
            {
                'first': 'Mary',
                'last': 'Simpson'
            },
        ])
        assert_matching_tables(tbl, expected)

        # Test coalescing into a new column
        tbl = Table(test_raw)
        tbl.coalesce_columns('new_last', ['last', 'lastname'])
        expected = Table([
            {
                'first': 'Bob',
                'new_last': 'Smith'
            },
            {
                'first': 'Jane',
                'new_last': 'Doe'
            },
            {
                'first': 'Mary',
                'new_last': 'Simpson'
            },
        ])
        assert_matching_tables(tbl, expected)