diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi index bf9a6d67228..27f93c27cbc 100644 --- a/python/pyarrow/array.pxi +++ b/python/pyarrow/array.pxi @@ -4203,9 +4203,9 @@ cdef class StringArray(Array): return cp.PyUnicode_DecodeUTF8(view.data(), view.size(), NULL) @staticmethod - def from_buffers(int length, Buffer value_offsets, Buffer data, - Buffer null_bitmap=None, int null_count=-1, - int offset=0): + def from_buffers(int64_t length, Buffer value_offsets, Buffer data, + Buffer null_bitmap=None, int64_t null_count=-1, + int64_t offset=0): """ Construct a StringArray from value_offsets and data buffers. If there are nulls in the data, also a null_bitmap and the matching @@ -4241,9 +4241,9 @@ cdef class LargeStringArray(Array): return cp.PyUnicode_DecodeUTF8(view.data(), view.size(), NULL) @staticmethod - def from_buffers(int length, Buffer value_offsets, Buffer data, - Buffer null_bitmap=None, int null_count=-1, - int offset=0): + def from_buffers(int64_t length, Buffer value_offsets, Buffer data, + Buffer null_bitmap=None, int64_t null_count=-1, + int64_t offset=0): """ Construct a LargeStringArray from value_offsets and data buffers. If there are nulls in the data, also a null_bitmap and the matching diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py index 74ff837e16e..96d39343880 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -785,27 +785,31 @@ def test_array_from_buffers(): pa.Array.from_buffers(pa.int16(), 3, ['', ''], offset=1) -def test_string_binary_from_buffers(): - array = pa.array(["a", None, "b", "c"]) +@pytest.mark.parametrize("array_factory,string_type,binary_type", [ + (pa.StringArray, pa.string(), pa.binary()), + (pa.LargeStringArray, pa.large_string(), pa.large_binary()), +]) +def test_string_binary_from_buffers(array_factory, string_type, binary_type): + array = pa.array(["a", None, "b", "c"], type=string_type) buffers = array.buffers() - copied = pa.StringArray.from_buffers( + copied = array_factory.from_buffers( len(array), buffers[1], buffers[2], buffers[0], array.null_count, array.offset) assert copied.to_pylist() == ["a", None, "b", "c"] - binary_copy = pa.Array.from_buffers(pa.binary(), len(array), + binary_copy = pa.Array.from_buffers(binary_type, len(array), array.buffers(), array.null_count, array.offset) assert binary_copy.to_pylist() == [b"a", None, b"b", b"c"] - copied = pa.StringArray.from_buffers( + copied = array_factory.from_buffers( len(array), buffers[1], buffers[2], buffers[0]) assert copied.to_pylist() == ["a", None, "b", "c"] sliced = array[1:] buffers = sliced.buffers() - copied = pa.StringArray.from_buffers( + copied = array_factory.from_buffers( len(sliced), buffers[1], buffers[2], buffers[0], -1, sliced.offset) assert copied.to_pylist() == [None, "b", "c"] assert copied.null_count == 1 @@ -814,12 +818,65 @@ def test_string_binary_from_buffers(): # the null bitmap. sliced = array[2:] buffers = sliced.buffers() - copied = pa.StringArray.from_buffers( + copied = array_factory.from_buffers( len(sliced), buffers[1], buffers[2], None, -1, sliced.offset) assert copied.to_pylist() == ["b", "c"] assert copied.null_count == 0 +@pytest.mark.large_memory +@pytest.mark.skipif( + sys.maxsize <= 2**31, reason="Requires a 64-bit address space", +) +@pytest.mark.parametrize("array_factory,string_type,offset_format", [ + (pa.StringArray, pa.string(), "