Skip to content

Commit 129a529

Browse files
GH-39788: [Python] Validate max_chunksize in Table.to_batches (#39796)
### Rationale for this change Validating the keyword to be strictly positive, to avoid an infinite loop. * Closes: #39788 Authored-by: Joris Van den Bossche <jorisvandenbossche@gmail.com> Signed-off-by: Raúl Cumplido <raulcumplido@gmail.com>
1 parent 796b0cc commit 129a529

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

python/pyarrow/table.pxi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4172,6 +4172,8 @@ cdef class Table(_Tabular):
41724172
reader.reset(new TableBatchReader(deref(self.table)))
41734173

41744174
if max_chunksize is not None:
4175+
if not max_chunksize > 0:
4176+
raise ValueError("'max_chunksize' should be strictly positive")
41754177
c_max_chunksize = max_chunksize
41764178
reader.get().set_chunksize(c_max_chunksize)
41774179

python/pyarrow/tests/test_table.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,9 @@ def test_table_to_batches():
10891089
table_from_iter = pa.Table.from_batches(iter([batch1, batch2, batch1]))
10901090
assert table.equals(table_from_iter)
10911091

1092+
with pytest.raises(ValueError):
1093+
table.to_batches(max_chunksize=0)
1094+
10921095

10931096
def test_table_basics():
10941097
data = [

0 commit comments

Comments
 (0)