You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Python] pa.record_batch raises TypeError for tuple data #55418
Hello @AlenkaF
I would like to work on this issue and submit a solution along with the necessary tests.
Would it be possible for me to take responsibility for this issue ?
Thank you
@kartik00052 please stop indiscriminately posting on all newly created issues or we will have to ban you. There is a reason the previous PR was closed. Please investigate a little bit before indiscriminately pinging if you can work on an issue.
Check whether there's someone else working on it (does it have PRs? is it assigned?) also check if there are related closed PRs what is the reason, if there is a conversation take that into account.
Keep RecordBatch.from_arrays restricted to lists and convert tuples via list(data) inside pa.record_batch().
Option 1 provides consistency across both tabular constructors. Does removing the list restriction on RecordBatch.from_arrays match the intended design?
Happy to put together a PR with tests for (1) if that is the preferred direction.
My first question, which I haven't investigated yet, is: why is arrays parameter typed to list in Cython, is there a special reason behind that decision? If yes, we can not blindly remove the type restriction there.
I checked the history and implementation of RecordBatch.from_arrays to see why arrays was typed to list in Cython:
There does not appear to be an architectural or safety reason for it, looks to be a historical artifact from 2017.
A few details:
Under the hood:RecordBatch.from_arrays only checks len(arrays) and arrays[0] before passing it to _sanitize_arrays(arrays, ...). _sanitize_arrays produces an internal Python list (converted_arrays), which is then used to populate the C++ vector[shared_ptr[CArray]]. The input sequence is never passed directly to C++.
Parity with Table:Table.from_arrays has always kept arrays untyped and accepts tuples without issue.
Original intent: When pa.record_batch() was added in ARROW-6263, it was explicitly written as if isinstance(data, (list, tuple)): return RecordBatch.from_arrays(data, ...). Tuples were clearly intended to be supported, but were blocked by the legacy Cython typing.
Given that, dropping the list restriction on RecordBatch.from_arrays (def from_arrays(arrays, ...)) should be completely safe and aligns it with Table.from_arrays and the typing stubs in #55264.
Commit history details
Oct 2016 (a9747ceac, ARROW-312): Both RecordBatch.from_arrays and Table.from_arrays were originally untyped (def from_arrays(names, arrays)).
Jul 2018 (ec9b72a23, ARROW-1715):list names was relaxed to names in RecordBatch.from_arrays to support schemas during unpickling, leaving list arrays.
Dec 2018 (9da458437, ARROW-2624):dict metadata was relaxed to metadata to allow arbitrary mappings, leaving list arrays.
Aug 2019 (05bc63c3b, ARROW-6263):pa.record_batch and pa.table factory functions were added with isinstance(data, (list, tuple)). pa.table worked because Table.from_arrays was untyped, while pa.record_batch failed on tuples due to the remaining Cython check.
Activity
Moemenmohamed24 commentedon Nov 5, 2026
Hello @AlenkaF
I would like to work on this issue and submit a solution along with the necessary tests.
Would it be possible for me to take responsibility for this issue ?
Thank you
kartik00052 commentedon Nov 6, 2026
can I work on this now...??
AlenkaF commentedon Nov 6, 2026
This issue needs some discussion on the approach to take first, before any PR is made.
raulcd commentedon Nov 6, 2026
@kartik00052 please stop indiscriminately posting on all newly created issues or we will have to ban you. There is a reason the previous PR was closed. Please investigate a little bit before indiscriminately pinging if you can work on an issue.
Check whether there's someone else working on it (does it have PRs? is it assigned?) also check if there are related closed PRs what is the reason, if there is a conversation take that into account.
Awesome06 commentedon Nov 8, 2026
There appear to be two ways to resolve this:
listtype restriction onRecordBatch.from_arrays(arrays, ...)to accept any sequence, matchingTable.from_arraysand theSequence[...]typing stubs in GH-55263: [Python][Annotations] Add internal types and core data structures #55264.RecordBatch.from_arraysrestricted to lists and convert tuples vialist(data)insidepa.record_batch().Option 1 provides consistency across both tabular constructors. Does removing the
listrestriction onRecordBatch.from_arraysmatch the intended design?Happy to put together a PR with tests for (1) if that is the preferred direction.
AlenkaF commentedon Nov 9, 2026
My first question, which I haven't investigated yet, is: why is arrays parameter typed to list in Cython, is there a special reason behind that decision? If yes, we can not blindly remove the type restriction there.
No PRs yet, please.
Awesome06 commentedon Nov 9, 2026
I checked the history and implementation of
RecordBatch.from_arraysto see whyarrayswas typed tolistin Cython:There does not appear to be an architectural or safety reason for it, looks to be a historical artifact from 2017.
A few details:
RecordBatch.from_arraysonly checkslen(arrays)andarrays[0]before passing it to_sanitize_arrays(arrays, ...)._sanitize_arraysproduces an internal Python list (converted_arrays), which is then used to populate the C++vector[shared_ptr[CArray]]. The input sequence is never passed directly to C++.Table:Table.from_arrayshas always keptarraysuntyped and accepts tuples without issue.pa.record_batch()was added in ARROW-6263, it was explicitly written asif isinstance(data, (list, tuple)): return RecordBatch.from_arrays(data, ...). Tuples were clearly intended to be supported, but were blocked by the legacy Cython typing.Given that, dropping the
listrestriction onRecordBatch.from_arrays(def from_arrays(arrays, ...)) should be completely safe and aligns it withTable.from_arraysand the typing stubs in #55264.Commit history details
a9747ceac, ARROW-312): BothRecordBatch.from_arraysandTable.from_arrayswere originally untyped (def from_arrays(names, arrays)).7d433dc27, ARROW-483 / PR ARROW-483: [C++/Python] Provide access to "custom_metadata" Field attribute in IPC setting #588):RecordBatch.from_arrayshad Cython types added (def from_arrays(list arrays, list names, dict metadata=None)), whileTable.from_arrayskeptarraysuntyped.ec9b72a23, ARROW-1715):list nameswas relaxed tonamesinRecordBatch.from_arraysto support schemas during unpickling, leavinglist arrays.9da458437, ARROW-2624):dict metadatawas relaxed tometadatato allow arbitrary mappings, leavinglist arrays.05bc63c3b, ARROW-6263):pa.record_batchandpa.tablefactory functions were added withisinstance(data, (list, tuple)).pa.tableworked becauseTable.from_arrayswas untyped, whilepa.record_batchfailed on tuples due to the remaining Cython check.