MCPcopy Create free account
hub / github.com/apache/arrow / test_table_to_batches

Function test_table_to_batches

python/pyarrow/tests/test_table.py:1487–1518  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1485
1486@pytest.mark.pandas
1487def 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(

Callers

nothing calls this directly

Calls 5

listFunction · 0.85
lenFunction · 0.85
mapFunction · 0.85
to_batchesMethod · 0.80
equalsMethod · 0.80

Tested by

no test coverage detected