| 2486 | (([[''], ['foo', 'bar']], [[4.5], [5., None]]), pa.chunked_array), |
| 2487 | ]) |
| 2488 | def test_table_from_pydict_schema(data, klass): |
| 2489 | # passed schema is source of truth for the columns |
| 2490 | |
| 2491 | data = OrderedDict([('strs', klass(data[0])), ('floats', klass(data[1]))]) |
| 2492 | |
| 2493 | # schema has columns not present in data -> error |
| 2494 | schema = pa.schema([('strs', pa.utf8()), ('floats', pa.float64()), |
| 2495 | ('ints', pa.int64())]) |
| 2496 | with pytest.raises(KeyError, match='ints'): |
| 2497 | pa.Table.from_pydict(data, schema=schema) |
| 2498 | |
| 2499 | # data has columns not present in schema -> ignored |
| 2500 | schema = pa.schema([('strs', pa.utf8())]) |
| 2501 | table = pa.Table.from_pydict(data, schema=schema) |
| 2502 | assert table.num_columns == 1 |
| 2503 | assert table.schema == schema |
| 2504 | assert table.column_names == ['strs'] |
| 2505 | |
| 2506 | |
| 2507 | @pytest.mark.parametrize( |