Skip to content

Commit

Permalink
apacheGH-37188: [MATLAB] Move test/util/featherRoundTrip.m into a p…
Browse files Browse the repository at this point in the history
…ackaged test utility function (apache#37190)

> **Warning** - Please don't merge this PR. It is still in progress.

### Rationale for this change

To simplify access to the `featherRoundTrip` function that is used in the `tfeather.m` tests this pull request moves the `featherRoundTrip` code into a new packaged test utility function `arrow.internal.test.io.feather.roundtrip`.

This makes it possible to`import` the function, rather than having to manually add the `test/util` folder to the MATLAB Search Path in the test class setup.

### What changes are included in this PR?

1. Moved `test/util/featherRoundTrip.m` code into a new internal packaged test utility function `arrow.internal.test.io.feather.roundtrip`.

### Are these changes tested?

Yes.

1. Updated all `tfeather.m` test cases to use new packaged function `arrow.internal.test.io.feather.roundtrip`.

### Are there any user-facing changes?

No.

This new packaged function is an internal test utility.

### Future Directions

1. Delete the old Feather MEX code.
2. Move more shared test infrastructure into packaged test functions under `arrow.internal.test.*`.
* Closes: apache#37188

Authored-by: Kevin Gurney <[email protected]>
Signed-off-by: Kevin Gurney <[email protected]>
  • Loading branch information
kevingurney authored Aug 16, 2023
1 parent 6412014 commit d330d1b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function tableOut = featherRoundTrip(filename, tableIn)
% FEATHERROUNDTRIP Helper function for round tripping a table
% to a Feather file.
% ROUNDTRIP Test utility which (1) writes a MATLAB
% table to a Feather V1 file and then (2) reads the
% resulting the Feather V1 file back into MATLAB
% as a table.

% Licensed to the Apache Software Foundation (ASF) under one or more
% contributor license agreements. See the NOTICE file distributed with
Expand All @@ -16,7 +17,11 @@
% 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.

featherwrite(filename, tableIn);
tableOut = featherread(filename);
end
function tRead = roundtrip(filename, tWrite)
arguments
filename (1, 1) string
tWrite table
end
featherwrite(filename, tWrite);
tRead = featherread(filename);
end
14 changes: 1 addition & 13 deletions matlab/test/arrow/io/feather/tRoundTrip.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@
% permissions and limitations under the License.
classdef tRoundTrip < matlab.unittest.TestCase

methods(TestClassSetup)
% Delete once arrow.internal.io.feather.Reader is submitted.
function addFeatherFunctionsToMATLABPath(testCase)
import matlab.unittest.fixtures.PathFixture
% Add Feather test utilities to the MATLAB path.
testCase.applyFixture(PathFixture('../../../util'));
% arrow.cpp.call must be on the MATLAB path.
testCase.assertTrue(~isempty(which('arrow.cpp.call')), ...
'''arrow.cpp.call'' must be on the MATLAB path. Use ''addpath'' to add folders to the MATLAB path.');
end
end

methods(Test)
function Basic(testCase)
import matlab.unittest.fixtures.TemporaryFolderFixture
Expand Down Expand Up @@ -118,4 +106,4 @@ function InvalidMATLABTableVariableNames(testCase)
{'Original variable name: '':''', ''});
end
end
end
end
45 changes: 24 additions & 21 deletions matlab/test/tfeather.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.

