| 2348 | (([[''], ['foo', 'bar']], [[4.5], [5., None]]), pa.chunked_array), |
| 2349 | ]) |
| 2350 | def test_from_arrays_schema(data, klass): |
| 2351 | data = [klass(data[0]), klass(data[1])] |
| 2352 | schema = pa.schema([('strs', pa.utf8()), ('floats', pa.float32())]) |
| 2353 | |
| 2354 | table = pa.Table.from_arrays(data, schema=schema) |
| 2355 | assert table.num_columns == 2 |
| 2356 | assert table.num_rows == 3 |
| 2357 | assert table.schema == schema |
| 2358 | |
| 2359 | # length of data and schema not matching |
| 2360 | schema = pa.schema([('strs', pa.utf8())]) |
| 2361 | with pytest.raises(ValueError): |
| 2362 | pa.Table.from_arrays(data, schema=schema) |
| 2363 | |
| 2364 | # with different but compatible schema |
| 2365 | schema = pa.schema([('strs', pa.utf8()), ('floats', pa.float32())]) |
| 2366 | table = pa.Table.from_arrays(data, schema=schema) |
| 2367 | assert pa.types.is_float32(table.column('floats').type) |
| 2368 | assert table.num_columns == 2 |
| 2369 | assert table.num_rows == 3 |
| 2370 | assert table.schema == schema |
| 2371 | |
| 2372 | # with different and incompatible schema |
| 2373 | schema = pa.schema([('strs', pa.utf8()), ('floats', pa.timestamp('s'))]) |
| 2374 | with pytest.raises((NotImplementedError, TypeError)): |
| 2375 | pa.Table.from_pydict(data, schema=schema) |
| 2376 | |
| 2377 | # Cannot pass both schema and metadata / names |
| 2378 | with pytest.raises(ValueError): |
| 2379 | pa.Table.from_arrays(data, schema=schema, names=['strs', 'floats']) |
| 2380 | |
| 2381 | with pytest.raises(ValueError): |
| 2382 | pa.Table.from_arrays(data, schema=schema, metadata={b'foo': b'bar'}) |
| 2383 | |
| 2384 | |
| 2385 | @pytest.mark.parametrize( |