| 2631 | |
| 2632 | @pytest.mark.pandas |
| 2633 | def test_table_factory_function(): |
| 2634 | import pandas as pd |
| 2635 | |
| 2636 | # Put in wrong order to make sure that lines up with schema |
| 2637 | d = OrderedDict([('b', ['a', 'b', 'c']), ('a', [1, 2, 3])]) |
| 2638 | |
| 2639 | d_explicit = {'b': pa.array(['a', 'b', 'c'], type='string'), |
| 2640 | 'a': pa.array([1, 2, 3], type='int32')} |
| 2641 | |
| 2642 | schema = pa.schema([('a', pa.int32()), ('b', pa.string())]) |
| 2643 | |
| 2644 | df = pd.DataFrame(d) |
| 2645 | table1 = pa.table(df) |
| 2646 | table2 = pa.Table.from_pandas(df) |
| 2647 | assert table1.equals(table2) |
| 2648 | table1 = pa.table(df, schema=schema) |
| 2649 | table2 = pa.Table.from_pandas(df, schema=schema) |
| 2650 | assert table1.equals(table2) |
| 2651 | |
| 2652 | table1 = pa.table(d_explicit) |
| 2653 | table2 = pa.Table.from_pydict(d_explicit) |
| 2654 | assert table1.equals(table2) |
| 2655 | |
| 2656 | # schema coerces type |
| 2657 | table1 = pa.table(d, schema=schema) |
| 2658 | table2 = pa.Table.from_pydict(d, schema=schema) |
| 2659 | assert table1.equals(table2) |
| 2660 | |
| 2661 | |
| 2662 | def test_table_factory_function_args(): |