| 2287 | (([[''], ['foo', 'bar']], [[4.5], [5., None]]), pa.chunked_array), |
| 2288 | ]) |
| 2289 | def test_from_arrays_schema(data, klass): |
| 2290 | data = [klass(data[0]), klass(data[1])] |
| 2291 | schema = pa.schema([('strs', pa.utf8()), ('floats', pa.float32())]) |
| 2292 | |
| 2293 | table = pa.Table.from_arrays(data, schema=schema) |
| 2294 | assert table.num_columns == 2 |
| 2295 | assert table.num_rows == 3 |
| 2296 | assert table.schema == schema |
| 2297 | |
| 2298 | # length of data and schema not matching |
| 2299 | schema = pa.schema([('strs', pa.utf8())]) |
| 2300 | with pytest.raises(ValueError): |
| 2301 | pa.Table.from_arrays(data, schema=schema) |
| 2302 | |
| 2303 | # with different but compatible schema |
| 2304 | schema = pa.schema([('strs', pa.utf8()), ('floats', pa.float32())]) |
| 2305 | table = pa.Table.from_arrays(data, schema=schema) |
| 2306 | assert pa.types.is_float32(table.column('floats').type) |
| 2307 | assert table.num_columns == 2 |
| 2308 | assert table.num_rows == 3 |
| 2309 | assert table.schema == schema |
| 2310 | |
| 2311 | # with different and incompatible schema |
| 2312 | schema = pa.schema([('strs', pa.utf8()), ('floats', pa.timestamp('s'))]) |
| 2313 | with pytest.raises((NotImplementedError, TypeError)): |
| 2314 | pa.Table.from_pydict(data, schema=schema) |
| 2315 | |
| 2316 | # Cannot pass both schema and metadata / names |
| 2317 | with pytest.raises(ValueError): |
| 2318 | pa.Table.from_arrays(data, schema=schema, names=['strs', 'floats']) |
| 2319 | |
| 2320 | with pytest.raises(ValueError): |
| 2321 | pa.Table.from_arrays(data, schema=schema, metadata={b'foo': b'bar'}) |
| 2322 | |
| 2323 | |
| 2324 | @pytest.mark.parametrize( |