Skip to content

Commit 1760a86

Browse files
GH-43507: [C++] Use ViewOrCopyTo instead of CopyTo when pretty printing non-CPU data
1 parent d4d92e4 commit 1760a86

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎cpp/src/arrow/pretty_print.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ class ArrayPrinter : public PrettyPrinter {
394394
if (array.device_type() != DeviceAllocationType::kCPU) {
395395
// GH-43055: ideally we only copy start/end slices from non-CPU memory
396396
// based on the window size that is being printed
397-
ARROW_ASSIGN_OR_RAISE(auto array_cpu, array.CopyTo(default_cpu_memory_manager()));
397+
ARROW_ASSIGN_OR_RAISE(auto array_cpu,
398+
array.ViewOrCopyTo(default_cpu_memory_manager()));
398399
RETURN_NOT_OK(VisitArrayInline(*array_cpu, this));
399400
} else {
400401
RETURN_NOT_OK(VisitArrayInline(array, this));

‎python/pyarrow/tests/test_cuda.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,17 @@ def test_print_array():
973973
assert str(carr) == str(arr)
974974

975975

976+
@pytest.mark.parametrize("size", [10, 100])
977+
def test_print_array_host(size):
978+
buf = cuda.new_host_buffer(size*8)
979+
np_arr = np.frombuffer(buf, dtype=np.int64)
980+
np_arr[:] = range(size)
981+
982+
arr = pa.array(range(size), pa.int64())
983+
carr = pa.Array.from_buffers(pa.int64(), size, [None, buf])
984+
assert str(carr) == str(arr)
985+
986+
976987
def make_chunked_array(n_elements_per_chunk, n_chunks):
977988
arrs = []
978989
carrs = []

0 commit comments

Comments
 (0)