Skip to content

Commit f3a3fcc

Browse files
fangchenliclaude
andcommitted
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>
1 parent 255d968 commit f3a3fcc

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

crates/core/src/context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,7 @@ impl PySessionContext {
837837
let schema = partitions
838838
.0
839839
.iter()
840-
.flatten()
841-
.next()
840+
.find_map(|partition| partition.first())
842841
.ok_or_else(|| {
843842
PyValueError::new_err(
844843
"Cannot register record batches without a schema: the \

python/tests/test_context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ def test_register_record_batches_empty(ctx):
122122
with pytest.raises(ValueError, match="no record batches"):
123123
ctx.register_record_batches("t", [[]])
124124

125+
# An empty outer partition list carries no schema either, and raises the same error.
126+
with pytest.raises(ValueError, match="no record batches"):
127+
ctx.register_record_batches("t", [])
128+
125129
# The schema is still recovered from a later non-empty partition.
126130
batch = pa.RecordBatch.from_arrays([pa.array([1, 2, 3])], names=["a"])
127131
ctx.register_record_batches("t2", [[], [batch]])

0 commit comments

Comments
 (0)