Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MATLAB] Add Valid as a name-value pair on the arrow.array.Float64Array constructor #35693

Closed
kevingurney opened this issue May 19, 2023 · 3 comments · Fixed by #35977
Closed

Comments

@kevingurney
Copy link
Member

kevingurney commented May 19, 2023

Describe the enhancement requested

This is a follow up to #35676 and #35598 .

To allow users to clearly specify which values in an input MATLAB array should be treated as null values when constructing an arrow.array.Array, it would be helpful to add a Valid name-value pair.

This name-value pair would correspond to the public Valid property which encodes the validity bitmap (i.e. null values) in an arrow.array.Array (proposed in #35598).

Adding this name-value pair would provide clients with a way to unambiguously control null value handling behavior when constructing arrow.array.Array objects.

Example:

>> matlabArray = double([1, -1, -1, 3, 4, 5])'

matlabArray =

     1
    -1
    -1
     4
     5

>> A = arrow.array.Float64Array(matlabArray, Valid=logical([true false, false, true, true])) 

A = 

[
  1,
  null,
  null,
  4,
  5
]

Component(s)

MATLAB

@kevingurney kevingurney changed the title [MATLAB] Add Valid as a name-value pair on the arrow.array.Array superclass constructor [MATLAB] Add Valid as a name-value pair on the arrow.array.Float64Array constructor Jun 7, 2023
kou added a commit that referenced this issue Jun 10, 2023
…ay.Float64Array` constructor (#35977)

### Rationale for this change
Users should be able to specify exactly which elements in a MATLAB array should be treated as `null` values. In a previous PR, we added the name-value pair `InferNulls` which users can use to turn off the automatic "null detection" of values for which the MATLAB `ismissing` function returns true:

```MATLAB
>> matlabArray = [1 NaN 3];

% NaN is treated as null by default
>> arrowArray = arrow.array.Float64Array(matlabArray);

arrowArray = 

[
  1,
  null,
  3
]

% Don't treat NaN as a null value
>> arrowArray = arrow.array.Float64Array(matlabArray, InferNulls=false);

arrowArray = 

[
  1,
  nan,
  3
]
``` 

To provide more control, this PR adds a new name-value pair named `Valid`. This name-value pair will take precedence over `InferNulls` and allows users to specify which elements are valid using either a logical array or a list of indices:

```MATLAB
>> matlabArray = [1 NaN 3];

>> arrowArray = arrow.array.Float64Array(matlabArray, Valid=[true true false]);

arrowArray = 

[
  1,
  nan,
  null
]

>> arrowArray = arrow.array.Float64Array(matlabArray, Valid=[2 3]);

arrowArray = 

[
  null,
  nan,
  3
]

``` 

### What changes are included in this PR?

1. Added the `Valid` name-value pair to `arrow.array.Float64Array`.

### Are these changes tested?

1. Added a new test file called `tParseValidElements.m` to independently test the helper function `arrow.args.parseValidElements` used by `arrow.array.Float64Array`.
2. Added two integration tests in `tFloat64Array.m`.

### Are there any user-facing changes?
Yes, users can now pass the `Valid` name-value pair to `arrow.array.Float64Array`.

### Future Directions

1. Currently, only `arrow.array.Float64Array` supports the `InferNulls` and `Valid` name-value pairs. In a followup PR, we will add support for these name-value pairs to the rest of the numeric array classes. 

* Closes: #35693

Lead-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Co-authored-by: sgilmore10 <74676073+sgilmore10@users.noreply.github.com>
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
@kou kou added this to the 13.0.0 milestone Jun 10, 2023
@kou
Copy link
Member

kou commented Jun 10, 2023

@sgilmore10 Could you add a take only comment here to assign you to this issue?

@sgilmore10
Copy link
Member

Will do!

@sgilmore10
Copy link
Member

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants