Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/pyarrow/_dataset.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ cdef class InMemoryDataset(Dataset):
if isinstance(source, (pa.RecordBatch, pa.Table)):
source = [source]

if isinstance(source, (list, tuple)):
if isinstance(source, (list, tuple, pa.RecordBatchReader)):
batches = []
for item in source:
if isinstance(item, pa.RecordBatch):
Expand All @@ -1036,8 +1036,8 @@ cdef class InMemoryDataset(Dataset):
pyarrow_unwrap_table(table))
else:
raise TypeError(
'Expected a table, batch, or list of tables/batches '
'instead of the given type: ' +
'Expected a Table, RecordBatch, list of Table/RecordBatch, '
'or RecordBatchReader instead of the given type: ' +
type(source).__name__
)

Expand Down
2 changes: 1 addition & 1 deletion python/pyarrow/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ def dataset(source, schema=None, format=None, filesystem=None,
'of batches or tables. The given list contains the following '
f'types: {type_names}'
)
elif isinstance(source, (pa.RecordBatch, pa.Table)):
elif isinstance(source, (pa.RecordBatch, pa.Table, pa.RecordBatchReader)):
return _in_memory_dataset(source, **kwargs)
else:
raise TypeError(
Expand Down
3 changes: 2 additions & 1 deletion python/pyarrow/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2558,13 +2558,14 @@ def test_construct_from_invalid_sources_raise(multisourcefs):

def test_construct_in_memory(dataset_reader):
batch = pa.RecordBatch.from_arrays([pa.array(range(10))], names=["a"])
reader = pa.RecordBatchReader.from_batches(batch.schema, [batch])
table = pa.Table.from_batches([batch])

dataset_table = ds.dataset([], format='ipc', schema=pa.schema([])
).to_table()
assert dataset_table == pa.table([])

for source in (batch, table, [batch], [table]):
for source in (batch, table, [batch], [table], reader):
dataset = ds.dataset(source)
assert dataset_reader.to_table(dataset) == table
assert len(list(dataset.get_fragments())) == 1
Expand Down
Loading