Commits


Kevin Gurney authored and GitHub committed 05fe0d25834
GH-35598: [MATLAB] Add a public `Valid` property to to the `MATLAB arrow.array.<Array>` classes to query Null values (i.e. validity bitmap support) (#35655) ### Rationale for this change Currently, the `arrow.array.<Array>` classes do not support querying the Null values (i.e. validity bitmap) on an Arrow array. Support for encoding Null values is an important part of the Arrow memory format, so the MATLAB Interface to Arrow should support it. There are likely multiple different APIs that the MATLAB interface should have to support Null values robustly. However, to focus on incremental delivery, we can start by adding a public `Valid` property to the `arrow.array.<Array>` classes, which would return a `logical` array of null values in the given array. ### What changes are included in this PR? 1. Added a new public property `Valid` to the `arrow.array.Array` superclass. 2. Implemented basic null value handling for `arrow.array.Float64Array` (i.e. treat `NaN` values in the input MATLAB array as null values in the corresponding `arrow.array.Float64Array`). 3. Implement null value substitution (i.e. substitute null values with `NaN`) for `Float64Array` in `toMATLAB` and `double` conversion methods. Example of creating an `arrow.array.Float64Array` from a MATLAB `double` array containing `NaN` values: ```matlab >> matlabArray = [1, 2, NaN, 4, NaN]' matlabArray = 1 2 NaN 4 NaN >> arrowArray = arrow.array.Float64Array(matlabArray) arrowArray = [ 1, 2, null, 4, null ] >> arrowArray.Valid ans = 5×1 logical array 1 1 0 1 0 >> all(~isnan(matlabArray) == arrowArray.Valid) ans = logical 1 ``` ### Are these changes tested? Yes, we have added the following test points for the `Valid` property of `arrow.array.Float64Array`: 1. `ValidBasic` 2. `ValidNoNulls` 4. `ValidAllNulls` 5. `ValidEmpty` ### Are there any user-facing changes? Yes. There is now a public property `Valid` on the arrow.array.Float64Array` class which is a MATLAB `logical` array encoding the null values in the underlying Arrow array, where `true` indicates an element is valid (i.e. not null) and `false` indicates that an element is invalid (i.e. null). ### Future Directions 1. Implement more null value related methods like `isvalid`, `isnull`, `packagedValidityBitmap`, etc. 2. Add null value (i.e. `Valid` property) support to the rest of the `arrow.array.Array` subclasses. ### Notes 1. Thank you to @ sgilmore10 for your help with this pull request! Lead-authored-by: Kevin Gurney <kgurney@mathworks.com> Co-authored-by: sgilmore10 <74676073+sgilmore10@users.noreply.github.com> Co-authored-by: Kevin Gurney <kevin.p.gurney@gmail.com> Co-authored-by: Sarah Gilmore <sgilmore@mathworks.com> Co-authored-by: Sutou Kouhei <kou@cozmixng.org> Signed-off-by: Sutou Kouhei <kou@clear-code.com>