-
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.
…MATLAB class (#37629) ### Rationale for this change Following on to #37474, #37446, #37525, and #37627, we should implement `isequal` for the arrow.tabular.Table` MATLAB class. ### What changes are included in this PR? 1. Add new function `arrow.internal.tabular.isequal` that both `arrow.tabular.RecordBatch` and `arrow.tabular.Table` can use to implement their `isequal` methods. 2. Modified `arrow.tabular.RecordBatch` to use the new `isequal` package function to implement its `isequal` method. 3. Implemented the `isequal` method for `arrow.tabular.Table` using the new `isequal` package function. ### Are these changes tested? Yes, added `isequal` unit tests to `tTable.m` ### Are there any user-facing changes? Yes. Users can now compare `arrow.tabular.Table`s using `isequal`: ```matlab >> t1 = table(1, "A", false, VariableNames=["Number", "String", "Logical"]); >> t2 = table([1; 2], ["A"; "B"], [false; false], VariableNames=["Number", "String", "Logical"]); >> tbl1 = arrow.table(t1); >> tbl2 = arrow.table(t2); >> tbl3 = arrow.table(t1); >> isequal(tbl1, tbl2) ans = logical 0 >> isequal(tbl1, tbl3) ans = logical 1 ``` * Closes: #37628 Authored-by: Sarah Gilmore <sgilmore@mathworks.com> Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
- Loading branch information
1 parent
0e6b8c5
commit f1d2fc9
Showing
4 changed files
with
138 additions
and
39 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,60 @@ | ||
%ISEQUAL Utility function used by both arrow.tabular.RecordBatch and | ||
%arrow.tabular.Table to implement the isequal method. | ||
|
||
% 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 tf = isequal(tabularObj, varargin) | ||
narginchk(2, inf); | ||
tf = false; | ||
|
||
classType = string(class(tabularObj)); | ||
|
||
schemasToCompare = cell([1 numel(varargin)]); | ||
for ii = 1:numel(varargin) | ||
element = varargin{ii}; | ||
if ~isa(element, classType) | ||
% If element is not an instance of classType, then it cannot | ||
% be equal to tabularObj. Return false early. | ||
return; | ||
end | ||
schemasToCompare{ii} = element.Schema; | ||
end | ||
|
||
if ~isequal(tabularObj.Schema, schemasToCompare{:}) | ||
% If the schemas are not equal, then the record batches (or tables) | ||
% are not equal. Return false early. | ||
return; | ||
end | ||
|
||
% Function that extracts the column stored at colIndex from the | ||
% record batch (or table) stored at tabularIndex in varargin. | ||
getColumnFcn = @(tabularIndex, colIndex) varargin{tabularIndex}.column(colIndex); | ||
|
||
tabularObjIndices = 1:numel(varargin); | ||
for ii = 1:tabularObj.NumColumns | ||
colIndices = repmat(ii, [1 numel(tabularObjIndices)]); | ||
% Gather all columns at index ii across the record batches (or | ||
% tables) stored in varargin. Compare these columns with the | ||
% corresponding column in obj. If they are not equal, then the | ||
% record batches (or tables) are not equal. Return false. | ||
columnsToCompare = arrayfun(getColumnFcn, tabularObjIndices, colIndices, UniformOutput=false); | ||
if ~isequal(tabularObj.column(ii), columnsToCompare{:}) | ||
return; | ||
end | ||
end | ||
tf = true; | ||
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