| 1463 | |
| 1464 | |
| 1465 | def test_table_from_batches_and_schema(): |
| 1466 | schema = pa.schema([ |
| 1467 | pa.field('a', pa.int64()), |
| 1468 | pa.field('b', pa.float64()), |
| 1469 | ]) |
| 1470 | batch = pa.record_batch([pa.array([1]), pa.array([3.14])], |
| 1471 | names=['a', 'b']) |
| 1472 | table = pa.Table.from_batches([batch], schema) |
| 1473 | assert table.schema.equals(schema) |
| 1474 | assert table.column(0) == pa.chunked_array([[1]]) |
| 1475 | assert table.column(1) == pa.chunked_array([[3.14]]) |
| 1476 | |
| 1477 | incompatible_schema = pa.schema([pa.field('a', pa.int64())]) |
| 1478 | with pytest.raises(pa.ArrowInvalid): |
| 1479 | pa.Table.from_batches([batch], incompatible_schema) |
| 1480 | |
| 1481 | incompatible_batch = pa.record_batch([pa.array([1])], ['a']) |
| 1482 | with pytest.raises(pa.ArrowInvalid): |
| 1483 | pa.Table.from_batches([incompatible_batch], schema) |
| 1484 | |
| 1485 | |
| 1486 | @pytest.mark.pandas |