Skip to content

Commit 61d0739

Browse files
committed
test: add missing file error handling for arrow C stream reader
1 parent 8c0bfc0 commit 61d0739

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

python/tests/test_stream_error.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pyarrow as pa
2+
import pytest
3+
4+
5+
def test_arrow_c_stream_missing_file(ctx, tmp_path):
6+
schema = pa.schema([("a", pa.int64())])
7+
path = tmp_path / "missing.csv"
8+
path.write_text("a\n1\n2\n")
9+
df = ctx.read_csv(path, schema=schema)
10+
capsule = df.__arrow_c_stream__()
11+
path.unlink()
12+
reader = pa.RecordBatchReader._import_from_c_capsule(capsule)
13+
with pytest.raises(Exception): # noqa: B017
14+
reader.read_all()

src/dataframe.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,12 @@ impl Iterator for PartitionedDataFrameStreamReader {
410410
continue;
411411
}
412412
Err(e) => {
413+
#[cfg(debug_assertions)]
414+
{
415+
log::error!("PartitionedDataFrameStreamReader stream error: {e}");
416+
}
417+
// Stop iteration on error to avoid use-after-free.
418+
self.current = self.streams.len();
413419
return Some(Err(ArrowError::ExternalError(Box::new(e))));
414420
}
415421
}

0 commit comments

Comments
 (0)