forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apacheGH-38398: [MATLAB] Improve array display (apache#38400)
### Rationale for this change Currently, the display for `arrow.array.Array`s is not very MATLAB-like: ```matlab >> a = arrow.array([1 2 3 4]) a = [ 1, 2, 3, ] ``` At the very least, the display should include the class header and indent each line by 4 spaces. Here's one display option: ```matlab >> a = arrow.array([1 2 3 4]) a = Float64Array with 4 elements and 0 null values: 1 | 2 | 3 | 4 ``` ### What changes are included in this PR? 1. Array display now includes a class header, which states the array type and the number of elements/nulls in the array. 2. Changed the [`window`](https://github.com/apache/arrow/blob/37935604bf168a3b2d52f3cc5b0edf83b5783309/cpp/src/arrow/pretty_print.h#L79C1-L80C1) size to 3 from 10. 3. Primitive and string arrays are displayed horizontally, i.e. set [`skip_new_lines`](https://github.com/apache/arrow/blob/37935604bf168a3b2d52f3cc5b0edf83b5783309/cpp/src/arrow/pretty_print.h#L90) to `false`. Uses ` | ` as the delimiter between elements with no opening/closing brackets. 4. All other array types (`struct`, `list`, etc) are displayed vertically with an `indent` of 4. **Example String Array Display:** ```matlab >> a = arrow.array(["Hello", missing, "Bye"]) a = StringArray with 3 elements and 1 null value: "Hello" | null | "Bye" ``` **Example Struct Array Display:** ```matlab >> a1 = arrow.array(["Hello", missing, "Bye"]); >> a2 = arrow.array([1 2 3]); >> structArray = arrow.array.StructArray.fromArrays(a1, a2) structArray = StructArray with 3 elements and 0 null values: -- is_valid: all not null -- child 0 type: string [ "Hello", null, "Bye" ] -- child 1 type: double [ 1, 2, 3 ] ``` ### Are these changes tested? Yes. Added a new test class called `tArrayDisplay.m` with unit tests for array display. ### Are there any user-facing changes? Yes. Users will see a different display for arrays now. ### Future Directions 1. apache#38166 * Closes: apache#38398 Lead-authored-by: Sarah Gilmore <[email protected]> Co-authored-by: sgilmore10 <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Kevin Gurney <[email protected]>
- Loading branch information
1 parent
006f387
commit e14f60b
Showing
6 changed files
with
439 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
matlab/src/matlab/+arrow/+array/+internal/+display/getHeader.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
%GETHEADER Generates the display header for arrow.array.Array classes | ||
|
||
% Licensed to the Apache Software Foundation (ASF) under one or more | ||
% contributor license agreements. See the NOTICE file distributed with | ||
% this work for additional information regarding copyright ownership. | ||
% The ASF licenses this file to you under the Apache License, Version | ||
% 2.0 (the "License"); you may not use this file except in compliance | ||
% with the License. You may obtain a copy of the License at | ||
% | ||
% http://www.apache.org/licenses/LICENSE-2.0 | ||
% | ||
% Unless required by applicable law or agreed to in writing, software | ||
% distributed under the License is distributed on an "AS IS" BASIS, | ||
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
% implied. See the License for the specific language governing | ||
% permissions and limitations under the License. | ||
|
||
function header = getHeader(className, numElements, numNulls) | ||
import arrow.array.internal.display.pluralizeStringIfNeeded | ||
elementString = pluralizeStringIfNeeded(numElements, "element"); | ||
|
||
nullString = pluralizeStringIfNeeded(numNulls, "null value"); | ||
|
||
numString = "%d"; | ||
if usejava("desktop") | ||
% Bold the number of elements and nulls if the desktop is enabled | ||
numString = compose("<strong>%s</strong>", numString); | ||
end | ||
|
||
formatSpec = " %s with " + numString + " %s and " + numString + " %s"; | ||
if numElements > 0 | ||
formatSpec = formatSpec + ":"; | ||
end | ||
formatSpec = formatSpec + newline; | ||
|
||
header = compose(formatSpec, className, numElements, elementString, numNulls, nullString); | ||
header = char(header); | ||
end |
23 changes: 23 additions & 0 deletions
23
matlab/src/matlab/+arrow/+array/+internal/+display/pluralizeStringIfNeeded.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
%PLURALIZESTRINGIFNEEDED Pluralizes str if num is not equal to 1. | ||
|
||
% Licensed to the Apache Software Foundation (ASF) under one or more | ||
% contributor license agreements. See the NOTICE file distributed with | ||
% this work for additional information regarding copyright ownership. | ||
% The ASF licenses this file to you under the Apache License, Version | ||
% 2.0 (the "License"); you may not use this file except in compliance | ||
% with the License. You may obtain a copy of the License at | ||
% | ||
% http://www.apache.org/licenses/LICENSE-2.0 | ||
% | ||
% Unless required by applicable law or agreed to in writing, software | ||
% distributed under the License is distributed on an "AS IS" BASIS, | ||
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
% implied. See the License for the specific language governing | ||
% permissions and limitations under the License. | ||
|
||
function str = pluralizeStringIfNeeded(num, str) | ||
if num ~= 1 | ||
str = str + "s"; | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.