MCPcopy Create free account
hub / github.com/apache/arrow / test_py_record_batch_reader

Function test_py_record_batch_reader

python/pyarrow/tests/test_ipc.py:1192–1234  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1190
1191
1192def test_py_record_batch_reader():
1193 def make_schema():
1194 return pa.schema([('field', pa.int64())])
1195
1196 def make_batches():
1197 schema = make_schema()
1198 batch1 = pa.record_batch([[1, 2, 3]], schema=schema)
1199 batch2 = pa.record_batch([[4, 5]], schema=schema)
1200 return [batch1, batch2]
1201
1202 # With iterable
1203 batches = UserList(make_batches()) # weakrefable
1204 wr = weakref.ref(batches)
1205
1206 with pa.RecordBatchReader.from_batches(make_schema(),
1207 batches) as reader:
1208 batches = None
1209 assert wr() is not None
1210 assert list(reader) == make_batches()
1211 assert wr() is None
1212
1213 # With iterator
1214 batches = iter(UserList(make_batches())) # weakrefable
1215 wr = weakref.ref(batches)
1216
1217 with pa.RecordBatchReader.from_batches(make_schema(),
1218 batches) as reader:
1219 batches = None
1220 assert wr() is not None
1221 assert list(reader) == make_batches()
1222 assert wr() is None
1223
1224 # ensure we get proper error when not passing a schema
1225 # (https://issues.apache.org/jira/browse/ARROW-18229)
1226 batches = make_batches()
1227 with pytest.raises(TypeError):
1228 reader = pa.RecordBatchReader.from_batches(
1229 [('field', pa.int64())], batches)
1230 pass
1231
1232 with pytest.raises(TypeError):
1233 reader = pa.RecordBatchReader.from_batches(None, batches)
1234 pass
1235
1236
1237def test_record_batch_reader_from_arrow_stream():

Callers

nothing calls this directly

Calls 3

listFunction · 0.85
make_batchesFunction · 0.70
make_schemaFunction · 0.70

Tested by

no test coverage detected