Skip to content

bugfix: no panic on empty table#613

Merged
andygrove merged 1 commit into
apache:mainfrom
mesejo:bugfix/panic-empty-table
Apr 13, 2024
Merged

bugfix: no panic on empty table#613
andygrove merged 1 commit into
apache:mainfrom
mesejo:bugfix/panic-empty-table

Conversation

@mesejo

@mesejo mesejo commented Mar 22, 2024

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #575 .

@andygrove andygrove left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @mesejo

@andygrove
andygrove merged commit 7204a35 into apache:main Apr 13, 2024
fangchenli added a commit to fangchenli/datafusion-python that referenced this pull request Jul 11, 2026
`register_record_batches` read the schema via unchecked `partitions.0[0][0]`,
which panics when a partition contains no record batches (e.g. the batches of
an empty pyarrow table, whose `to_batches()` returns `[]`).

Take the schema from the first available batch across all partitions and return
a clear error when there is none, mirroring the empty-table handling added for
`from_arrow_table` in apache#613. A non-empty later partition now also works instead
of panicking on an empty leading one.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
kosiew pushed a commit that referenced this pull request Jul 14, 2026
* fix: no panic on empty partition in register_record_batches

`register_record_batches` read the schema via unchecked `partitions.0[0][0]`,
which panics when a partition contains no record batches (e.g. the batches of
an empty pyarrow table, whose `to_batches()` returns `[]`).

Take the schema from the first available batch across all partitions and return
a clear error when there is none, mirroring the empty-table handling added for
`from_arrow_table` in #613. A non-empty later partition now also works instead
of panicking on an empty leading one.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* refactor: address review feedback

- Use find_map(|p| p.first()) instead of flatten().next() to make the
  "first batch in any partition" intent clearer (per @kosiew).
- Extend regression test to also assert the empty outer partition list
  case ([]) raises the same ValueError.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic when reading empty pyarrow.Table

2 participants