()
| 1485 | |
| 1486 | @pytest.mark.pandas |
| 1487 | def test_table_to_batches(): |
| 1488 | from pandas.testing import assert_frame_equal |
| 1489 | import pandas as pd |
| 1490 | |
| 1491 | df1 = pd.DataFrame({'a': list(range(10))}) |
| 1492 | df2 = pd.DataFrame({'a': list(range(10, 30))}) |
| 1493 | |
| 1494 | batch1 = pa.RecordBatch.from_pandas(df1, preserve_index=False) |
| 1495 | batch2 = pa.RecordBatch.from_pandas(df2, preserve_index=False) |
| 1496 | |
| 1497 | table = pa.Table.from_batches([batch1, batch2, batch1]) |
| 1498 | |
| 1499 | expected_df = pd.concat([df1, df2, df1], ignore_index=True) |
| 1500 | |
| 1501 | batches = table.to_batches() |
| 1502 | assert len(batches) == 3 |
| 1503 | |
| 1504 | assert_frame_equal(pa.Table.from_batches(batches).to_pandas(), |
| 1505 | expected_df) |
| 1506 | |
| 1507 | batches = table.to_batches(max_chunksize=15) |
| 1508 | assert list(map(len, batches)) == [10, 15, 5, 10] |
| 1509 | |
| 1510 | assert_frame_equal(table.to_pandas(), expected_df) |
| 1511 | assert_frame_equal(pa.Table.from_batches(batches).to_pandas(), |
| 1512 | expected_df) |
| 1513 | |
| 1514 | table_from_iter = pa.Table.from_batches(iter([batch1, batch2, batch1])) |
| 1515 | assert table.equals(table_from_iter) |
| 1516 | |
| 1517 | with pytest.raises(ValueError): |
| 1518 | table.to_batches(max_chunksize=0) |
| 1519 | |
| 1520 | |
| 1521 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected