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

Function test_string_binary_from_buffers

python/pyarrow/tests/test_array.py:787–819  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

785
786
787def test_string_binary_from_buffers():
788 array = pa.array(["a", None, "b", "c"])
789
790 buffers = array.buffers()
791 copied = pa.StringArray.from_buffers(
792 len(array), buffers[1], buffers[2], buffers[0], array.null_count,
793 array.offset)
794 assert copied.to_pylist() == ["a", None, "b", "c"]
795
796 binary_copy = pa.Array.from_buffers(pa.binary(), len(array),
797 array.buffers(), array.null_count,
798 array.offset)
799 assert binary_copy.to_pylist() == [b"a", None, b"b", b"c"]
800
801 copied = pa.StringArray.from_buffers(
802 len(array), buffers[1], buffers[2], buffers[0])
803 assert copied.to_pylist() == ["a", None, "b", "c"]
804
805 sliced = array[1:]
806 buffers = sliced.buffers()
807 copied = pa.StringArray.from_buffers(
808 len(sliced), buffers[1], buffers[2], buffers[0], -1, sliced.offset)
809 assert copied.to_pylist() == [None, "b", "c"]
810 assert copied.null_count == 1
811
812 # Slice but exclude all null entries so that we don't need to pass
813 # the null bitmap.
814 sliced = array[2:]
815 buffers = sliced.buffers()
816 copied = pa.StringArray.from_buffers(
817 len(sliced), buffers[1], buffers[2], None, -1, sliced.offset)
818 assert copied.to_pylist() == ["b", "c"]
819 assert copied.null_count == 0
820
821
822def test_string_view_from_buffers():

Callers

nothing calls this directly

Calls 3

lenFunction · 0.85
buffersMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected