kevingurney commented on code in PR #37617:
URL: https://github.com/apache/arrow/pull/37617#discussion_r1319063593


##########
matlab/test/arrow/type/tField.m:
##########
@@ -127,5 +127,107 @@ function TestImmutableProperties(testCase)
             testCase.verifyError(@() setfield(field, "Type", arrow.boolean), 
"MATLAB:class:noSetMethod")
         end
 
+        function TestIsEqualScalarTrue(testCase)
+            % Two scalar arrow.type.Field objects are equal if:
+            %
+            %  1. Their Name properties are equal
+            %  2. Their Type properties are equal
+
+            f1 = arrow.field("A", arrow.timestamp(TimeZone="America/New_York", 
TimeUnit="Second"));
+            f2 = arrow.field("A", arrow.timestamp(TimeZone="America/New_York", 
TimeUnit="Second"));
+            testCase.verifyTrue(isequal(f1, f2));
+        end
+
+        function TestIsEqualScalarFalse(testCase)
+            % Verifies isequal returns false when expected. 
+            f1 = arrow.field("A", arrow.timestamp(TimeZone="America/New_York", 
TimeUnit="Second"));
+            f2 = arrow.field("B", arrow.timestamp(TimeZone="America/New_York", 
TimeUnit="Second"));
+            f3 = arrow.field("A", arrow.timestamp(TimeZone="America/New_York", 
TimeUnit="Millisecond"));
+            f4 = arrow.field("A", arrow.time32());
+
+            % Name properties are not equal
+            testCase.verifyFalse(isequal(f1, f2));
+
+            % Type properties are not equal
+            testCase.verifyFalse(isequal(f1, f3));
+
+            % Type properties have different class types
+            testCase.verifyFalse(isequal(f1, f4));
+
+            % Compare arrow.type.Field and a string
+            testCase.verifyFalse(isequal(f1, "A"));
+        end
+
+        function TestIsEqualNonScalarTrue(testCase)
+            % Two nonscalar arrow.type.Field arrays are equal if:
+            %  1. They have the same shape
+            %  2. Their corresponding Field elements are equal
+            
+            f1 = arrow.field("A", arrow.timestamp(TimeZone="America/New_York", 
TimeUnit="Second"));
+            f2 = arrow.field("B", arrow.string());
+            fieldArray1 = [f1 f2 f1; f2 f1 f1];
+            fieldArray2 = [f1 f2 f1; f2 f1 f1];
+
+            testCase.verifyTrue(isequal(fieldArray1, fieldArray2));
+            testCase.verifyTrue(isequal(fieldArray1, fieldArray2, 
fieldArray1));
+        end
+
+         function TestIsEqualEmptyFields(testCase)

Review Comment:
   I think the indentation is slightly off here.



##########
matlab/src/matlab/+arrow/+type/Field.m:
##########
@@ -50,6 +51,42 @@
             name = obj.Proxy.getName();
         end
 
+        function tf = isequal(obj, varargin)
+            narginchk(2, inf);
+            tf = false;
+
+            namesToCompare = strings(numel(obj), numel(varargin));
+            typesToCompare = cell([1 numel(varargin)]);
+
+            for ii = 1:numel(varargin)
+                field = varargin{ii};
+                if ~isa(field, "arrow.type.Field") || ~isequal(size(obj), 
size(field))
+                    % Return early if field is not an arrow.type.Field
+                    % or if the dimensions of obj and field do not match.
+                    return;
+                end
+
+                namesToCompare(:, ii) = [field(:).Name];
+                typesToCompare{1, ii} = [field(:).Type];
+            end
+
+            if isempty(obj)
+                % Return true early if the Field array is empty. Already

Review Comment:
   Could you reword this comment to something like "At this point, since we 
have already confirmed all the Fields have the same dimensions, if one of the 
Fields are empty, then they must all be empty. This means they must all be 
equal."



##########
matlab/test/arrow/type/tField.m:
##########
@@ -127,5 +127,107 @@ function TestImmutableProperties(testCase)
             testCase.verifyError(@() setfield(field, "Type", arrow.boolean), 
"MATLAB:class:noSetMethod")
         end
 
+        function TestIsEqualScalarTrue(testCase)
+            % Two scalar arrow.type.Field objects are equal if:
+            %
+            %  1. Their Name properties are equal
+            %  2. Their Type properties are equal
+
+            f1 = arrow.field("A", arrow.timestamp(TimeZone="America/New_York", 
TimeUnit="Second"));
+            f2 = arrow.field("A", arrow.timestamp(TimeZone="America/New_York", 
TimeUnit="Second"));
+            testCase.verifyTrue(isequal(f1, f2));
+        end
+
+        function TestIsEqualScalarFalse(testCase)
+            % Verifies isequal returns false when expected. 
+            f1 = arrow.field("A", arrow.timestamp(TimeZone="America/New_York", 
TimeUnit="Second"));
+            f2 = arrow.field("B", arrow.timestamp(TimeZone="America/New_York", 
TimeUnit="Second"));
+            f3 = arrow.field("A", arrow.timestamp(TimeZone="America/New_York", 
TimeUnit="Millisecond"));
+            f4 = arrow.field("A", arrow.time32());
+
+            % Name properties are not equal
+            testCase.verifyFalse(isequal(f1, f2));
+
+            % Type properties are not equal
+            testCase.verifyFalse(isequal(f1, f3));
+
+            % Type properties have different class types
+            testCase.verifyFalse(isequal(f1, f4));
+
+            % Compare arrow.type.Field and a string
+            testCase.verifyFalse(isequal(f1, "A"));
+        end
+
+        function TestIsEqualNonScalarTrue(testCase)
+            % Two nonscalar arrow.type.Field arrays are equal if:
+            %  1. They have the same shape
+            %  2. Their corresponding Field elements are equal
+            
+            f1 = arrow.field("A", arrow.timestamp(TimeZone="America/New_York", 
TimeUnit="Second"));
+            f2 = arrow.field("B", arrow.string());
+            fieldArray1 = [f1 f2 f1; f2 f1 f1];
+            fieldArray2 = [f1 f2 f1; f2 f1 f1];
+
+            testCase.verifyTrue(isequal(fieldArray1, fieldArray2));
+            testCase.verifyTrue(isequal(fieldArray1, fieldArray2, 
fieldArray1));
+        end
+
+         function TestIsEqualEmptyFields(testCase)
+            % Verify isequal returns the expected value when at least one
+            % of the inputs is empty.
+            
+            f1 = arrow.type.Field.empty(1, 0);
+            f2 = arrow.type.Field.empty(0, 1);
+            f3 = arrow.type.Field.empty(0, 0);
+            f4 = arrow.field("B", arrow.string());
+
+            % Compare two 1x0 Field arrays
+            testCase.verifyTrue(isequal(f1, f1));
+            
+            % Compare two 0x1 Field arrays
+            testCase.verifyTrue(isequal(f2, f2));
+
+            % Compare two 0x0 Field arrays
+            testCase.verifyTrue(isequal(f3, f3));
+
+            % Compare 1x0 and 0x1 Field arrays
+            testCase.verifyFalse(isequal(f1, f2));
+
+            % Compare 1x0 and 0x0 Field arrays
+            testCase.verifyFalse(isequal(f1, f3));
+
+            % Compare 0x1 and 0x0 Field arrays
+            testCase.verifyFalse(isequal(f2, f3));
+
+            % Compare 1x0 and 1x1 Field arrays
+            testCase.verifyFalse(isequal(f1, f4));
+        end
+
+        function TestIsEqualNonScalarFalse(testCase)
+            % Verifies isequal returns false when expected.

Review Comment:
   "... when expected for non-scalar Field arrays."



-- 
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]

Reply via email to