Skip to content

[Python] table.to_struct_array fails for empty table #46355

@hombit

Description

@hombit

Describe the bug, including details regarding any error messages, version, and platform.

import pyarrow as pa

table = pa.table({"a": pa.array([]), "b": pa.array([], type=pa.float64())})
array = table.to_struct_array()
File ~/.virtualenvs/nested-pandas/lib/python3.13/site-packages/pyarrow/table.pxi:4963, in pyarrow.lib.Table.to_struct_array()

File ~/.virtualenvs/nested-pandas/lib/python3.13/site-packages/pyarrow/table.pxi:1551, in pyarrow.lib.chunked_array()

File ~/.virtualenvs/nested-pandas/lib/python3.13/site-packages/pyarrow/error.pxi:155, in pyarrow.lib.pyarrow_internal_check_status()

File ~/.virtualenvs/nested-pandas/lib/python3.13/site-packages/pyarrow/error.pxi:92, in pyarrow.lib.check_status()

ArrowInvalid: cannot construct ChunkedArray from empty vector and omitted type

I guess it is because zero-chunk case is not covered here:

arrow/python/pyarrow/table.pxi

Lines 4963 to 4966 in 03bdb2a

return chunked_array([
batch.to_struct_array()
for batch in self.to_batches(max_chunksize=max_chunksize)
])

Component(s)

Python

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions