-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-35676: [MATLAB] Add an
InferNulls
name-value pair for controllin…
…g null value inference during construction of `arrow.array.Array` (#35827) ### Rationale for this change This change lets users control toggle the automatic null-value detection behavior. By default, values MATLAB considers to be missing (e.g. `NaN` for `double`, `<missing>` for `string`, and `NaT` for `datetime`) will be treated as `null` values. Users can toggle this behavior on and off using the `InferNulls` name-value pair. **Example** ```matlab >> matlabArray = [1 NaN 3]' matlabArray = 1 NaN 3 % Treat NaN as a null value >> arrowArray1 = arrow.array.Float64Array(maltabArray, InferNulls=true) arrowArray1 = [ 1, null, 3 ] % Don't treat NaN as a null value >> arrowArray2 = arrow.array.Float64Array(maltabArray, InferNulls=false) arrowArray2 = [ 1, nan, 3 ] ``` We've only added this nv-pair to `arrow.array.Float64Array` for now. We'll add this nv-pair to the other types in a followup changelist. ### What changes are included in this PR? 1. Added `InferNulls` name-value pair to `arrow.array.Float64Array`. 2. Added common validation function `arrow.args.validateTypeAndShape` to remove duplicate validation code among the numeric classes. 3. Added a function called `arrow.args.parseValidElements` that the `arrow.array.<Type>Array` classes will be able to share for generating the logical mask of valid elements. ### Are these changes tested? Yes, we added a test pointed called `InferNulls` to the test class`tFloat64Array.m`. ### Are there any user-facing changes? Yes, users can now control how `NaN` values are treated when creating an `arrow.array.Float64Array`. ### Future Directions 1. Add a name-value pair to allow users to specify the valid elements themselves. 2. Extend null support to other numeric types. 3. We've been working on adding error-handling support to `mathworks/libmexclass`. We have a prototype to do this using status-like and result-like objects already pushed to a [branch](https://github.com/mathworks/libmexclass/tree/33). Once this branch is merged with the `main` branch of `mathworks/libmexclass`, we'll port it over. ### Notes Thank you @ kevingurney for all the help with this PR! * Closes: #35676 Lead-authored-by: Sarah Gilmore <sgilmore@mathworks.com> Co-authored-by: Kevin Gurney <kgurney@mathworks.com> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
- Loading branch information
1 parent
8878fc8
commit f44f768
Showing
14 changed files
with
102 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
% 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 validElements = parseValidElements(data, inferNulls) | ||
% Returns a logical vector of the validElements in data. If inferNulls | ||
% is true, calls ismissing on data to determine which elements are | ||
% null. | ||
|
||
if inferNulls | ||
% TODO: consider making validElements empty if everything is valid. | ||
validElements = ~ismissing(data); | ||
else | ||
% TODO: consider making this an empty array if everything is valid | ||
validElements = true([numel(data) 1]); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
% 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 validateTypeAndShape(data, type) | ||
% Validates data has the expected type and is a vector or empty 2D | ||
% matrix. If data is numeric, validates is real and nonsparse. | ||
|
||
arguments | ||
data | ||
type(1, 1) string | ||
end | ||
|
||
% If data is empty, only require it's shape to be 2D to support 0x0 | ||
% arrays. Otherwise, require data to be a vector. | ||
% | ||
% TODO: Consider supporting nonvector 2D arrays. We chould reshape them | ||
% to column vectors if needed. | ||
|
||
expectedShape = "vector"; | ||
if isempty(data) | ||
expectedShape = "2d"; | ||
end | ||
validateattributes(data, type, [expectedShape, "nonsparse", "real"]); | ||
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
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
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
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
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
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
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