kevingurney commented on code in PR #37998:
URL: https://github.com/apache/arrow/pull/37998#discussion_r1344627052
##########
matlab/test/arrow/array/tStructArray.m:
##########
@@ -273,5 +273,91 @@ function IsEqualFalse(tc)
tc.verifyFalse(isequal(array1, array3));
end
+ function FromMATLABBasic(tc)
+ % Verify StructArray.fromMATLAB returns the expected
+ % StructArray.
+ import arrow.array.StructArray
+
+ T = table([1 2]', ["A1" "A2"]', VariableNames=["Number" "String"]);
+ array = StructArray.fromMATLAB(T);
+ tc.verifyEqual(array.Length, int64(2));
+ tc.verifyEqual(array.NumFields, int32(2));
+ tc.verifyEqual(array.FieldNames, ["Number" "String"]);
+
+ field1 = arrow.array([1 2]');
+ field2 = arrow.array(["A1" "A2"]');
+
+ tc.verifyEqual(field1, array.field(1));
+ tc.verifyEqual(field2, array.field(2));
+ end
+
+ function FromMATLABFieldNames(tc)
+ % Verify StructArray.fromMATLAB returns the expected
+ % StructArray when the FieldNames nv-pair is supplied.
+ import arrow.array.StructArray
+
+ T = table([1 2]', ["A1" "A2"]', VariableNames=["Number" "String"]);
+ array = StructArray.fromMATLAB(T, FieldNames=["Custom" "Name"]);
+ tc.verifyEqual(array.Length, int64(2));
+ tc.verifyEqual(array.NumFields, int32(2));
+ tc.verifyEqual(array.FieldNames, ["Custom" "Name"]);
+ tc.verifyEqual(array.Valid, [true; true]);
+
+ field1 = arrow.array([1 2]');
+ field2 = arrow.array(["A1" "A2"]');
+
+ tc.verifyEqual(field1, array.field(1));
+ tc.verifyEqual(field2, array.field(2));
+ end
+
+ function FromMATLABValid(tc)
+ % Verify StructArray.fromMATLAB returns the expected
+ % StructArray when the Valid nv-pair is supplied.
+
+ import arrow.array.StructArray
+
+ T = table([1 2]', ["A1" "A2"]', VariableNames=["Number" "String"]);
+ array = StructArray.fromMATLAB(T, Valid=2);
+ tc.verifyEqual(array.Length, int64(2));
+ tc.verifyEqual(array.NumFields, int32(2));
+ tc.verifyEqual(array.FieldNames, ["Number" "String"]);
+ tc.verifyEqual(array.Valid, [false; true]);
+
+ field1 = arrow.array([1 2]');
+ field2 = arrow.array(["A1" "A2"]');
+
+ tc.verifyEqual(field1, array.field(1));
+ tc.verifyEqual(field2, array.field(2));
+ end
+
+ function FromMATLABZeroVariablesError(tc)
+ % Verify StructArray.fromMATLAB throws an error when the input
+ % table T has zero variables.
+ import arrow.array.StructArray
+
+ fcn = @() StructArray.fromMATLAB(table);
+ tc.verifyError(fcn, "arrow:struct:ZeroVariables");
+ end
+
+ function FromMATLABZeroWrongNumberFieldNames(tc)
+ % Verify StructArray.fromMATLAB throws an error when the
+ % FieldNames nv-pair is provided and its number of elements
+ % does not equal the number of variables in the input table T.
+
+ import arrow.array.StructArray
+
+ fcn = @() StructArray.fromMATLAB(table(1), FieldNames=["A" "B"]);
+ tc.verifyError(fcn, "arrow:tabular:WrongNumberColumnNames");
+ end
+
+ function FromMATLABValidBadIndex(tc)
Review Comment:
Maybe we could rename this to `FromMATLABValidNVPairBadIndex`. `ValidBad`
sounds a bit confusing.
##########
matlab/test/arrow/array/tStructArray.m:
##########
@@ -273,5 +273,91 @@ function IsEqualFalse(tc)
tc.verifyFalse(isequal(array1, array3));
end
+ function FromMATLABBasic(tc)
+ % Verify StructArray.fromMATLAB returns the expected
+ % StructArray.
+ import arrow.array.StructArray
+
+ T = table([1 2]', ["A1" "A2"]', VariableNames=["Number" "String"]);
+ array = StructArray.fromMATLAB(T);
+ tc.verifyEqual(array.Length, int64(2));
+ tc.verifyEqual(array.NumFields, int32(2));
+ tc.verifyEqual(array.FieldNames, ["Number" "String"]);
+
+ field1 = arrow.array([1 2]');
+ field2 = arrow.array(["A1" "A2"]');
+
+ tc.verifyEqual(field1, array.field(1));
+ tc.verifyEqual(field2, array.field(2));
+ end
+
+ function FromMATLABFieldNames(tc)
+ % Verify StructArray.fromMATLAB returns the expected
+ % StructArray when the FieldNames nv-pair is supplied.
+ import arrow.array.StructArray
+
+ T = table([1 2]', ["A1" "A2"]', VariableNames=["Number" "String"]);
+ array = StructArray.fromMATLAB(T, FieldNames=["Custom" "Name"]);
+ tc.verifyEqual(array.Length, int64(2));
+ tc.verifyEqual(array.NumFields, int32(2));
+ tc.verifyEqual(array.FieldNames, ["Custom" "Name"]);
+ tc.verifyEqual(array.Valid, [true; true]);
+
+ field1 = arrow.array([1 2]');
+ field2 = arrow.array(["A1" "A2"]');
+
+ tc.verifyEqual(field1, array.field(1));
+ tc.verifyEqual(field2, array.field(2));
+ end
+
+ function FromMATLABValid(tc)
+ % Verify StructArray.fromMATLAB returns the expected
+ % StructArray when the Valid nv-pair is supplied.
+
+ import arrow.array.StructArray
+
+ T = table([1 2]', ["A1" "A2"]', VariableNames=["Number" "String"]);
+ array = StructArray.fromMATLAB(T, Valid=2);
+ tc.verifyEqual(array.Length, int64(2));
+ tc.verifyEqual(array.NumFields, int32(2));
+ tc.verifyEqual(array.FieldNames, ["Number" "String"]);
+ tc.verifyEqual(array.Valid, [false; true]);
+
+ field1 = arrow.array([1 2]');
+ field2 = arrow.array(["A1" "A2"]');
+
+ tc.verifyEqual(field1, array.field(1));
+ tc.verifyEqual(field2, array.field(2));
+ end
+
+ function FromMATLABZeroVariablesError(tc)
+ % Verify StructArray.fromMATLAB throws an error when the input
+ % table T has zero variables.
+ import arrow.array.StructArray
+
+ fcn = @() StructArray.fromMATLAB(table);
+ tc.verifyError(fcn, "arrow:struct:ZeroVariables");
+ end
+
+ function FromMATLABZeroWrongNumberFieldNames(tc)
+ % Verify StructArray.fromMATLAB throws an error when the
+ % FieldNames nv-pair is provided and its number of elements
+ % does not equal the number of variables in the input table T.
+
+ import arrow.array.StructArray
+
+ fcn = @() StructArray.fromMATLAB(table(1), FieldNames=["A" "B"]);
+ tc.verifyError(fcn, "arrow:tabular:WrongNumberColumnNames");
+ end
+
+ function FromMATLABValidBadIndex(tc)
+ % Verify StructArray.fromMATLAB throws an error when the
+ % Valid nv-pair is provided and its contains an invalid index.
Review Comment:
its contains -> it contains
##########
matlab/test/arrow/array/tStructArray.m:
##########
@@ -273,5 +273,91 @@ function IsEqualFalse(tc)
tc.verifyFalse(isequal(array1, array3));
end
+ function FromMATLABBasic(tc)
+ % Verify StructArray.fromMATLAB returns the expected
+ % StructArray.
+ import arrow.array.StructArray
+
+ T = table([1 2]', ["A1" "A2"]', VariableNames=["Number" "String"]);
+ array = StructArray.fromMATLAB(T);
+ tc.verifyEqual(array.Length, int64(2));
+ tc.verifyEqual(array.NumFields, int32(2));
+ tc.verifyEqual(array.FieldNames, ["Number" "String"]);
+
+ field1 = arrow.array([1 2]');
+ field2 = arrow.array(["A1" "A2"]');
+
+ tc.verifyEqual(field1, array.field(1));
+ tc.verifyEqual(field2, array.field(2));
+ end
+
+ function FromMATLABFieldNames(tc)
+ % Verify StructArray.fromMATLAB returns the expected
+ % StructArray when the FieldNames nv-pair is supplied.
+ import arrow.array.StructArray
+
+ T = table([1 2]', ["A1" "A2"]', VariableNames=["Number" "String"]);
+ array = StructArray.fromMATLAB(T, FieldNames=["Custom" "Name"]);
+ tc.verifyEqual(array.Length, int64(2));
+ tc.verifyEqual(array.NumFields, int32(2));
+ tc.verifyEqual(array.FieldNames, ["Custom" "Name"]);
+ tc.verifyEqual(array.Valid, [true; true]);
+
+ field1 = arrow.array([1 2]');
+ field2 = arrow.array(["A1" "A2"]');
+
+ tc.verifyEqual(field1, array.field(1));
+ tc.verifyEqual(field2, array.field(2));
+ end
+
+ function FromMATLABValid(tc)
+ % Verify StructArray.fromMATLAB returns the expected
+ % StructArray when the Valid nv-pair is supplied.
+
+ import arrow.array.StructArray
+
+ T = table([1 2]', ["A1" "A2"]', VariableNames=["Number" "String"]);
+ array = StructArray.fromMATLAB(T, Valid=2);
+ tc.verifyEqual(array.Length, int64(2));
+ tc.verifyEqual(array.NumFields, int32(2));
+ tc.verifyEqual(array.FieldNames, ["Number" "String"]);
+ tc.verifyEqual(array.Valid, [false; true]);
+
+ field1 = arrow.array([1 2]');
+ field2 = arrow.array(["A1" "A2"]');
+
+ tc.verifyEqual(field1, array.field(1));
+ tc.verifyEqual(field2, array.field(2));
+ end
+
+ function FromMATLABZeroVariablesError(tc)
+ % Verify StructArray.fromMATLAB throws an error when the input
+ % table T has zero variables.
+ import arrow.array.StructArray
+
+ fcn = @() StructArray.fromMATLAB(table);
+ tc.verifyError(fcn, "arrow:struct:ZeroVariables");
+ end
+
+ function FromMATLABZeroWrongNumberFieldNames(tc)
Review Comment:
I think the `Zero` can be dropped from the function name here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]