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

Function test_table_c_stream_interface

python/pyarrow/tests/test_table.py:620–656  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

618
619
620def test_table_c_stream_interface():
621 class StreamWrapper:
622 def __init__(self, batches):
623 self.batches = batches
624
625 def __arrow_c_stream__(self, requested_schema=None):
626 reader = pa.RecordBatchReader.from_batches(
627 self.batches[0].schema, self.batches)
628 return reader.__arrow_c_stream__(requested_schema)
629
630 data = [
631 pa.record_batch([pa.array([1, 2, 3], type=pa.int64())], names=['a']),
632 pa.record_batch([pa.array([4, 5, 6], type=pa.int64())], names=['a'])
633 ]
634 wrapper = StreamWrapper(data)
635
636 # Can roundtrip through the wrapper.
637 result = pa.table(wrapper)
638 expected = pa.Table.from_batches(data)
639 assert result == expected
640
641 # Passing schema works if already that schema
642 result = pa.table(wrapper, schema=data[0].schema)
643 assert result == expected
644
645 # Passing a different schema will cast
646 good_schema = pa.schema([pa.field('a', pa.int32())])
647 result = pa.table(wrapper, schema=good_schema)
648 assert result == expected.cast(good_schema)
649
650 # If schema doesn't match, raises NotImplementedError
651 with pytest.raises(
652 pa.lib.ArrowTypeError, match="Field 0 cannot be cast"
653 ):
654 pa.table(
655 wrapper, schema=pa.schema([pa.field('a', pa.list_(pa.int32()))])
656 )
657
658
659def test_recordbatch_itercolumns():

Callers

nothing calls this directly

Calls 5

StreamWrapperClass · 0.70
arrayMethod · 0.45
schemaMethod · 0.45
fieldMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected