-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-37230: [MATLAB] Add
arrow.type.Date64Type
class and `arrow.date6…
…4` construction function (#37578) ### Rationale for this change In support of adding `arrow.array.Date64Array`, this pull request adds a new `arrow.type.Date64Type` class and associated `arrow.date64` construction function to the MATLAB interface. ### What changes are included in this PR? 1. New `arrow.type.Date64Type` class. 2. New `arrow.date64` construction function that returns an `arrow.type.Date64Type` instance. 3. New `arrow.type.ID.Date64` type enumeration value. **Example** ```matlab >> type = arrow.date64() type = Date64Type with properties: ID: Date64 DateUnit: Millisecond ``` ### Are these changes tested? Yes. 1. Added a new `tDate64Type` test class. 2. Updated the `tID` test class to include `arrow.type.ID.Date64`. ### Are there any user-facing changes? Yes. 1. There is a new public `arrow.type.Date64Type` class. 2. There is a new public `arrow.date64` construction function. 3. There is a new `arrow.type.ID.Date64` type enumeration value. ### Future Directions 1. #37572 2. #37577 * Closes: #37230 Authored-by: Kevin Gurney <[email protected]> Signed-off-by: Kevin Gurney <[email protected]>
- Loading branch information
1 parent
d5cc9d9
commit 756a5d7
Showing
11 changed files
with
246 additions
and
3 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
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,31 @@ | ||
// 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/type/proxy/date64_type.h" | ||
|
||
namespace arrow::matlab::type::proxy { | ||
|
||
Date64Type::Date64Type(std::shared_ptr<arrow::Date64Type> date64_type) : DateType(std::move(date64_type)) {} | ||
|
||
libmexclass::proxy::MakeResult Date64Type::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) { | ||
using Date64TypeProxy = arrow::matlab::type::proxy::Date64Type; | ||
|
||
const auto type = arrow::date64(); | ||
const auto date64_type = std::static_pointer_cast<arrow::Date64Type>(type); | ||
return std::make_shared<Date64TypeProxy>(std::move(date64_type)); | ||
} | ||
} |
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,36 @@ | ||
// 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. | ||
|
||
#pragma once | ||
|
||
#include "arrow/matlab/type/proxy/date_type.h" | ||
|
||
namespace arrow::matlab::type::proxy { | ||
|
||
class Date64Type : public arrow::matlab::type::proxy::DateType { | ||
|
||
public: | ||
Date64Type(std::shared_ptr<arrow::Date64Type> date64_type); | ||
|
||
~Date64Type() {} | ||
|
||
static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments); | ||
|
||
}; | ||
|
||
} | ||
|
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,33 @@ | ||
%DATE64TYPE Type class for date64 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. | ||
% 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 Date64Type < arrow.type.DateType | ||
|
||
methods | ||
|
||
function obj = Date64Type(proxy) | ||
arguments | ||
proxy(1, 1) libmexclass.proxy.Proxy {validate(proxy, "arrow.type.proxy.Date64Type")} | ||
end | ||
import arrow.internal.proxy.validate | ||
|
||
[email protected](proxy); | ||
end | ||
|
||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
%DATE64 Creates an arrow.type.Date64Type object | ||
|
||
% 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 type = date64() | ||
proxy = arrow.internal.proxy.create("arrow.type.proxy.Date64Type"); | ||
type = arrow.type.Date64Type(proxy); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
% Test class for arrow.type.Date64Type and arrow.date64 | ||
|
||
% 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 tDate64Type < hFixedWidthType | ||
|
||
properties | ||
ConstructionFcn = @arrow.date64 | ||
ArrowType = arrow.date64 | ||
TypeID = arrow.type.ID.Date64 | ||
BitWidth = int32(64) | ||
ClassName = "arrow.type.Date64Type" | ||
end | ||
|
||
methods(Test) | ||
function TestClass(testCase) | ||
% Verify ArrowType is an object of the expected class type. | ||
name = string(class(testCase.ArrowType)); | ||
testCase.verifyEqual(name, testCase.ClassName); | ||
end | ||
|
||
function DefaultDateUnit(testCase) | ||
% Verify the default DateUnit is Millisecond. | ||
type = testCase.ArrowType; | ||
actualUnit = type.DateUnit; | ||
expectedUnit = arrow.type.DateUnit.Millisecond; | ||
testCase.verifyEqual(actualUnit, expectedUnit); | ||
end | ||
|
||
function Display(testCase) | ||
% Verify the display of Date64Type objects. | ||
% | ||
% Example: | ||
% | ||
% Date32Type with properties: | ||
% | ||
% ID: Date64 | ||
% DateUnit: Millisecond | ||
% | ||
type = testCase.ConstructionFcn(); %#ok<NASGU> | ||
classnameLink = "<a href=""matlab:helpPopup arrow.type.Date64Type"" style=""font-weight:bold"">Date64Type</a>"; | ||
header = " " + classnameLink + " with properties:" + newline; | ||
body = strjust(pad(["ID:"; "DateUnit:"])); | ||
body = body + " " + ["Date64"; "Millisecond"]; | ||
body = " " + body; | ||
footer = string(newline); | ||
expectedDisplay = char(strjoin([header body' footer], newline)); | ||
actualDisplay = evalc('disp(type)'); | ||
testCase.verifyEqual(actualDisplay, expectedDisplay); | ||
end | ||
|
||
function DateUnitNoSetter(testCase) | ||
% Verify that an error is thrown when trying to set the value | ||
% of the DateUnit property. | ||
type = arrow.date64(); | ||
testCase.verifyError(@() setfield(type, "DateUnit", "Day"), "MATLAB:class:SetProhibited"); | ||
end | ||
|
||
function InvalidProxy(testCase) | ||
% Verify that an error is thrown when a Proxy of an unexpected | ||
% type is passed to the arrow.type.Date64Type constructor. | ||
array = arrow.array([1, 2, 3]); | ||
proxy = array.Proxy; | ||
testCase.verifyError(@() arrow.type.Date64Type(proxy), "arrow:proxy:ProxyNameMismatch"); | ||
end | ||
|
||
function IsEqualTrue(testCase) | ||
% Verifies isequal method of arrow.type.Date64Type returns true if | ||
% these conditions are met: | ||
% | ||
% 1. All input arguments have a class type arrow.type.Date64Type | ||
% 2. All inputs have the same size | ||
|
||
% Scalar Date64Type arrays | ||
date64Type1 = arrow.date64(); | ||
date64Type2 = arrow.date64(); | ||
testCase.verifyTrue(isequal(date64Type1, date64Type2)); | ||
|
||
% Non-scalar Date64Type arrays | ||
typeArray1 = [date64Type1 date64Type1]; | ||
typeArray2 = [date64Type2 date64Type2]; | ||
testCase.verifyTrue(isequal(typeArray1, typeArray2)); | ||
end | ||
|
||
function IsEqualFalse(testCase) | ||
% Verifies the isequal method of arrow.type.Date64Type returns | ||
% false when expected. | ||
|
||
% Pass a different arrow.type.Type subclass to isequal | ||
date64Type = arrow.date64(); | ||
int32Type = arrow.int32(); | ||
testCase.verifyFalse(isequal(date64Type, int32Type)); | ||
testCase.verifyFalse(isequal([date64Type date64Type], [int32Type int32Type])); | ||
|
||
% Date64Type arrays have different sizes | ||
typeArray1 = [date64Type date64Type]; | ||
typeArray2 = [date64Type date64Type]'; | ||
testCase.verifyFalse(isequal(typeArray1, typeArray2)); | ||
end | ||
|
||
end | ||
|
||
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