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


##########
matlab/src/cpp/arrow/matlab/array/proxy/time32_array.cc:
##########
@@ -0,0 +1,62 @@
+// 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.
+
+#include "arrow/matlab/array/proxy/time32_array.h"
+
+#include "arrow/matlab/type/time_unit.h"
+#include "arrow/util/utf8.h"
+
+namespace arrow::matlab::array::proxy {
+
+    // Specialization of NumericArray::Make for arrow::Time32Type
+    template <>
+    libmexclass::proxy::MakeResult Time32Array::make(const 
libmexclass::proxy::FunctionArguments& constructor_arguments) {
+       namespace mda = ::matlab::data;
+       using MatlabBuffer = arrow::matlab::buffer::MatlabBuffer;
+       using Time32Array = arrow::Time32Array;
+       using Time32ArrayProxy = 
arrow::matlab::array::proxy::NumericArray<arrow::Time32Type>;
+
+       mda::StructArray opts = constructor_arguments[0];
+
+       // Get the mxArray from constructor arguments
+       const mda::TypedArray<int32_t> timestamp_mda = opts[0]["MatlabArray"];
+       const mda::TypedArray<bool> validity_bitmap_mda = opts[0]["Valid"];
+       
+       const mda::TypedArray<mda::MATLABString> units_mda = 
opts[0]["TimeUnit"];
+
+       // extract the time unit
+       const std::u16string& u16_timeunit = units_mda[0];
+       MATLAB_ASSIGN_OR_ERROR(const auto time_unit,
+                              
arrow::matlab::type::timeUnitFromString(u16_timeunit),
+                              error::UKNOWN_TIME_UNIT_ERROR_ID)
+
+       // create the timestamp_type

Review Comment:
   timestamp_type -> time32_type



##########
matlab/src/cpp/arrow/matlab/array/proxy/time32_array.cc:
##########
@@ -0,0 +1,62 @@
+// 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.
+
+#include "arrow/matlab/array/proxy/time32_array.h"
+
+#include "arrow/matlab/type/time_unit.h"
+#include "arrow/util/utf8.h"
+
+namespace arrow::matlab::array::proxy {
+
+    // Specialization of NumericArray::Make for arrow::Time32Type
+    template <>
+    libmexclass::proxy::MakeResult Time32Array::make(const 
libmexclass::proxy::FunctionArguments& constructor_arguments) {
+       namespace mda = ::matlab::data;
+       using MatlabBuffer = arrow::matlab::buffer::MatlabBuffer;
+       using Time32Array = arrow::Time32Array;
+       using Time32ArrayProxy = 
arrow::matlab::array::proxy::NumericArray<arrow::Time32Type>;
+
+       mda::StructArray opts = constructor_arguments[0];
+
+       // Get the mxArray from constructor arguments
+       const mda::TypedArray<int32_t> timestamp_mda = opts[0]["MatlabArray"];
+       const mda::TypedArray<bool> validity_bitmap_mda = opts[0]["Valid"];
+       
+       const mda::TypedArray<mda::MATLABString> units_mda = 
opts[0]["TimeUnit"];
+
+       // extract the time unit
+       const std::u16string& u16_timeunit = units_mda[0];
+       MATLAB_ASSIGN_OR_ERROR(const auto time_unit,
+                              
arrow::matlab::type::timeUnitFromString(u16_timeunit),
+                              error::UKNOWN_TIME_UNIT_ERROR_ID)
+
+       // create the timestamp_type
+       auto data_type = arrow::time32(time_unit);
+       auto array_length = 
static_cast<int32_t>(timestamp_mda.getNumberOfElements()); // cast size_t to 
int64_t

Review Comment:
   "cast size_t to int64_t" -> "cast size_t to int32_t"



##########
matlab/src/matlab/+arrow/+array/Time32Array.m:
##########
@@ -0,0 +1,84 @@
+% arrow.array.Time32Array
+
+% 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.
+
+classdef Time32Array < arrow.array.Array
+
+    properties(Access=private)
+        NullSubstitutionValue = seconds(NaN);
+    end
+
+    methods
+        function obj = Time32Array(proxy)
+            arguments
+                proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, 
"arrow.array.proxy.Time32Array")}
+            end
+            import arrow.internal.proxy.validate
+            [email protected](proxy);
+        end
+
+        function times = toMATLAB(obj)
+            import arrow.type.TimeUnit
+
+            matlabArray = obj.Proxy.toMATLAB();
+            if obj.Type.TimeUnit == TimeUnit.Second
+                times = seconds(matlabArray);
+            else
+                times = milliseconds(matlabArray);
+            end
+            times(~obj.Valid) = obj.NullSubstitutionValue;
+        end
+
+        function times = duration(obj)
+            times = obj.toMATLAB();
+        end
+    end
+
+    methods(Static, Access=private)
+        function time = convertDurationToNumber(data, timeUnit)

Review Comment:
   Maybe we could rename this to `convertDurationToTicks`?



##########
matlab/test/arrow/array/tTime32Array.m:
##########
@@ -0,0 +1,221 @@
+%TTIME32ARRAY Unit tests for arrow.array.Time32Array
+
+% 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.
+
+classdef tTime32Array < matlab.unittest.TestCase
+
+    properties
+        ArrowArrayConstructorFcn = @arrow.array.Time32Array.fromMATLAB
+    end
+
+    properties(TestParameter)
+        Unit = {arrow.type.TimeUnit.Second, arrow.type.TimeUnit.Millisecond}
+    end
+
+    methods (Test)
+        function Basic(tc)
+            times = seconds(1:4);
+            array = tc.ArrowArrayConstructorFcn(times);
+            className = string(class(array));
+            tc.verifyEqual(className, "arrow.array.Time32Array");
+        end
+
+        function TypeIsTime32(tc)
+            times = seconds(1:4);
+            array = tc.ArrowArrayConstructorFcn(times);
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Second);
+        end
+
+        function SupportedTimeUnit(tc)
+            import arrow.type.TimeUnit
+            times = seconds(1:4);
+            
+            array = tc.ArrowArrayConstructorFcn(times, TimeUnit="Second");
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Second);
+
+            array = tc.ArrowArrayConstructorFcn(times, 
TimeUnit=TimeUnit.Second);
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Second);
+
+            array = tc.ArrowArrayConstructorFcn(times, TimeUnit="Millisecond");
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Millisecond);
+
+            array = tc.ArrowArrayConstructorFcn(times, 
TimeUnit=TimeUnit.Millisecond);
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Millisecond);
+        end
+
+        function UnsupportedTimeUnitError(tc)
+            % Verify arrow.array.Time32Array.fromMATLAB() errors if 
+            % supplied an unsupported TimeUnit (Microsecond or Nanosecond).
+            import arrow.type.TimeUnit
+            times = seconds(1:4);
+            fcn = @() tc.ArrowArrayConstructorFcn(times, 
TimeUnit="Microsecond");
+            tc.verifyError(fcn, 
"arrow:validate:temporal:UnsupportedTime32TimeUnit");
+
+            fcn = @() tc.ArrowArrayConstructorFcn(times, 
TimeUnit=TimeUnit.Microsecond);
+            tc.verifyError(fcn, 
"arrow:validate:temporal:UnsupportedTime32TimeUnit");
+
+            fcn = @() tc.ArrowArrayConstructorFcn(times, 
TimeUnit="Nanosecond");
+            tc.verifyError(fcn, 
"arrow:validate:temporal:UnsupportedTime32TimeUnit");
+
+            fcn = @() tc.ArrowArrayConstructorFcn(times, 
TimeUnit=TimeUnit.Nanosecond);
+            tc.verifyError(fcn, 
"arrow:validate:temporal:UnsupportedTime32TimeUnit");
+        end
+
+        function TestLength(testCase)
+            % Verify the Length property.
+
+            times = duration.empty(0, 1);
+            array = testCase.ArrowArrayConstructorFcn(times);
+            testCase.verifyEqual(array.Length, int64(0));
+
+            times = duration(1, 2, 3);
+            array = testCase.ArrowArrayConstructorFcn(times);
+            testCase.verifyEqual(array.Length, int64(1));
+
+            times = duration(1, 2, 3) + hours(0:4);
+            array = testCase.ArrowArrayConstructorFcn(times);
+            testCase.verifyEqual(array.Length, int64(5));
+        end
+
+        function TestToMATLAB(testCase, Unit)
+            % Verify toMATLAB() round-trips the original duration array.
+            times = seconds([100 200 355 400]);
+            array = testCase.ArrowArrayConstructorFcn(times, TimeUnit=Unit);
+            values = toMATLAB(array);
+            testCase.verifyEqual(values, times');
+        end
+
+        function TestDuration(testCase, Unit)
+            % Verify duration() round-trips the original duration array.
+            times = seconds([100 200 355 400]);
+            array = testCase.ArrowArrayConstructorFcn(times, TimeUnit=Unit);
+            values = duration(array);
+            testCase.verifyEqual(values, times');
+        end
+
+        function TestValid(testCase, Unit)
+            % Verify the Valid property returns the expected logical vector.
+            times = seconds([100 200 NaN 355 NaN 400]);
+            arrray = testCase.ArrowArrayConstructorFcn(times, TImeUnit=Unit);
+            testCase.verifyEqual(arrray.Valid, [true; true; false; true; 
false; true]);
+            testCase.verifyEqual(toMATLAB(arrray), times');
+            testCase.verifyEqual(duration(arrray), times');
+        end
+
+        function InferNullsTrueNVPair(testCase, Unit)
+            % Verify arrow.array.Time32Array.fromMATLAB() behaves as
+            % expected by InferNulls=true is provided.

Review Comment:
   by -> when



##########
matlab/src/cpp/arrow/matlab/array/proxy/time32_array.cc:
##########
@@ -0,0 +1,62 @@
+// 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.
+
+#include "arrow/matlab/array/proxy/time32_array.h"
+
+#include "arrow/matlab/type/time_unit.h"
+#include "arrow/util/utf8.h"
+
+namespace arrow::matlab::array::proxy {
+
+    // Specialization of NumericArray::Make for arrow::Time32Type
+    template <>
+    libmexclass::proxy::MakeResult Time32Array::make(const 
libmexclass::proxy::FunctionArguments& constructor_arguments) {
+       namespace mda = ::matlab::data;
+       using MatlabBuffer = arrow::matlab::buffer::MatlabBuffer;
+       using Time32Array = arrow::Time32Array;
+       using Time32ArrayProxy = 
arrow::matlab::array::proxy::NumericArray<arrow::Time32Type>;
+
+       mda::StructArray opts = constructor_arguments[0];
+
+       // Get the mxArray from constructor arguments
+       const mda::TypedArray<int32_t> timestamp_mda = opts[0]["MatlabArray"];
+       const mda::TypedArray<bool> validity_bitmap_mda = opts[0]["Valid"];
+       
+       const mda::TypedArray<mda::MATLABString> units_mda = 
opts[0]["TimeUnit"];
+
+       // extract the time unit
+       const std::u16string& u16_timeunit = units_mda[0];
+       MATLAB_ASSIGN_OR_ERROR(const auto time_unit,
+                              
arrow::matlab::type::timeUnitFromString(u16_timeunit),
+                              error::UKNOWN_TIME_UNIT_ERROR_ID)
+
+       // create the timestamp_type
+       auto data_type = arrow::time32(time_unit);
+       auto array_length = 
static_cast<int32_t>(timestamp_mda.getNumberOfElements()); // cast size_t to 
int64_t
+
+       auto data_buffer = std::make_shared<MatlabBuffer>(timestamp_mda);
+
+       // Pack the validity bitmap values.
+       MATLAB_ASSIGN_OR_ERROR(auto packed_validity_bitmap,
+                              bit::packValid(validity_bitmap_mda),
+                              error::BITPACK_VALIDITY_BITMAP_ERROR_ID);
+
+       auto array_data = arrow::ArrayData::Make(data_type, array_length, 
{packed_validity_bitmap, data_buffer});
+       auto timestamp_array = 
std::static_pointer_cast<Time32Array>(arrow::MakeArray(array_data));

Review Comment:
   timestamp_array -> time32_array



##########
matlab/src/cpp/arrow/matlab/array/proxy/time32_array.cc:
##########
@@ -0,0 +1,62 @@
+// 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.
+
+#include "arrow/matlab/array/proxy/time32_array.h"
+
+#include "arrow/matlab/type/time_unit.h"
+#include "arrow/util/utf8.h"
+
+namespace arrow::matlab::array::proxy {
+
+    // Specialization of NumericArray::Make for arrow::Time32Type
+    template <>
+    libmexclass::proxy::MakeResult Time32Array::make(const 
libmexclass::proxy::FunctionArguments& constructor_arguments) {
+       namespace mda = ::matlab::data;
+       using MatlabBuffer = arrow::matlab::buffer::MatlabBuffer;
+       using Time32Array = arrow::Time32Array;
+       using Time32ArrayProxy = 
arrow::matlab::array::proxy::NumericArray<arrow::Time32Type>;
+
+       mda::StructArray opts = constructor_arguments[0];
+
+       // Get the mxArray from constructor arguments
+       const mda::TypedArray<int32_t> timestamp_mda = opts[0]["MatlabArray"];

Review Comment:
   timestamp_mda -> time32_mda



##########
matlab/src/cpp/arrow/matlab/array/proxy/time32_array.cc:
##########
@@ -0,0 +1,62 @@
+// 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.
+
+#include "arrow/matlab/array/proxy/time32_array.h"
+
+#include "arrow/matlab/type/time_unit.h"
+#include "arrow/util/utf8.h"
+
+namespace arrow::matlab::array::proxy {
+
+    // Specialization of NumericArray::Make for arrow::Time32Type
+    template <>
+    libmexclass::proxy::MakeResult Time32Array::make(const 
libmexclass::proxy::FunctionArguments& constructor_arguments) {
+       namespace mda = ::matlab::data;
+       using MatlabBuffer = arrow::matlab::buffer::MatlabBuffer;
+       using Time32Array = arrow::Time32Array;
+       using Time32ArrayProxy = 
arrow::matlab::array::proxy::NumericArray<arrow::Time32Type>;
+
+       mda::StructArray opts = constructor_arguments[0];
+
+       // Get the mxArray from constructor arguments
+       const mda::TypedArray<int32_t> timestamp_mda = opts[0]["MatlabArray"];
+       const mda::TypedArray<bool> validity_bitmap_mda = opts[0]["Valid"];
+       
+       const mda::TypedArray<mda::MATLABString> units_mda = 
opts[0]["TimeUnit"];
+
+       // extract the time unit
+       const std::u16string& u16_timeunit = units_mda[0];
+       MATLAB_ASSIGN_OR_ERROR(const auto time_unit,
+                              
arrow::matlab::type::timeUnitFromString(u16_timeunit),
+                              error::UKNOWN_TIME_UNIT_ERROR_ID)
+
+       // create the timestamp_type
+       auto data_type = arrow::time32(time_unit);
+       auto array_length = 
static_cast<int32_t>(timestamp_mda.getNumberOfElements()); // cast size_t to 
int64_t
+
+       auto data_buffer = std::make_shared<MatlabBuffer>(timestamp_mda);

Review Comment:
   timestamp_mda -> time32_mda



##########
matlab/src/matlab/+arrow/+array/Time32Array.m:
##########
@@ -0,0 +1,84 @@
+% arrow.array.Time32Array
+
+% 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.
+
+classdef Time32Array < arrow.array.Array
+
+    properties(Access=private)
+        NullSubstitutionValue = seconds(NaN);
+    end
+
+    methods
+        function obj = Time32Array(proxy)
+            arguments
+                proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, 
"arrow.array.proxy.Time32Array")}
+            end
+            import arrow.internal.proxy.validate
+            [email protected](proxy);
+        end
+
+        function times = toMATLAB(obj)
+            import arrow.type.TimeUnit
+
+            matlabArray = obj.Proxy.toMATLAB();
+            if obj.Type.TimeUnit == TimeUnit.Second
+                times = seconds(matlabArray);
+            else
+                times = milliseconds(matlabArray);
+            end
+            times(~obj.Valid) = obj.NullSubstitutionValue;
+        end
+
+        function times = duration(obj)
+            times = obj.toMATLAB();
+        end
+    end
+
+    methods(Static, Access=private)
+        function time = convertDurationToNumber(data, timeUnit)
+            if (timeUnit == arrow.type.TimeUnit.Second)
+                time = cast(seconds(data), "int32");
+            else
+                time = cast(milliseconds(data), "int32");
+            end
+        end
+    end
+
+    methods(Static)
+        function array = fromMATLAB(data, opts)
+            arguments
+                data
+                opts.TimeUnit(1, 1) TimeUnit {timeUnit("Time32", 
opts.TimeUnit)} = TimeUnit.Second
+                opts.InferNulls(1, 1) logical = true
+                opts.Valid
+            end
+
+            import arrow.type.TimeUnit
+            import arrow.array.Time32Array
+            import arrow.internal.validate.temporal.timeUnit
+            
+            arrow.internal.validate.type(data, "duration");
+            arrow.internal.validate.shape(data);
+
+            validElements = arrow.internal.validate.parseValidElements(data, 
opts);
+            time = Time32Array.convertDurationToNumber(data, opts.TimeUnit);

Review Comment:
   time -> ticks



##########
matlab/test/arrow/array/tTime32Array.m:
##########
@@ -0,0 +1,221 @@
+%TTIME32ARRAY Unit tests for arrow.array.Time32Array
+
+% 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.
+
+classdef tTime32Array < matlab.unittest.TestCase
+
+    properties
+        ArrowArrayConstructorFcn = @arrow.array.Time32Array.fromMATLAB
+    end
+
+    properties(TestParameter)
+        Unit = {arrow.type.TimeUnit.Second, arrow.type.TimeUnit.Millisecond}
+    end
+
+    methods (Test)
+        function Basic(tc)
+            times = seconds(1:4);
+            array = tc.ArrowArrayConstructorFcn(times);
+            className = string(class(array));
+            tc.verifyEqual(className, "arrow.array.Time32Array");

Review Comment:
   I think you can use `verifyInstanceOf` here.



##########
matlab/test/arrow/array/tTime32Array.m:
##########
@@ -0,0 +1,221 @@
+%TTIME32ARRAY Unit tests for arrow.array.Time32Array
+
+% 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.
+
+classdef tTime32Array < matlab.unittest.TestCase
+
+    properties
+        ArrowArrayConstructorFcn = @arrow.array.Time32Array.fromMATLAB
+    end
+
+    properties(TestParameter)
+        Unit = {arrow.type.TimeUnit.Second, arrow.type.TimeUnit.Millisecond}
+    end
+
+    methods (Test)
+        function Basic(tc)
+            times = seconds(1:4);
+            array = tc.ArrowArrayConstructorFcn(times);
+            className = string(class(array));
+            tc.verifyEqual(className, "arrow.array.Time32Array");
+        end
+
+        function TypeIsTime32(tc)
+            times = seconds(1:4);
+            array = tc.ArrowArrayConstructorFcn(times);
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Second);
+        end
+
+        function SupportedTimeUnit(tc)
+            import arrow.type.TimeUnit
+            times = seconds(1:4);
+            
+            array = tc.ArrowArrayConstructorFcn(times, TimeUnit="Second");
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Second);
+
+            array = tc.ArrowArrayConstructorFcn(times, 
TimeUnit=TimeUnit.Second);
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Second);
+
+            array = tc.ArrowArrayConstructorFcn(times, TimeUnit="Millisecond");
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Millisecond);
+
+            array = tc.ArrowArrayConstructorFcn(times, 
TimeUnit=TimeUnit.Millisecond);
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Millisecond);
+        end
+
+        function UnsupportedTimeUnitError(tc)
+            % Verify arrow.array.Time32Array.fromMATLAB() errors if 
+            % supplied an unsupported TimeUnit (Microsecond or Nanosecond).
+            import arrow.type.TimeUnit
+            times = seconds(1:4);
+            fcn = @() tc.ArrowArrayConstructorFcn(times, 
TimeUnit="Microsecond");
+            tc.verifyError(fcn, 
"arrow:validate:temporal:UnsupportedTime32TimeUnit");
+
+            fcn = @() tc.ArrowArrayConstructorFcn(times, 
TimeUnit=TimeUnit.Microsecond);
+            tc.verifyError(fcn, 
"arrow:validate:temporal:UnsupportedTime32TimeUnit");
+
+            fcn = @() tc.ArrowArrayConstructorFcn(times, 
TimeUnit="Nanosecond");
+            tc.verifyError(fcn, 
"arrow:validate:temporal:UnsupportedTime32TimeUnit");
+
+            fcn = @() tc.ArrowArrayConstructorFcn(times, 
TimeUnit=TimeUnit.Nanosecond);
+            tc.verifyError(fcn, 
"arrow:validate:temporal:UnsupportedTime32TimeUnit");
+        end
+
+        function TestLength(testCase)
+            % Verify the Length property.
+
+            times = duration.empty(0, 1);
+            array = testCase.ArrowArrayConstructorFcn(times);
+            testCase.verifyEqual(array.Length, int64(0));
+
+            times = duration(1, 2, 3);
+            array = testCase.ArrowArrayConstructorFcn(times);
+            testCase.verifyEqual(array.Length, int64(1));
+
+            times = duration(1, 2, 3) + hours(0:4);
+            array = testCase.ArrowArrayConstructorFcn(times);
+            testCase.verifyEqual(array.Length, int64(5));
+        end
+
+        function TestToMATLAB(testCase, Unit)
+            % Verify toMATLAB() round-trips the original duration array.
+            times = seconds([100 200 355 400]);
+            array = testCase.ArrowArrayConstructorFcn(times, TimeUnit=Unit);
+            values = toMATLAB(array);
+            testCase.verifyEqual(values, times');
+        end
+
+        function TestDuration(testCase, Unit)
+            % Verify duration() round-trips the original duration array.
+            times = seconds([100 200 355 400]);
+            array = testCase.ArrowArrayConstructorFcn(times, TimeUnit=Unit);
+            values = duration(array);
+            testCase.verifyEqual(values, times');
+        end
+
+        function TestValid(testCase, Unit)
+            % Verify the Valid property returns the expected logical vector.
+            times = seconds([100 200 NaN 355 NaN 400]);
+            arrray = testCase.ArrowArrayConstructorFcn(times, TImeUnit=Unit);
+            testCase.verifyEqual(arrray.Valid, [true; true; false; true; 
false; true]);
+            testCase.verifyEqual(toMATLAB(arrray), times');
+            testCase.verifyEqual(duration(arrray), times');
+        end
+
+        function InferNullsTrueNVPair(testCase, Unit)
+            % Verify arrow.array.Time32Array.fromMATLAB() behaves as
+            % expected by InferNulls=true is provided.
+
+            times = seconds([1 2 NaN 4 5 NaN 7]);
+            array = testCase.ArrowArrayConstructorFcn(times, InferNulls=true, 
TimeUnit=Unit);
+            expectedValid = [true; true; false; true; true; false; true];
+            testCase.verifyEqual(array.Valid, expectedValid);
+            testCase.verifyEqual(toMATLAB(array), times');
+            testCase.verifyEqual(duration(array), times');
+        end
+
+        function InferNullsFalseNVPair(testCase, Unit)
+            % Verify arrow.array.Time32Array.fromMATLAB() behaves as
+            % expected by InferNulls=false is provided.

Review Comment:
   by -> when



##########
matlab/test/arrow/array/tTime32Array.m:
##########
@@ -0,0 +1,221 @@
+%TTIME32ARRAY Unit tests for arrow.array.Time32Array
+
+% 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.
+
+classdef tTime32Array < matlab.unittest.TestCase
+
+    properties
+        ArrowArrayConstructorFcn = @arrow.array.Time32Array.fromMATLAB
+    end
+
+    properties(TestParameter)
+        Unit = {arrow.type.TimeUnit.Second, arrow.type.TimeUnit.Millisecond}
+    end
+
+    methods (Test)
+        function Basic(tc)
+            times = seconds(1:4);
+            array = tc.ArrowArrayConstructorFcn(times);
+            className = string(class(array));
+            tc.verifyEqual(className, "arrow.array.Time32Array");
+        end
+
+        function TypeIsTime32(tc)
+            times = seconds(1:4);
+            array = tc.ArrowArrayConstructorFcn(times);
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Second);
+        end
+
+        function SupportedTimeUnit(tc)
+            import arrow.type.TimeUnit
+            times = seconds(1:4);
+            
+            array = tc.ArrowArrayConstructorFcn(times, TimeUnit="Second");
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Second);
+
+            array = tc.ArrowArrayConstructorFcn(times, 
TimeUnit=TimeUnit.Second);
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Second);
+
+            array = tc.ArrowArrayConstructorFcn(times, TimeUnit="Millisecond");
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Millisecond);
+
+            array = tc.ArrowArrayConstructorFcn(times, 
TimeUnit=TimeUnit.Millisecond);
+            tc.verifyTime32Type(array.Type, arrow.type.TimeUnit.Millisecond);
+        end
+
+        function UnsupportedTimeUnitError(tc)
+            % Verify arrow.array.Time32Array.fromMATLAB() errors if 
+            % supplied an unsupported TimeUnit (Microsecond or Nanosecond).
+            import arrow.type.TimeUnit
+            times = seconds(1:4);
+            fcn = @() tc.ArrowArrayConstructorFcn(times, 
TimeUnit="Microsecond");
+            tc.verifyError(fcn, 
"arrow:validate:temporal:UnsupportedTime32TimeUnit");
+
+            fcn = @() tc.ArrowArrayConstructorFcn(times, 
TimeUnit=TimeUnit.Microsecond);
+            tc.verifyError(fcn, 
"arrow:validate:temporal:UnsupportedTime32TimeUnit");
+
+            fcn = @() tc.ArrowArrayConstructorFcn(times, 
TimeUnit="Nanosecond");
+            tc.verifyError(fcn, 
"arrow:validate:temporal:UnsupportedTime32TimeUnit");
+
+            fcn = @() tc.ArrowArrayConstructorFcn(times, 
TimeUnit=TimeUnit.Nanosecond);
+            tc.verifyError(fcn, 
"arrow:validate:temporal:UnsupportedTime32TimeUnit");
+        end
+
+        function TestLength(testCase)
+            % Verify the Length property.
+
+            times = duration.empty(0, 1);
+            array = testCase.ArrowArrayConstructorFcn(times);
+            testCase.verifyEqual(array.Length, int64(0));
+
+            times = duration(1, 2, 3);
+            array = testCase.ArrowArrayConstructorFcn(times);
+            testCase.verifyEqual(array.Length, int64(1));
+
+            times = duration(1, 2, 3) + hours(0:4);
+            array = testCase.ArrowArrayConstructorFcn(times);
+            testCase.verifyEqual(array.Length, int64(5));
+        end
+
+        function TestToMATLAB(testCase, Unit)
+            % Verify toMATLAB() round-trips the original duration array.
+            times = seconds([100 200 355 400]);
+            array = testCase.ArrowArrayConstructorFcn(times, TimeUnit=Unit);
+            values = toMATLAB(array);
+            testCase.verifyEqual(values, times');
+        end
+
+        function TestDuration(testCase, Unit)
+            % Verify duration() round-trips the original duration array.
+            times = seconds([100 200 355 400]);
+            array = testCase.ArrowArrayConstructorFcn(times, TimeUnit=Unit);
+            values = duration(array);
+            testCase.verifyEqual(values, times');
+        end
+
+        function TestValid(testCase, Unit)
+            % Verify the Valid property returns the expected logical vector.
+            times = seconds([100 200 NaN 355 NaN 400]);
+            arrray = testCase.ArrowArrayConstructorFcn(times, TImeUnit=Unit);
+            testCase.verifyEqual(arrray.Valid, [true; true; false; true; 
false; true]);
+            testCase.verifyEqual(toMATLAB(arrray), times');
+            testCase.verifyEqual(duration(arrray), times');
+        end
+
+        function InferNullsTrueNVPair(testCase, Unit)
+            % Verify arrow.array.Time32Array.fromMATLAB() behaves as
+            % expected by InferNulls=true is provided.
+
+            times = seconds([1 2 NaN 4 5 NaN 7]);
+            array = testCase.ArrowArrayConstructorFcn(times, InferNulls=true, 
TimeUnit=Unit);
+            expectedValid = [true; true; false; true; true; false; true];
+            testCase.verifyEqual(array.Valid, expectedValid);
+            testCase.verifyEqual(toMATLAB(array), times');
+            testCase.verifyEqual(duration(array), times');
+        end
+
+        function InferNullsFalseNVPair(testCase, Unit)
+            % Verify arrow.array.Time32Array.fromMATLAB() behaves as
+            % expected by InferNulls=false is provided.
+
+            times = seconds([1 2 NaN 4 5 NaN 7]);
+            array = testCase.ArrowArrayConstructorFcn(times, InferNulls=false, 
TimeUnit=Unit);
+            expectedValid = true([7 1]);
+            testCase.verifyEqual(array.Valid, expectedValid);
+
+            % If NaN durations were not considered null values, then they
+            % are treated like int32(0) values.
+            expectedTime = times';
+            expectedTime([3 6]) = 0;
+            testCase.verifyEqual(toMATLAB(array), expectedTime);
+            testCase.verifyEqual(duration(array), expectedTime);
+        end
+
+        function TestValidNVPair(testCase, Unit)
+            % Verify arrow.array.Time32Array.fromMATLAB() accepts the Valid
+            % nv-pair, and it behaves as expected.
+
+            times = seconds([1 2 NaN 4 5 NaN 7]);
+            
+            % Supply the Valid name-value pair as vector of indices.
+            array = testCase.ArrowArrayConstructorFcn(times, TimeUnit=Unit, 
Valid=[1 2 3 5]);
+            testCase.verifyEqual(array.Valid, [true; true; true; false; true; 
false; false]);
+            expectedTimes = times';
+            expectedTimes(3) = 0;
+            expectedTimes([4 6 7]) = NaN;
+            testCase.verifyEqual(toMATLAB(array), expectedTimes);
+
+            % Supply the Valid name-value pair as a logical scalar.
+            array = testCase.ArrowArrayConstructorFcn(times, TimeUnit=Unit, 
Valid=false);
+            testCase.verifyEqual(array.Valid, false([7 1]));
+            expectedTimes(:) = NaN;
+            testCase.verifyEqual(toMATLAB(array), expectedTimes);
+        end
+
+        function EmptyDurationVector(testCase)
+            % Verify arrow.array.Time32Array.fromMATLAB() accepts any
+            % empty-shaped duration as input.
+
+            times = duration.empty(0, 0);
+            array = testCase.ArrowArrayConstructorFcn(times);
+            testCase.verifyEqual(array.Length, int64(0));
+            testCase.verifyEqual(array.Valid, logical.empty(0, 1));
+            testCase.verifyEqual(toMATLAB(array), duration.empty(0, 1));
+
+            % test with NDimensional empty array

Review Comment:
   Just a slight wording change suggestion: "Test with an N-Dimensional empty 
array"



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