kevingurney commented on code in PR #37446:
URL: https://github.com/apache/arrow/pull/37446#discussion_r1309483714
##########
matlab/src/cpp/arrow/matlab/array/proxy/array.cc:
##########
@@ -91,4 +93,26 @@ namespace arrow::matlab::array::proxy {
context.outputs[0] = factory.createScalar(proxy_id);
context.outputs[1] =
factory.createScalar(static_cast<int64_t>(type_id));
}
+
+ void Array::isEqual(libmexclass::proxy::method::Context& context) {
+ namespace mda = ::matlab::data;
+
+ const mda::TypedArray<uint64_t> array_proxy_ids = context.inputs[0];
+
+ bool is_equal = true;
+ const auto equals_options = arrow::EqualOptions::Defaults();
+ for (const auto& array_proxy_id : array_proxy_ids) {
+ // Retrieve the proxy::Array proxy from the ProxyManager
Review Comment:
I think this could be reworded as just "Retrieve the Array proxy from the
ProxyManager."
##########
matlab/test/arrow/array/tTime32Array.m:
##########
@@ -208,6 +208,76 @@ function ErrorIfNonDuration(testCase)
fcn = @() testCase.ArrowArrayConstructorFcn(numbers);
testCase.verifyError(fcn, "arrow:array:InvalidType");
end
+
+ function TestIsEqualTrue(tc, Unit)
+ % Verifies isequal returns true when expected. Two are
+ % considered equal if:
+ % 1. They have the same type
+ % 2. They have the same length
+ % 3. The same elements are valid
+ % 4. Corresponding valid elements are equal.
+
+ times1 = seconds([1 2 3 4]);
+ times2 = seconds([1 2 10 4]);
+
+ array1 = tc.ArrowArrayConstructorFcn(times1, TimeUnit=Unit,
Valid=[1 2 4]);
+ array2 = tc.ArrowArrayConstructorFcn(times1, TimeUnit=Unit,
Valid=[1 2 4]);
+ array3 = tc.ArrowArrayConstructorFcn(times2, TimeUnit=Unit,
Valid=[1 2 4]);
+
+ tc.verifyTrue(isequal(array1, array2));
+ tc.verifyTrue(isequal(array1, array3));
+ tc.verifyTrue(isequal(array1, array2, array3));
+ end
+
+ function TestIsEqualFalse(tc, Unit)
+ % Verify isequal returns false when expected. Two arrays are
+ % considered not equal if one of the conditions is met:
+ % 1. They have different types
+ % 2. They have different lengths
+ % 3. Different elements are valid
+ % 4. The corresponding valid elements are not equal.
Review Comment:
5. They have the same `TimeUnit`.
##########
matlab/test/arrow/array/hNumericArray.m:
##########
@@ -149,5 +149,60 @@ function TestArrowType(tc)
arrowArray = tc.ArrowArrayConstructorFcn(data);
tc.verifyEqual(arrowArray.Type.ID, tc.ArrowType.ID);
end
+
+ function TestIsEqualTrue(tc)
+ % Verifies isequal returns true when expected. Two are
Review Comment:
Two -> Two arrays
##########
matlab/test/arrow/array/tTimestampArray.m:
##########
@@ -179,8 +179,85 @@ function EmptyDatetimeVector(testCase)
testCase.verifyEqual(arrowArray.Length, int64(0));
testCase.verifyEqual(arrowArray.Valid, logical.empty(0, 1));
testCase.verifyEqual(toMATLAB(arrowArray), datetime.empty(0, 1));
+ end
+
+ function TestIsEqualTrue(tc, TimeZone)
+ % Verifies isequal returns true when expected. Two are
+ % considered equal if:
+ % 1. They have the same type
+ % 2. They have the same length
+ % 3. The same elements are valid
+ % 4. Corresponding valid elements are equal.
+
+ dates1 = datetime(2023, 6, 22, TimeZone=TimeZone) + days(0:4);
+ dates2 = datetime(2023, 6, 22, TimeZone=TimeZone) + days([0 1 5 3
4]);
+
+ array1 = tc.ArrowArrayConstructorFcn(dates1, Valid=[1 2 4]);
+ array2 = tc.ArrowArrayConstructorFcn(dates1, Valid=[1 2 4]);
+ array3 = tc.ArrowArrayConstructorFcn(dates2, Valid=[1 2 4]);
+
+ tc.verifyTrue(isequal(array1, array2));
+ tc.verifyTrue(isequal(array1, array3));
+ tc.verifyTrue(isequal(array1, array2, array3));
+ end
+
+ function TestIsEqualFalse(tc, TimeZone)
+ % Verify isequal returns false when expected. Two arrays are
+ % considered not equal if one of the conditions is met:
+ % 1. They have different types
+ % 2. They have different lengths
+ % 3. Different elements are valid
+ % 4. The corresponding valid elements are not equal.
+
+ dates1 = datetime(2023, 6, 22, TimeZone=TimeZone) + days(0:4);
+ dates2 = datetime(2023, 6, 22, TimeZone=TimeZone) + days([1 1 2 3
4]);
+ dates3 = datetime(2023, 6, 22, TimeZone=TimeZone) + days(0:5);
+ array1 = tc.ArrowArrayConstructorFcn(dates1, Valid=[1 2 4]);
+ array2 = tc.ArrowArrayConstructorFcn(dates1, Valid=[1 4]);
+ array3 = tc.ArrowArrayConstructorFcn(dates2, Valid=[1 2 4]);
+ array4 = arrow.array([true false true false]);
+ array5 = tc.ArrowArrayConstructorFcn(dates3, Valid=[1 2 4]);
+
+ % The same elements are not valid.
+ tc.verifyFalse(isequal(array1, array2));
+ % Corresponding elements are not equal.
+ tc.verifyFalse(isequal(array1, array3));
+
+ % The arrays have different types.
+ tc.verifyFalse(isequal(array1, array4));
+
+ % The arrays have different lengths.
+ tc.verifyFalse(isequal(array1, array5));
+
+ % Comparing an arrow.array.BooleanArray to a double
+ tc.verifyFalse(isequal(array1, 1));
+
+ % Supply more than two input arguments to isequal
+ tc.verifyFalse(isequal(array1, array1, array3, array4, array5));
+ end
+
+ function TestIsEqualFalseTimeZoneMistmatch(tc)
+ % Verify two TimestampArrays are not considered equal if one
+ % has a TimeZone and one does not.
+ dates1 = datetime(2023, 6, 22, TimeZone="America/Anchorage") +
days(0:4);
+ dates2 = dates1 - tzoffset(dates1);
+ dates2.TimeZone = '';
+
+ array1 = tc.ArrowArrayConstructorFcn(dates1);
+ array2 = tc.ArrowArrayConstructorFcn(dates2);
+
+ % arrays are not equal
+ tc.verifyFalse(isequal(array1, array2));
+ end
+ function TestIsEqualFalseTimeUnitMistmatch(tc, TimeZone)
Review Comment:
Should we add a test for whether two Timestamps are equal if they have two
different TimeZone values?
##########
matlab/test/arrow/array/tBooleanArray.m:
##########
@@ -158,5 +158,60 @@ function TestArrowType(tc)
arrowArray = tc.ArrowArrayConstructorFcn(data);
tc.verifyEqual(arrowArray.Type.ID, tc.ArrowType.ID);
end
+
+ function TestIsEqualTrue(tc)
+ % Verifies isequal returns true when expected. Two are
Review Comment:
Two -> Two arrays
##########
matlab/test/arrow/array/hNumericArray.m:
##########
@@ -149,5 +149,60 @@ function TestArrowType(tc)
arrowArray = tc.ArrowArrayConstructorFcn(data);
tc.verifyEqual(arrowArray.Type.ID, tc.ArrowType.ID);
end
+
+ function TestIsEqualTrue(tc)
+ % Verifies isequal returns true when expected. Two are
+ % considered equal if:
+ % 1. They have the same type
+ % 2. They have the same length
+ % 3. The same elements are valid
+ % 4. Corresponding valid elements are equal.
+
+ data1 = tc.MatlabArrayFcn([1 2 3 4]);
+ data2 = tc.MatlabArrayFcn([1 2 5 4]);
+ array1 = tc.ArrowArrayConstructorFcn(data1, Valid=[1 2 4]);
+ array2 = tc.ArrowArrayConstructorFcn(data1, Valid=[1 2 4]);
+ array3 = tc.ArrowArrayConstructorFcn(data2, Valid=[1 2 4]);
+
+ tc.verifyTrue(isequal(array1, array2));
+ tc.verifyTrue(isequal(array1, array3));
+ tc.verifyTrue(isequal(array1, array2, array3));
+ end
+
+ function TestIsEqualFalse(tc)
+ % Verify isequal returns false when expected. Two arrays are
+ % considered not equal if one of the conditions is met:
Review Comment:
one of the conditions -> one of the following conditions
##########
matlab/test/arrow/array/tTime64Array.m:
##########
@@ -224,6 +224,75 @@ function NanosecondPrecision(testCase)
expected = milliseconds(1.0030030);
testCase.verifyEqual(duration(array), expected);
end
+
+ function TestIsEqualTrue(tc, Unit)
+ % Verifies isequal returns true when expected. Two are
+ % considered equal if:
+ % 1. They have the same type
+ % 2. They have the same length
+ % 3. The same elements are valid
+ % 4. Corresponding valid elements are equal.
+
+ times1 = seconds([1 2 3 4]);
+ times2 = seconds([1 2 10 4]);
+
+ array1 = tc.ArrowArrayConstructorFcn(times1, TimeUnit=Unit,
Valid=[1 2 4]);
+ array2 = tc.ArrowArrayConstructorFcn(times1, TimeUnit=Unit,
Valid=[1 2 4]);
+ array3 = tc.ArrowArrayConstructorFcn(times2, TimeUnit=Unit,
Valid=[1 2 4]);
+
+ tc.verifyTrue(isequal(array1, array2));
+ tc.verifyTrue(isequal(array1, array3));
+ tc.verifyTrue(isequal(array1, array2, array3));
+ end
+
+ function TestIsEqualFalse(tc, Unit)
+ % Verify isequal returns false when expected. Two arrays are
+ % considered not equal if one of the conditions is met:
+ % 1. They have different types
+ % 2. They have different lengths
+ % 3. Different elements are valid
+ % 4. The corresponding valid elements are not equal.
+
+ times1 = seconds([1 2 3 4]);
+ times2 = seconds([1 1 2 3]);
+ times3 = seconds([1 2 3 4 5]);
+
+ array1 = tc.ArrowArrayConstructorFcn(times1, TimeUnit=Unit,
Valid=[1 2 4]);
+ array2 = tc.ArrowArrayConstructorFcn(times1, TimeUnit=Unit,
Valid=[1 4]);
+ array3 = tc.ArrowArrayConstructorFcn(times2, TimeUnit=Unit,
Valid=[1 2 4]);
+ array4 = arrow.array([true false true false]);
+ array5 = tc.ArrowArrayConstructorFcn(times3, Valid=[1 2 4]);
+
+ % The same elements are not valid.
+ tc.verifyFalse(isequal(array1, array2));
+
+ % Corresponding elements are not equal.
+ tc.verifyFalse(isequal(array1, array3));
+
+ % The arrays have different types.
+ tc.verifyFalse(isequal(array1, array4));
+
+ % The arrays have different lengths.
+ tc.verifyFalse(isequal(array1, array5));
+
+ % Comparing an arrow.array.BooleanArray to a double
+ tc.verifyFalse(isequal(array1, 1));
+
+ % Supply more than two input arguments to isequal
+ tc.verifyFalse(isequal(array1, array1, array3, array4, array5));
+ end
+
+ function TestIsEqualFalseTimeUnitMistmatch(tc)
+ % Verify two Time64Arrays are not considered equal they have
Review Comment:
"equal they" -> "equal if they"
--
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]