This is an automated email from the ASF dual-hosted git repository.
kevingurney pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 65e2f22a91 GH-37597: [MATLAB] Add `toMATLAB` method to
`arrow.array.ChunkedArray` class (#37613)
65e2f22a91 is described below
commit 65e2f22a91db5b1aca32bb5a2481a03612a4df33
Author: sgilmore10 <[email protected]>
AuthorDate: Thu Sep 7 13:46:23 2023 -0400
GH-37597: [MATLAB] Add `toMATLAB` method to `arrow.array.ChunkedArray`
class (#37613)
### Rationale for this change
Currently, there is no way to easily convert an `arrow.array.ChunkedArray`
into a corresponding MATLAB array, other than (1) manually iterating chunk by
chunk, (2) calling `toMATLAB` on each chunk, and then (3) concatenating all of
the converted chunks together into one contiguous MATLAB array.
It would be helpful to add a toMATLAB method to `arrow.array.ChunkedArray`
that abstracts away all of these steps.
### What changes are included in this PR?
1. Added `toMATLAB` method to `arrow.array.ChunkedArray` class
2. Added `preallocateMATLABArray` abstract method to `arrow.type.Type`
class. This method is used by the `ChunkedArray` `toMATLAB` to pre-allocate a
MATLAB array of the expected class type and shape. This is necessary to ensure
`toMATLAB` returns the correct MATLAB array when the `ChunkedArray` has zero
chunks. If `toMATLAB` stored the result of calling `toMATLAB` on each chunk in
a `cell` array before concatenating the values, `toMATLAB` would return a 0x0
`double` array for zero-chu [...]
3. Implement `preallocateMATLABArray` on all `arrow.type.Type` classes.
4. Added an abstract class `arrow.type.NumericType` that all classes
representing numeric data types inherit from. `NumericType` implements
`preallocateMATLABArray` for its subclasses.
### Are these changes tested?
Yes. Added unit tests to `tChunkedArray.m`.
### Are there any user-facing changes?
Yes. Users can now call `toMATLAB` on `ChunkedArray`s.
**Example**
```matlab
>> a = arrow.array([1 2 NaN 4 5]);
>> b = arrow.array([6 7 8 9 NaN 11]);
>> c = arrow.array.ChunkedArray.fromArrays(a, b);
>> data = toMATLAB(c)
data =
1
2
NaN
4
5
6
7
8
9
NaN
11
```
* Closes: #37597
Authored-by: Sarah Gilmore <[email protected]>
Signed-off-by: Kevin Gurney <[email protected]>
---
matlab/src/matlab/+arrow/+array/ChunkedArray.m | 11 +
matlab/src/matlab/+arrow/+type/BooleanType.m | 6 +
matlab/src/matlab/+arrow/+type/DateType.m | 6 +
matlab/src/matlab/+arrow/+type/Float32Type.m | 14 +-
matlab/src/matlab/+arrow/+type/Float64Type.m | 14 +-
matlab/src/matlab/+arrow/+type/Int16Type.m | 14 +-
matlab/src/matlab/+arrow/+type/Int32Type.m | 14 +-
matlab/src/matlab/+arrow/+type/Int64Type.m | 14 +-
matlab/src/matlab/+arrow/+type/Int8Type.m | 14 +-
.../+arrow/+type/{Int32Type.m => NumericType.m} | 23 ++-
matlab/src/matlab/+arrow/+type/StringType.m | 6 +
matlab/src/matlab/+arrow/+type/TimeType.m | 7 +
matlab/src/matlab/+arrow/+type/TimestampType.m | 6 +
matlab/src/matlab/+arrow/+type/Type.m | 4 +
matlab/src/matlab/+arrow/+type/UInt16Type.m | 15 +-
matlab/src/matlab/+arrow/+type/UInt32Type.m | 15 +-
matlab/src/matlab/+arrow/+type/UInt64Type.m | 14 +-
matlab/src/matlab/+arrow/+type/UInt8Type.m | 14 +-
matlab/test/arrow/array/tChunkedArray.m | 223 +++++++++++++++++++++
19 files changed, 324 insertions(+), 110 deletions(-)
diff --git a/matlab/src/matlab/+arrow/+array/ChunkedArray.m
b/matlab/src/matlab/+arrow/+array/ChunkedArray.m
index e6ee812866..96d7bb57a4 100644
--- a/matlab/src/matlab/+arrow/+array/ChunkedArray.m
+++ b/matlab/src/matlab/+arrow/+array/ChunkedArray.m
@@ -60,6 +60,17 @@ classdef ChunkedArray < matlab.mixin.CustomDisplay & ...
array = traits.ArrayConstructor(proxy);
end
+ function data = toMATLAB(obj)
+ data = preallocateMATLABArray(obj.Type, obj.Length);
+ startIndex = 1;
+ for ii = 1:obj.NumChunks
+ chunk = obj.chunk(ii);
+ endIndex = startIndex + chunk.Length - 1;
+ data(startIndex:endIndex) = toMATLAB(chunk);
+ startIndex = endIndex + 1;
+ end
+ end
+
function tf = isequal(obj, varargin)
narginchk(2, inf);
diff --git a/matlab/src/matlab/+arrow/+type/BooleanType.m
b/matlab/src/matlab/+arrow/+type/BooleanType.m
index 197ab51583..fcc5985ad2 100644
--- a/matlab/src/matlab/+arrow/+type/BooleanType.m
+++ b/matlab/src/matlab/+arrow/+type/BooleanType.m
@@ -32,4 +32,10 @@ classdef BooleanType < arrow.type.FixedWidthType
groups = matlab.mixin.util.PropertyGroup(targets);
end
end
+
+ methods(Hidden)
+ function data = preallocateMATLABArray(~, length)
+ data = false([length 1]);
+ end
+ end
end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/DateType.m
b/matlab/src/matlab/+arrow/+type/DateType.m
index ac6ece47ce..513538c848 100644
--- a/matlab/src/matlab/+arrow/+type/DateType.m
+++ b/matlab/src/matlab/+arrow/+type/DateType.m
@@ -42,4 +42,10 @@ classdef DateType < arrow.type.TemporalType
end
end
+ methods(Hidden)
+ function data = preallocateMATLABArray(~, length)
+ data = NaT([length 1]);
+ end
+ end
+
end
diff --git a/matlab/src/matlab/+arrow/+type/Float32Type.m
b/matlab/src/matlab/+arrow/+type/Float32Type.m
index 98c9f5fd79..14b9187ca6 100644
--- a/matlab/src/matlab/+arrow/+type/Float32Type.m
+++ b/matlab/src/matlab/+arrow/+type/Float32Type.m
@@ -1,3 +1,5 @@
+%FLOAT32TYPE Type class for float32 data.
+
% 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.
@@ -13,8 +15,7 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.
-classdef Float32Type < arrow.type.FixedWidthType
-%FLOAT32TYPE Type class for float32 data.
+classdef Float32Type < arrow.type.NumericType
methods
function obj = Float32Type(proxy)
@@ -22,14 +23,7 @@ classdef Float32Type < arrow.type.FixedWidthType
proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy,
"arrow.type.proxy.Float32Type")}
end
import arrow.internal.proxy.validate
- [email protected](proxy);
- end
- end
-
- methods (Access=protected)
- function groups = getDisplayPropertyGroups(~)
- targets = "ID";
- groups = matlab.mixin.util.PropertyGroup(targets);
+ [email protected](proxy);
end
end
end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/Float64Type.m
b/matlab/src/matlab/+arrow/+type/Float64Type.m
index 634e7d1a5c..7c934b784e 100644
--- a/matlab/src/matlab/+arrow/+type/Float64Type.m
+++ b/matlab/src/matlab/+arrow/+type/Float64Type.m
@@ -1,3 +1,5 @@
+%FLOAT64TYPE Type class for float64 data.
+
% 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.
@@ -13,8 +15,7 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.
-classdef Float64Type < arrow.type.FixedWidthType
-%FLOAT64Type Type class for float64 data.
+classdef Float64Type < arrow.type.NumericType
methods
function obj = Float64Type(proxy)
@@ -22,14 +23,7 @@ classdef Float64Type < arrow.type.FixedWidthType
proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy,
"arrow.type.proxy.Float64Type")}
end
import arrow.internal.proxy.validate
- [email protected](proxy);
- end
- end
-
- methods (Access=protected)
- function groups = getDisplayPropertyGroups(~)
- targets = "ID";
- groups = matlab.mixin.util.PropertyGroup(targets);
+ [email protected](proxy);
end
end
end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/Int16Type.m
b/matlab/src/matlab/+arrow/+type/Int16Type.m
index ca59f1c077..a7343b3905 100644
--- a/matlab/src/matlab/+arrow/+type/Int16Type.m
+++ b/matlab/src/matlab/+arrow/+type/Int16Type.m
@@ -1,3 +1,5 @@
+%INT16TYPE Type class for int16 data.
+
% 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.
@@ -13,8 +15,7 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.
-classdef Int16Type < arrow.type.FixedWidthType
-%INT16TYPE Type class for int8 data.
+classdef Int16Type < arrow.type.NumericType
methods
function obj = Int16Type(proxy)
@@ -22,14 +23,7 @@ classdef Int16Type < arrow.type.FixedWidthType
proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy,
"arrow.type.proxy.Int16Type")}
end
import arrow.internal.proxy.validate
- [email protected](proxy);
- end
- end
-
- methods (Access=protected)
- function groups = getDisplayPropertyGroups(~)
- targets = "ID";
- groups = matlab.mixin.util.PropertyGroup(targets);
+ [email protected](proxy);
end
end
end
diff --git a/matlab/src/matlab/+arrow/+type/Int32Type.m
b/matlab/src/matlab/+arrow/+type/Int32Type.m
index 68036d6485..2f1a654915 100644
--- a/matlab/src/matlab/+arrow/+type/Int32Type.m
+++ b/matlab/src/matlab/+arrow/+type/Int32Type.m
@@ -1,3 +1,5 @@
+%INT32TYPE Type class for int32 data.
+
% 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.
@@ -13,8 +15,7 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.
-classdef Int32Type < arrow.type.FixedWidthType
-%INT32TYPE Type class for int32 data.
+classdef Int32Type < arrow.type.NumericType
methods
function obj = Int32Type(proxy)
@@ -22,14 +23,7 @@ classdef Int32Type < arrow.type.FixedWidthType
proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy,
"arrow.type.proxy.Int32Type")}
end
import arrow.internal.proxy.validate
- [email protected](proxy);
- end
- end
-
- methods (Access=protected)
- function groups = getDisplayPropertyGroups(~)
- targets = "ID";
- groups = matlab.mixin.util.PropertyGroup(targets);
+ [email protected](proxy);
end
end
end
diff --git a/matlab/src/matlab/+arrow/+type/Int64Type.m
b/matlab/src/matlab/+arrow/+type/Int64Type.m
index d5bd7ff3a5..52cd30ac3e 100644
--- a/matlab/src/matlab/+arrow/+type/Int64Type.m
+++ b/matlab/src/matlab/+arrow/+type/Int64Type.m
@@ -1,3 +1,5 @@
+%INT64TYPE Type class for int64 data.
+
% 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.
@@ -13,8 +15,7 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.
-classdef Int64Type < arrow.type.FixedWidthType
-%INT64TYPE Type class for int64 data.
+classdef Int64Type < arrow.type.NumericType
methods
function obj = Int64Type(proxy)
@@ -22,14 +23,7 @@ classdef Int64Type < arrow.type.FixedWidthType
proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy,
"arrow.type.proxy.Int64Type")}
end
import arrow.internal.proxy.validate
- [email protected](proxy);
- end
- end
-
- methods (Access=protected)
- function groups = getDisplayPropertyGroups(~)
- targets = "ID";
- groups = matlab.mixin.util.PropertyGroup(targets);
+ [email protected](proxy);
end
end
end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/Int8Type.m
b/matlab/src/matlab/+arrow/+type/Int8Type.m
index 5df75afe76..bf07d0de44 100644
--- a/matlab/src/matlab/+arrow/+type/Int8Type.m
+++ b/matlab/src/matlab/+arrow/+type/Int8Type.m
@@ -1,3 +1,5 @@
+%INT8TYPE Type class for int8 data.
+
% 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.
@@ -13,8 +15,7 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.
-classdef Int8Type < arrow.type.FixedWidthType
-%INT8TYPE Type class for int8 data.
+classdef Int8Type < arrow.type.NumericType
methods
function obj = Int8Type(proxy)
@@ -22,14 +23,7 @@ classdef Int8Type < arrow.type.FixedWidthType
proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy,
"arrow.type.proxy.Int8Type")}
end
import arrow.internal.proxy.validate
- [email protected](proxy);
- end
- end
-
- methods (Access=protected)
- function groups = getDisplayPropertyGroups(~)
- targets = "ID";
- groups = matlab.mixin.util.PropertyGroup(targets);
+ [email protected](proxy);
end
end
end
diff --git a/matlab/src/matlab/+arrow/+type/Int32Type.m
b/matlab/src/matlab/+arrow/+type/NumericType.m
similarity index 72%
copy from matlab/src/matlab/+arrow/+type/Int32Type.m
copy to matlab/src/matlab/+arrow/+type/NumericType.m
index 68036d6485..b23fad7897 100644
--- a/matlab/src/matlab/+arrow/+type/Int32Type.m
+++ b/matlab/src/matlab/+arrow/+type/NumericType.m
@@ -1,3 +1,5 @@
+%NUMERICTYPE Type class for numeric data
+
% 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.
@@ -13,24 +15,29 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.
-classdef Int32Type < arrow.type.FixedWidthType
-%INT32TYPE Type class for int32 data.
+classdef NumericType < arrow.type.FixedWidthType
- methods
- function obj = Int32Type(proxy)
+ methods
+ function obj = NumericType(proxy)
arguments
- proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy,
"arrow.type.proxy.Int32Type")}
+ proxy(1, 1) libmexclass.proxy.Proxy
end
- import arrow.internal.proxy.validate
+
[email protected](proxy);
end
end
+ methods(Hidden)
+ function data = preallocateMATLABArray(obj, length)
+ traits = arrow.type.traits.traits(obj.ID);
+ data = zeros([length 1], traits.MatlabClassName);
+ end
+ end
+
methods (Access=protected)
function groups = getDisplayPropertyGroups(~)
targets = "ID";
groups = matlab.mixin.util.PropertyGroup(targets);
end
end
-end
-
+end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/StringType.m
b/matlab/src/matlab/+arrow/+type/StringType.m
index 53c73b3e33..e85e94cf90 100644
--- a/matlab/src/matlab/+arrow/+type/StringType.m
+++ b/matlab/src/matlab/+arrow/+type/StringType.m
@@ -32,5 +32,11 @@ classdef StringType < arrow.type.Type
groups = matlab.mixin.util.PropertyGroup(targets);
end
end
+
+ methods(Hidden)
+ function data = preallocateMATLABArray(~, length)
+ data = strings(length, 1);
+ end
+ end
end
diff --git a/matlab/src/matlab/+arrow/+type/TimeType.m
b/matlab/src/matlab/+arrow/+type/TimeType.m
index a0f8beb704..9e3e4fadbe 100644
--- a/matlab/src/matlab/+arrow/+type/TimeType.m
+++ b/matlab/src/matlab/+arrow/+type/TimeType.m
@@ -42,4 +42,11 @@ classdef TimeType < arrow.type.TemporalType
end
end
+ methods(Hidden)
+ function data = preallocateMATLABArray(~, length)
+ data = NaN([length 1]);
+ data = seconds(data);
+ end
+ end
+
end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/TimestampType.m
b/matlab/src/matlab/+arrow/+type/TimestampType.m
index 07e61f9570..8aa9b308ed 100644
--- a/matlab/src/matlab/+arrow/+type/TimestampType.m
+++ b/matlab/src/matlab/+arrow/+type/TimestampType.m
@@ -47,4 +47,10 @@ classdef TimestampType < arrow.type.TemporalType
groups = matlab.mixin.util.PropertyGroup(targets);
end
end
+
+ methods(Hidden)
+ function data = preallocateMATLABArray(obj, length)
+ data = NaT([length, 1], TimeZone=obj.TimeZone);
+ end
+ end
end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/Type.m
b/matlab/src/matlab/+arrow/+type/Type.m
index 8f4ce4dd6c..24f83e0267 100644
--- a/matlab/src/matlab/+arrow/+type/Type.m
+++ b/matlab/src/matlab/+arrow/+type/Type.m
@@ -93,6 +93,10 @@ classdef (Abstract) Type < matlab.mixin.CustomDisplay & ...
end
end
+ methods(Abstract, Hidden)
+ data = preallocateMATLABArray(obj, length)
+ end
+
methods (Sealed)
function tf = isequal(obj, varargin)
diff --git a/matlab/src/matlab/+arrow/+type/UInt16Type.m
b/matlab/src/matlab/+arrow/+type/UInt16Type.m
index d7600c982b..abe40d1824 100644
--- a/matlab/src/matlab/+arrow/+type/UInt16Type.m
+++ b/matlab/src/matlab/+arrow/+type/UInt16Type.m
@@ -1,3 +1,5 @@
+%UINT16TYPE Type class for uint16 data.
+
% 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.
@@ -13,8 +15,7 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.
-classdef UInt16Type < arrow.type.FixedWidthType
-%UINT16TYPE Type class for uint16 data.
+classdef UInt16Type < arrow.type.NumericType
methods
function obj = UInt16Type(proxy)
@@ -22,15 +23,7 @@ classdef UInt16Type < arrow.type.FixedWidthType
proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy,
"arrow.type.proxy.UInt16Type")}
end
import arrow.internal.proxy.validate
- [email protected](proxy);
- end
- end
-
-
- methods (Access=protected)
- function groups = getDisplayPropertyGroups(~)
- targets = "ID";
- groups = matlab.mixin.util.PropertyGroup(targets);
+ [email protected](proxy);
end
end
end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/UInt32Type.m
b/matlab/src/matlab/+arrow/+type/UInt32Type.m
index e16699cba5..a81c70aa43 100644
--- a/matlab/src/matlab/+arrow/+type/UInt32Type.m
+++ b/matlab/src/matlab/+arrow/+type/UInt32Type.m
@@ -1,3 +1,5 @@
+%UINT32TYPE Type class for uint32 data.
+
% 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.
@@ -13,8 +15,7 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.
-classdef UInt32Type < arrow.type.FixedWidthType
-%UINT32TYPE Type class for uint32 data.
+classdef UInt32Type < arrow.type.NumericType
methods
function obj = UInt32Type(proxy)
@@ -22,15 +23,7 @@ classdef UInt32Type < arrow.type.FixedWidthType
proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy,
"arrow.type.proxy.UInt32Type")}
end
import arrow.internal.proxy.validate
- [email protected](proxy);
- end
- end
-
-
- methods (Access=protected)
- function groups = getDisplayPropertyGroups(~)
- targets = "ID";
- groups = matlab.mixin.util.PropertyGroup(targets);
+ [email protected](proxy);
end
end
end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/UInt64Type.m
b/matlab/src/matlab/+arrow/+type/UInt64Type.m
index c190f252ab..488120c5fa 100644
--- a/matlab/src/matlab/+arrow/+type/UInt64Type.m
+++ b/matlab/src/matlab/+arrow/+type/UInt64Type.m
@@ -1,3 +1,5 @@
+%UINT64TYPE Type class for uint64 data.
+
% 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.
@@ -13,8 +15,7 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.
-classdef UInt64Type < arrow.type.FixedWidthType
-%UINT64TYPE Type class for uint64 data.
+classdef UInt64Type < arrow.type.NumericType
methods
function obj = UInt64Type(proxy)
@@ -22,14 +23,7 @@ classdef UInt64Type < arrow.type.FixedWidthType
proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy,
"arrow.type.proxy.UInt64Type")}
end
import arrow.internal.proxy.validate
- [email protected](proxy);
- end
- end
-
- methods (Access=protected)
- function groups = getDisplayPropertyGroups(~)
- targets = "ID";
- groups = matlab.mixin.util.PropertyGroup(targets);
+ [email protected](proxy);
end
end
end
\ No newline at end of file
diff --git a/matlab/src/matlab/+arrow/+type/UInt8Type.m
b/matlab/src/matlab/+arrow/+type/UInt8Type.m
index 89715991ed..e7a8756994 100644
--- a/matlab/src/matlab/+arrow/+type/UInt8Type.m
+++ b/matlab/src/matlab/+arrow/+type/UInt8Type.m
@@ -1,3 +1,5 @@
+%UINT8TYPE Type class for uint8 data.
+
% 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.
@@ -13,8 +15,7 @@
% implied. See the License for the specific language governing
% permissions and limitations under the License.
-classdef UInt8Type < arrow.type.FixedWidthType
-%UINT8TYPE Type class for uint8 data.
+classdef UInt8Type < arrow.type.NumericType
methods
function obj = UInt8Type(proxy)
@@ -22,14 +23,7 @@ classdef UInt8Type < arrow.type.FixedWidthType
proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy,
"arrow.type.proxy.UInt8Type")}
end
import arrow.internal.proxy.validate
- [email protected](proxy);
- end
- end
-
- methods (Access=protected)
- function groups = getDisplayPropertyGroups(~)
- targets = "ID";
- groups = matlab.mixin.util.PropertyGroup(targets);
+ [email protected](proxy);
end
end
end
\ No newline at end of file
diff --git a/matlab/test/arrow/array/tChunkedArray.m
b/matlab/test/arrow/array/tChunkedArray.m
index e075d0c31a..3c7a52501f 100644
--- a/matlab/test/arrow/array/tChunkedArray.m
+++ b/matlab/test/arrow/array/tChunkedArray.m
@@ -24,6 +24,21 @@ classdef tChunkedArray < matlab.unittest.TestCase
Float64Type = arrow.float64()
end
+ properties(TestParameter)
+ IntegerMatlabClass = {"uint8", ...
+ "uint16", ...
+ "uint32", ...
+ "uint64", ...
+ "int8", ...
+ "int16", ...
+ "int32", ...
+ "int64"};
+
+ FloatMatlabClass = {"single", "double"}
+
+ TimeZone = {"America/New_York", ""}
+ end
+
methods (Test)
function FromArraysTooFewInputsError(testCase)
% Verify an error is thrown when neither the Type nv-pair nor
@@ -240,6 +255,214 @@ classdef tChunkedArray < matlab.unittest.TestCase
fcn = @() chunkedArray.chunk(2);
testCase.verifyError(fcn,
"arrow:chunkedarray:NumericIndexWithEmptyChunkedArray");
end
+
+ function ToMATLABBooleanType(testCase)
+ % Verify toMATLAB returns the expected MATLAB array when the
+ % Chunked Array contains boolean arrays.
+ import arrow.array.ChunkedArray
+
+ bools = true([1 11]);
+ bools([2 3 7 8 9]) = false;
+ a1 = arrow.array(bools(1:8));
+ a2 = arrow.array(bools(8:7));
+ a3 = arrow.array(bools(9:11));
+
+ % ChunkedArray with three chunks and nonzero length
+ chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3);
+ actualArray1 = toMATLAB(chunkedArray1);
+ expectedArray1 = bools';
+ testCase.verifyEqual(actualArray1, expectedArray1);
+
+ % ChunkedArray with zero chunks and zero length
+ chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type);
+ actualArray2 = toMATLAB(chunkedArray2);
+ expectedArray2 = logical.empty(0, 1);
+ testCase.verifyEqual(actualArray2, expectedArray2);
+
+ % ChunkedArray with two chunks and zero length
+ chunkedArray3 = ChunkedArray.fromArrays(a2, a2);
+ actualArray3 = toMATLAB(chunkedArray3);
+ expectedArray3 = logical.empty(0, 1);
+ testCase.verifyEqual(actualArray3, expectedArray3);
+ end
+
+ function ToMATLABIntegerTypes(testCase, IntegerMatlabClass)
+ % Verify toMATLAB returns the expected MATLAB array when the
+ % Chunked Array contains integer arrays.
+ import arrow.array.ChunkedArray
+
+ a1 = arrow.array(cast([1 2 3 4], IntegerMatlabClass));
+ a2 = arrow.array(cast([], IntegerMatlabClass));
+ a3 = arrow.array(cast([5 6 7 8 9], IntegerMatlabClass));
+
+ % ChunkedArray with three chunks and nonzero length
+ chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3);
+ actualArray1 = toMATLAB(chunkedArray1);
+ expectedArray1 = cast((1:9)', IntegerMatlabClass);
+ testCase.verifyEqual(actualArray1, expectedArray1);
+
+ % ChunkedArray with zero chunks and zero length
+ chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type);
+ actualArray2 = toMATLAB(chunkedArray2);
+ expectedArray2 = cast(double.empty(0, 1), IntegerMatlabClass);
+ testCase.verifyEqual(actualArray2, expectedArray2);
+
+ % ChunkedArray with two chunks and zero length
+ chunkedArray3 = ChunkedArray.fromArrays(a2, a2);
+ actualArray3 = toMATLAB(chunkedArray3);
+ expectedArray3 = cast(double.empty(0, 1), IntegerMatlabClass);
+ testCase.verifyEqual(actualArray3, expectedArray3);
+ end
+
+ function ToMATLABFloatTypes(testCase, FloatMatlabClass)
+ % Verify toMATLAB returns the expected MATLAB array when the
+ % Chunked Array contains float arrays.
+ import arrow.array.ChunkedArray
+
+ a1 = arrow.array(cast([1 NaN 3 4], FloatMatlabClass));
+ a2 = arrow.array(cast([], FloatMatlabClass));
+ a3 = arrow.array(cast([5 6 7 NaN 9], FloatMatlabClass));
+
+ % ChunkedArray with three chunks and nonzero length
+ chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3);
+ actualArray1 = toMATLAB(chunkedArray1);
+ expectedArray1 = cast((1:9)', FloatMatlabClass);
+ expectedArray1([2 8]) = NaN;
+ testCase.verifyEqual(actualArray1, expectedArray1);
+
+ % ChunkedArray with zero chunks and zero length
+ chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type);
+ actualArray2 = toMATLAB(chunkedArray2);
+ expectedArray2 = cast(double.empty(0, 1), FloatMatlabClass);
+ testCase.verifyEqual(actualArray2, expectedArray2);
+
+ % ChunkedArray with two chunks and zero length
+ chunkedArray3 = ChunkedArray.fromArrays(a2, a2);
+ actualArray3 = toMATLAB(chunkedArray3);
+ expectedArray3 = cast(double.empty(0, 1), FloatMatlabClass);
+ testCase.verifyEqual(actualArray3, expectedArray3);
+ end
+
+ function ToMATLABTimeTypes(testCase)
+ % Verify toMATLAB returns the expected MATLAB array when the
+ % Chunked Array contains time arrays.
+ import arrow.array.ChunkedArray
+
+ a1 = arrow.array(seconds([1 NaN 3 4]));
+ a2 = arrow.array(seconds([]));
+ a3 = arrow.array(seconds([5 6 7 NaN 9]));
+
+ % ChunkedArray with three chunks and nonzero length
+ chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3);
+ actualArray1 = toMATLAB(chunkedArray1);
+ expectedArray1 = seconds((1:9)');
+ expectedArray1([2 8]) = NaN;
+ testCase.verifyEqual(actualArray1, expectedArray1);
+
+ % ChunkedArray with zero chunks and zero length
+ chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type);
+ actualArray2 = toMATLAB(chunkedArray2);
+ expectedArray2 = duration.empty(0, 1);
+ testCase.verifyEqual(actualArray2, expectedArray2);
+
+ % ChunkedArray with two chunks and zero length
+ chunkedArray3 = ChunkedArray.fromArrays(a2, a2);
+ actualArray3 = toMATLAB(chunkedArray3);
+ expectedArray3 = duration.empty(0, 1);
+ testCase.verifyEqual(actualArray3, expectedArray3);
+ end
+
+ function ToMATLABDateTypes(testCase)
+ % Verify toMATLAB returns the expected MATLAB array when the
+ % Chunked Array contains date arrays.
+ import arrow.array.*
+
+ dates = datetime(2023, 9, 7) + days(0:10);
+ dates([5 9]) = NaT;
+ a1 = Date64Array.fromMATLAB(dates(1:5));
+ a2 = Date64Array.fromMATLAB(dates(6:5));
+ a3 = Date64Array.fromMATLAB(dates(6:end));
+
+ % ChunkedArray with three chunks and nonzero length
+ chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3);
+ actualArray1 = toMATLAB(chunkedArray1);
+ expectedArray1 = dates';
+ testCase.verifyEqual(actualArray1, expectedArray1);
+
+ % ChunkedArray with zero chunks and zero length
+ chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type);
+ actualArray2 = toMATLAB(chunkedArray2);
+ expectedArray2 = datetime.empty(0, 1);
+ testCase.verifyEqual(actualArray2, expectedArray2);
+
+ % ChunkedArray with two chunks and zero length
+ chunkedArray3 = ChunkedArray.fromArrays(a2, a2);
+ actualArray3 = toMATLAB(chunkedArray3);
+ expectedArray3 = datetime.empty(0, 1);
+ testCase.verifyEqual(actualArray3, expectedArray3);
+ end
+
+ function ToMATLABTimestampType(testCase, TimeZone)
+ % Verify toMATLAB returns the expected MATLAB array when the
+ % Chunked Array contains timestamp arrays.
+ import arrow.array.ChunkedArray
+
+ dates = datetime(2023, 9, 7, TimeZone=TimeZone) + days(0:10);
+ dates([5 9]) = NaT;
+ a1 = arrow.array(dates(1:5));
+ a2 = arrow.array(dates(6:5));
+ a3 = arrow.array(dates(6:end));
+
+ % ChunkedArray with three chunks and nonzero length
+ chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3);
+ actualArray1 = toMATLAB(chunkedArray1);
+ expectedArray1 = dates';
+ testCase.verifyEqual(actualArray1, expectedArray1);
+
+ % ChunkedArray with zero chunks and zero length
+ chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type);
+ actualArray2 = toMATLAB(chunkedArray2);
+ expectedArray2 = datetime.empty(0, 1);
+ expectedArray2.TimeZone = TimeZone;
+ testCase.verifyEqual(actualArray2, expectedArray2);
+
+ % ChunkedArray with two chunks and zero length
+ chunkedArray3 = ChunkedArray.fromArrays(a2, a2);
+ actualArray3 = toMATLAB(chunkedArray3);
+ expectedArray3 = datetime.empty(0, 1);
+ expectedArray3.TimeZone = TimeZone;
+ testCase.verifyEqual(actualArray3, expectedArray3);
+ end
+
+ function ToMATLABStringType(testCase)
+ % Verify toMATLAB returns the expected MATLAB array when the
+ % Chunked Array contains string arrays.
+ import arrow.array.*
+
+ strs = compose("%d", 1:11);
+ strs([5 9]) = missing;
+ a1 = arrow.array(strs(1:7));
+ a2 = arrow.array(strs(7:6));
+ a3 = arrow.array(strs(8:11));
+
+ % ChunkedArray with three chunks and nonzero length
+ chunkedArray1 = ChunkedArray.fromArrays(a1, a2, a3);
+ actualArray1 = toMATLAB(chunkedArray1);
+ expectedArray1 = strs';
+ testCase.verifyEqual(actualArray1, expectedArray1);
+
+ % ChunkedArray with zero chunks and zero length
+ chunkedArray2 = ChunkedArray.fromArrays(Type=a1.Type);
+ actualArray2 = toMATLAB(chunkedArray2);
+ expectedArray2 = string.empty(0, 1);
+ testCase.verifyEqual(actualArray2, expectedArray2);
+
+ % ChunkedArray with two chunks and zero length
+ chunkedArray3 = ChunkedArray.fromArrays(a2, a2);
+ actualArray3 = toMATLAB(chunkedArray3);
+ expectedArray3 = string.empty(0, 1);
+ testCase.verifyEqual(actualArray3, expectedArray3);
+ end
end
methods