apache / apache/arrow

[Python ] Table.to_batches() loses schema information when table has zero rows

Open
#49,309 6 comments 0 reactions 0 assignees View on GitHub
Component: Python Type: enhancement
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 13h
Merged PRs (30d)
88

Description

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

Calling `to_batches` on a zero-row table returns an empty list, losing the schema information:
```
Python 3.13.5 (main, Jun 12 2025, 08:56:14) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyarrow as pa
>>> pa.__version__
'23.0.1'
>>> table = pa.table({"col": pa.array([], pa.int64())})
>>> table.to_batches()
[]
```
I would expect the result to be a single-element list, containing a `RecordBatch` with zero rows, and the same schema as the original table.

### Component(s)

Python

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.