methods(TestClassSetup)
function addFeatherFunctionsToMATLABPath(testCase)
import matlab.unittest.fixtures.PathFixture
% Add Feather test utilities to the MATLAB path.
testCase.applyFixture(PathFixture('util'));
% arrow.cpp.call must be on the MATLAB path.
testCase.assertTrue(~isempty(which('arrow.cpp.call')), ...
'''arrow.cpp.call'' must be on the MATLAB path. Use ''addpath'' to add folders to the MATLAB path.');
end
end

methods(TestMethodSetup)

function setupTempWorkingDirectory(testCase)
Expand All @@ -40,15 +29,18 @@ function setupTempWorkingDirectory(testCase)

function NumericDatatypesNoNulls(testCase)
import arrow.internal.test.tabular.createTableWithSupportedTypes
import arrow.internal.test.io.feather.roundtrip

filename = fullfile(pwd, 'temp.feather');

actualTable = createTableWithSupportedTypes;
expectedTable = featherRoundTrip(filename, actualTable);
expectedTable = roundtrip(filename, actualTable);
testCase.verifyEqual(actualTable, expectedTable);
end

function NumericDatatypesWithNaNRow(testCase)
import arrow.internal.test.tabular.createTableWithSupportedTypes
import arrow.internal.test.io.feather.roundtrip

filename = fullfile(pwd, 'temp.feather');

Expand Down Expand Up @@ -76,25 +68,27 @@ function NumericDatatypesWithNaNRow(testCase)
'VariableNames', variableNames);
addRow(1,:) = {NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN};
actualTable = [t; addRow];
expectedTable = featherRoundTrip(filename, actualTable);
expectedTable = roundtrip(filename, actualTable);
testCase.verifyEqual(actualTable, expectedTable);
end

function NumericDatatypesWithNaNColumns(testCase)
import arrow.internal.test.tabular.createTableWithSupportedTypes
import arrow.internal.test.io.feather.roundtrip

filename = fullfile(pwd, 'temp.feather');

actualTable = createTableWithSupportedTypes;
actualTable.double = [NaN; NaN; NaN];
actualTable.int64 = [NaN; NaN; NaN];

expectedTable = featherRoundTrip(filename, actualTable);
expectedTable = roundtrip(filename, actualTable);
testCase.verifyEqual(actualTable, expectedTable);
end

function NumericDatatypesWithExpInfSciNotation(testCase)
import arrow.internal.test.tabular.createTableWithSupportedTypes
import arrow.internal.test.io.feather.roundtrip

filename = fullfile(pwd, 'temp.feather');

Expand All @@ -106,49 +100,54 @@ function NumericDatatypesWithExpInfSciNotation(testCase)

actualTable.int64(2) = 1.0418e+03;

expectedTable = featherRoundTrip(filename, actualTable);
expectedTable = roundtrip(filename, actualTable);
testCase.verifyEqual(actualTable, expectedTable);
end

function IgnoreRowVarNames(testCase)
import arrow.internal.test.tabular.createTableWithSupportedTypes
import arrow.internal.test.io.feather.roundtrip

filename = fullfile(pwd, 'temp.feather');

actualTable = createTableWithSupportedTypes;
time = {'day1', 'day2', 'day3'};
actualTable.Properties.RowNames = time;
expectedTable = featherRoundTrip(filename, actualTable);
expectedTable = roundtrip(filename, actualTable);
actualTable = createTableWithSupportedTypes;
testCase.verifyEqual(actualTable, expectedTable);
end

function NotFeatherExtension(testCase)
import arrow.internal.test.tabular.createTableWithSupportedTypes
import arrow.internal.test.io.feather.roundtrip

filename = fullfile(pwd, 'temp.txt');

actualTable = createTableWithSupportedTypes;
expectedTable = featherRoundTrip(filename, actualTable);
expectedTable = roundtrip(filename, actualTable);
testCase.verifyEqual(actualTable, expectedTable);
end

function EmptyTable(testCase)
import arrow.internal.test.io.feather.roundtrip

filename = fullfile(pwd, 'temp.feather');

actualTable = table;
expectedTable = featherRoundTrip(filename, actualTable);
expectedTable = roundtrip(filename, actualTable);
testCase.verifyEqual(actualTable, expectedTable);
end

function zeroByNTable(testCase)
import arrow.internal.test.tabular.createTableWithSupportedTypes
import arrow.internal.test.io.feather.roundtrip

filename = fullfile(pwd, 'temp.feather');

actualTable = createTableWithSupportedTypes;
actualTable([1, 2], :) = [];
expectedTable = featherRoundTrip(filename, actualTable);
expectedTable = roundtrip(filename, actualTable);
testCase.verifyEqual(actualTable, expectedTable);
end

Expand Down Expand Up @@ -243,6 +242,8 @@ function NumericComplexUnsupported(testCase)
end

function SupportedTypes(testCase)
import arrow.internal.test.io.feather.roundtrip

filename = fullfile(pwd, 'temp.feather');

% Create a table with all supported MATLAB types.
Expand All @@ -260,11 +261,13 @@ function SupportedTypes(testCase)
string (["A", "B", "C"]'), ...
datetime(2023, 6, 28) + days(0:2)');

actualTable = featherRoundTrip(filename, expectedTable);
actualTable = roundtrip(filename, expectedTable);
testCase.verifyEqual(actualTable, expectedTable);
end

function UnicodeVariableNames(testCase)
import arrow.internal.test.io.feather.roundtrip

filename = fullfile(pwd, 'temp.feather');

smiley = "😀";
Expand All @@ -273,7 +276,7 @@ function UnicodeVariableNames(testCase)
columnNames = [smiley, tree, mango];
expectedTable = table(1, 2, 3, VariableNames=columnNames);

actualTable = featherRoundTrip(filename, expectedTable);
actualTable = roundtrip(filename, expectedTable);
testCase.verifyEqual(actualTable, expectedTable);
end

Expand Down

0 comments on commit d330d1b

Please sign in to comment.