| 2390 | (([[''], ['foo', 'bar']], [[4.5], [5., None]]), pa.chunked_array), |
| 2391 | ]) |
| 2392 | def test_table_from_pydict_arrow_arrays(data, klass): |
| 2393 | data = OrderedDict([('strs', klass(data[0])), ('floats', klass(data[1]))]) |
| 2394 | schema = pa.schema([('strs', pa.utf8()), ('floats', pa.float64())]) |
| 2395 | |
| 2396 | # With arrays as values |
| 2397 | table = pa.Table.from_pydict(data) |
| 2398 | assert table.num_columns == 2 |
| 2399 | assert table.num_rows == 3 |
| 2400 | assert table.schema == schema |
| 2401 | |
| 2402 | # With explicit (matching) schema |
| 2403 | table = pa.Table.from_pydict(data, schema=schema) |
| 2404 | assert table.num_columns == 2 |
| 2405 | assert table.num_rows == 3 |
| 2406 | assert table.schema == schema |
| 2407 | |
| 2408 | # with different but compatible schema |
| 2409 | schema = pa.schema([('strs', pa.utf8()), ('floats', pa.float32())]) |
| 2410 | table = pa.Table.from_pydict(data, schema=schema) |
| 2411 | assert pa.types.is_float32(table.column('floats').type) |
| 2412 | assert table.num_columns == 2 |
| 2413 | assert table.num_rows == 3 |
| 2414 | assert table.schema == schema |
| 2415 | |
| 2416 | # with different and incompatible schema |
| 2417 | schema = pa.schema([('strs', pa.utf8()), ('floats', pa.timestamp('s'))]) |
| 2418 | with pytest.raises((NotImplementedError, TypeError)): |
| 2419 | pa.Table.from_pydict(data, schema=schema) |
| 2420 | |
| 2421 | |
| 2422 | @pytest.mark.parametrize('data, klass', [ |