| 2451 | (([[''], ['foo', 'bar']], [[4.5], [5., None]]), pa.chunked_array), |
| 2452 | ]) |
| 2453 | def test_table_from_pydict_arrow_arrays(data, klass): |
| 2454 | data = OrderedDict([('strs', klass(data[0])), ('floats', klass(data[1]))]) |
| 2455 | schema = pa.schema([('strs', pa.utf8()), ('floats', pa.float64())]) |
| 2456 | |
| 2457 | # With arrays as values |
| 2458 | table = pa.Table.from_pydict(data) |
| 2459 | assert table.num_columns == 2 |
| 2460 | assert table.num_rows == 3 |
| 2461 | assert table.schema == schema |
| 2462 | |
| 2463 | # With explicit (matching) schema |
| 2464 | table = pa.Table.from_pydict(data, schema=schema) |
| 2465 | assert table.num_columns == 2 |
| 2466 | assert table.num_rows == 3 |
| 2467 | assert table.schema == schema |
| 2468 | |
| 2469 | # with different but compatible schema |
| 2470 | schema = pa.schema([('strs', pa.utf8()), ('floats', pa.float32())]) |
| 2471 | table = pa.Table.from_pydict(data, schema=schema) |
| 2472 | assert pa.types.is_float32(table.column('floats').type) |
| 2473 | assert table.num_columns == 2 |
| 2474 | assert table.num_rows == 3 |
| 2475 | assert table.schema == schema |
| 2476 | |
| 2477 | # with different and incompatible schema |
| 2478 | schema = pa.schema([('strs', pa.utf8()), ('floats', pa.timestamp('s'))]) |
| 2479 | with pytest.raises((NotImplementedError, TypeError)): |
| 2480 | pa.Table.from_pydict(data, schema=schema) |
| 2481 | |
| 2482 | |
| 2483 | @pytest.mark.parametrize('data, klass', [ |