From 8ac0443fa18e2caed1bea9240a54ea1504372a05 Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Tue, 24 Oct 2023 11:38:02 -0400 Subject: [PATCH] 1. Add test for ListArray display 2. Remove extra indentation applied to list and struct arrays --- .../src/cpp/arrow/matlab/array/proxy/array.cc | 3 +- matlab/src/matlab/+arrow/+array/Array.m | 2 +- matlab/test/arrow/array/tArrayDisplay.m | 34 ++++++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/matlab/src/cpp/arrow/matlab/array/proxy/array.cc b/matlab/src/cpp/arrow/matlab/array/proxy/array.cc index a9bdee43d032a..4e52c990d3eae 100644 --- a/matlab/src/cpp/arrow/matlab/array/proxy/array.cc +++ b/matlab/src/cpp/arrow/matlab/array/proxy/array.cc @@ -71,7 +71,8 @@ namespace arrow::matlab::array::proxy { std::stringstream ss; MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(arrow::PrettyPrint(*array, opts, &ss), context, error::ARRAY_PRETTY_PRINT_FAILED); - const auto str_utf8 = ss.str(); + const auto str_utf8 = opts.skip_new_lines ? " " + ss.str() : ss.str(); + MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(const auto str_utf16, arrow::util::UTF8StringToUTF16(str_utf8), context, error::UNICODE_CONVERSION_ERROR_ID); auto str_mda = factory.createScalar(str_utf16); context.outputs[0] = str_mda; diff --git a/matlab/src/matlab/+arrow/+array/Array.m b/matlab/src/matlab/+arrow/+array/Array.m index 4d356105e8181..293ad87ad4316 100644 --- a/matlab/src/matlab/+arrow/+array/Array.m +++ b/matlab/src/matlab/+arrow/+array/Array.m @@ -75,7 +75,7 @@ function displayScalarObject(obj) disp(getHeader(obj)); if obj.NumElements > 0 - disp(" " + toString(obj) + newline); + disp(toString(obj) + newline); end end end diff --git a/matlab/test/arrow/array/tArrayDisplay.m b/matlab/test/arrow/array/tArrayDisplay.m index 4e4721fa1b196..eb61a6906e171 100644 --- a/matlab/test/arrow/array/tArrayDisplay.m +++ b/matlab/test/arrow/array/tArrayDisplay.m @@ -273,7 +273,7 @@ function DisplayStructArray(testCase) header = compose(" %s with %s elements and %s null values:" + newline, ... classNameLink, numElementString, numNullString); - body = " -- is_valid: all not null" + newline + ... + body = " -- is_valid: all not null" + newline + ... " -- child 0 type: double" + newline + ... " [" + newline + ... " 1," + newline + ... @@ -289,6 +289,38 @@ function DisplayStructArray(testCase) testCase.verifyEqual(actualDisplay, expectedDisplay); end + function DisplayListArray(testCase) + import arrow.internal.test.display.makeLinkString + + Offsets = arrow.array(int32([0, 2, 3])); + Values = arrow.array([1, 2, 3]); + + listArray = arrow.array.ListArray.fromArrays(Offsets, Values); %#ok + + classNameLink = makeLinkString(FullClassName="arrow.array.ListArray", ... + ClassName="ListArray", ... + BoldFont=true); + + numElementString = getNumString(2); + numNullString = getNumString(0); + header = compose(" %s with %s elements and %s null values:" + newline, ... + classNameLink, numElementString, numNullString); + + body = " [" + newline + ... + " [" + newline + ... + " 1," + newline + ... + " 2" + newline + ... + " ]," + newline + ... + " [" + newline + ... + " 3" + newline + ... + " ]" + newline + ... + " ]" + newline + newline; + + expectedDisplay = char(strjoin([header body], newline)); + actualDisplay = evalc('disp(listArray)'); + testCase.verifyEqual(actualDisplay, expectedDisplay); + end + end end