예제 #1
0
    def test_table_grouped_tail_synthetic(self):
        test_csv = _make_test_csv_file(
            """
            col1,col2,col3
            a,1,foo
            a,2,bar
            b,1,foo
            b,2,baz
            c,1,foo
            c,2,
            """
        )

        expected = _make_test_csv_file(
            """
            col1,col2,col3
            a,2,bar
            b,2,baz
            c,2,foo
            """
        )

        with temporary_file() as output_file:
            table_grouped_tail(test_csv, output_path=output_file, group_by=["col1"])
            _compare_tables_equal(self, output_file, expected)
예제 #2
0
    def test_cross_product(self):
        csv1 = _make_test_csv_file(
            """
            col1,col2
            a,1
            b,2
            c,3
            d,4
            """
        )

        csv2 = _make_test_csv_file(
            """
            col3,col4
            1,a
            2,b
            3,c
            4,d
            """
        )

        expected = _make_test_csv_file(
            """
            col1,col2,col3,col4
            a,1,1,a
            a,1,2,b
            a,1,3,c
            a,1,4,d
            b,2,1,a
            b,2,2,b
            b,2,3,c
            b,2,4,d
            c,3,1,a
            c,3,2,b
            c,3,3,c
            c,3,4,d
            d,4,1,a
            d,4,2,b
            d,4,3,c
            d,4,4,d
            """
        )

        with temporary_file() as output_file:
            table_cross_product(csv1, csv2, output_file)
            _compare_tables_equal(self, output_file, expected)
    def test_table_concat(self):
        test_csv_1 = _make_test_csv_file("""
            col1,col2
            a,1
            a,2
            """)

        test_csv_2 = _make_test_csv_file("""
            col1,col2,col3
            b,1,foo
            b,2,bar
            """)

        test_csv_3 = _make_test_csv_file("""
            col3,col1,col2
            foo,c,1
            bar,c,2
            """)

        test_csv_4 = _make_test_csv_file("""
            col1
            d
            d
            """)

        expected = _make_test_csv_file("""
            col1,col2,col3
            a,1,
            a,2,
            b,1,foo
            b,2,bar
            c,1,foo
            c,2,bar
            d,,
            d,,
            """)

        with temporary_file() as output_file:
            tables = [test_csv_1, test_csv_2, test_csv_3, test_csv_4]
            table_concat(tables, output_path=output_file)
            _compare_tables_equal(self, output_file, expected)
예제 #4
0
    def test_table_rename(self):
        test_csv = _make_test_csv_file(
            """
            col1,col2,col3
            a,1,foo
            b,2,bar
            c,3,foo
            d,4,bar
            """
        )
        expected = _make_test_csv_file(
            """
            cola,colb
            a,1
            b,2
            c,3
            d,4
            """
        )

        with temporary_file() as output_file:
            table_rename(test_csv, output_file, {"col1": "cola", "col2": "colb", "col3": None})
            _compare_tables_equal(self, output_file, expected)