()
| 1190 | |
| 1191 | |
| 1192 | def 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 | |
| 1237 | def test_record_batch_reader_from_arrow_stream(): |
nothing calls this directly
no test coverage detected