Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MATLAB] Add arrow.type.Date64Type class and arrow.date64 construction function #37230

Closed
kevingurney opened this issue Aug 17, 2023 · 0 comments · Fixed by #37578
Closed

[MATLAB] Add arrow.type.Date64Type class and arrow.date64 construction function #37230

kevingurney opened this issue Aug 17, 2023 · 0 comments · Fixed by #37578

Comments

@kevingurney
Copy link
Member

Describe the enhancement requested

To add support for arrow.array.Date64Array, we will need to add support for a arrow.type.Date64Type class and associated arrow.date64 construction function to the MATLAB interface.

Component(s)

MATLAB

kevingurney added a commit that referenced this issue Aug 18, 2023
…#37236)

### Rationale for this change

To simplify the implementation of `Time32Type`, `Time64Type`, `Date32Type`, and `Date64Type`, it would be helpful to create an abstract `arrow.type.TemporalType` class that the date and time types can inherit from.

As a first step, we can modify the implementation of `TimestampType` to inherit from `TemporalType`.

This mimics the class inheritance hierarchy from the C++ libraries.

### What changes are included in this PR?

1. Added a new MATLAB class called `arrow.type.TemporalType`. It inherits from `arrow.type.FixedWidthType` and defines one read-only property: `TimeUnit`.
2. Modified the MATLAB class `arrow.type.TimestampType` to inherit from `arrow.type.TemporalType` instead of `arrow.type.FixedWidthType`.
3. Renamed the  C++ `proxy::TimestampType` methods `timeUnit()` and `timeZone()` to `getTimeUnit()` and `getTimeZone()`.

### Are these changes tested?

Yes. The existing tests in `tTimetampType.m` cover these changes.

### Are there any user-facing changes?

No.

### Future Directions

1. Add `arrow.type.Time32Type` (#37231)
2. Add `arrow.type.Time64Type` (#37225)
3. Add `arrow.type.Date32Type` (#37229), 
4. Add `arrow.type.Time64Type` (#37230).
5. Add `arrow.array.Time32Array`
6. Add `arrow.array.Time64Array`
7. Add `arrow.array.Date32Array`
8. Add `arrow.array.Date64Array`
* Closes: #37234

Lead-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Co-authored-by: Kevin Gurney <kgurney@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
kevingurney added a commit that referenced this issue Aug 18, 2023
…2` construction function (#37250)

### Rationale for this change

To support the addition of `arrow.array.Time32Array`, this pull request adds a new `arrow.type.Time32Type` class and associated `arrow.time32` construction function to the MATLAB interface.

### What changes are included in this PR?

1. New `arrow.type.Time32Type` class.
2. New `arrow.time32` construction function that returns an `arrow.type.Time32Type` instance.

**Example**

```matlab
>> type = arrow.time32(TimeUnit="Millisecond")

type = 

  Time32Type with properties:

          ID: Time32
    TimeUnit: Millisecond

>> class(type)

ans =

    'arrow.type.Time32Type'
```

### Are these changes tested?

Yes.

1. Added new tests for `Time32` type ID enumeration to `tID`.
2. Added a test class `tTimeUnit` for the new validation function `arrow.internal.validate.temporal.timeUnit`.
4. Added a new test class `tTime32Type`.

### Are there any user-facing changes?

Yes.

There are two new user-facing APIs:

1. `arrow.time32` construction function
2. `arrow.type.Time32Type` class

### Future Directions:

1. #37232
2. #37229
3.  #37230
4. #37251

### Notes

1. Thank you @ sgilmore10 for your help with this pull request!
* Closes: #37231

Lead-authored-by: Kevin Gurney <kgurney@mathworks.com>
Co-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
kevingurney pushed a commit that referenced this issue Aug 21, 2023
### Rationale for this change

The original motivation for adding the super-class `arrow.type.TemporalType` in #37236 was to define a common implementation for extracting the `Unit` property from `TimestampType`, `Time32Type`, `Time64Type`, `Date32Type`, and `Date64Type`. However, this approach doesn't work because the `Unit` property on `Date32Type` and `Date64Type` is a `DateUnit`, while the `Unit` property on the other three types is a`TimeUnit`. As a result, we cannot define a shared method for extracting the `Unit` property in `TemporalType`. 

Instead, we plan on making `arrow.type.TemporalType` a "tag"-class (i.e. it has no properties or methods) so it can be used to group the "temporal" types together to ease authoring conditional logical in client code. In a future PR, we plan on adding functions like `arrow.type.isTemporal`, `arrow.type.isNumeric`, etc. so that clients don't need to query the class type information directly (i.e. call `isa(type, "arrow.type.TemporalType")`). 

```matlab
function doStuff(arrowArray)
  import arrow.*

  arrowType = arrowArray.Type;
  if type.isTemporal(arrowType)
      ...
  else if type.isNumeric(arrowType)
      ...
  else 
      ...
  end
end
```

### What changes are included in this PR?

1. Removed the `TimeUnit` property from `arrow.type.TemporalType`
2. Added `TimeUnit` back as a property on `arrow.type.TimestampType` and `arrow.type.Time32Type`

### Are these changes tested?

Yes, the existing tests cover these changes.

### Are there any user-facing changes?

No.

### Future Directions
1. #37232
2. #37229
3. #37230

* Closes: #37251

Authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
kevingurney pushed a commit that referenced this issue Aug 21, 2023
…#37279)

### Rationale for this change

To reduce code duplication within `Time32Type` and `Time64Type`, we should add an abstract class called `arrow.type.TimeType` that implements  the getter method for the `TimeUnit` property. This class hierarchy will mirror the class hierarchy in the C++ arrow implementation.

### What changes are included in this PR?

1. Defined a new C++ proxy class for called `arrow::matlab::type::proxy::TimeType`. This class defines a `getTimeUnit` method.
2. Modified the C++ proxy class `Time32Type` to inherit from `arrow::matlab::type::proxy::TimeType`. Removed the `getTimeUnit` method from this class because it's now defined on `TimeType`.
3. Added a new MATLAB class called `arrow.type.TimeType`. It has one method: `get.TimeUnit`.
4. Modified `arrow.type.Time32Type` to inherit from `arrow.type.TimeType` and removed its `get.TimeUnit` method.

### Are these changes tested?

Yes, the existing tests cover these changes.

### Are there any user-facing changes?

No.

### Future Directions

1. #37232
2. #37229
3. #37230   
* Closes: #37262

Authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
kevingurney added a commit that referenced this issue Aug 21, 2023
### Rationale for this change

In support of adding  `arrow.type.Date32Type` and `arrow.type.Date64Type`, this pull request adds a `arrow.type.DateUnit` enumeration class mirroring the `arrow.type.TimeUnit` enumeration class.

`arrow.type.DateUnit` will have two values: `Day` and `Millisecond`.

### What changes are included in this PR?

1. Added a new enumeration class `arrow.type.DateUnit` which mirrors the `arrow.type.TimeUnit` enumeration class.

**Example**:

```matlab
>> day = arrow.type.DateUnit.Day

day = 

  DateUnit enumeration

    Day

>> millisecond = arrow.type.DateUnit.Millisecond

millisecond = 

  DateUnit enumeration

    Millisecond
```

### Are these changes tested?

Yes.

1. Added a new test class `tDateUnit` for `arrow.type.DateUnit` tests.
2. Updated code for `tTimeUnit` for consistency with `tDateUnit`.

### Are there any user-facing changes?

Yes.

1. There is now a new user-facing `arrow.type.DateUnit` enumeration class.

### Future Directions

1. Add an `arrow.internal.validate.temporal.dateUnit` helper function that mirrors `arrow.internal.validate.temporal.timeUnit`.
2. #37229
3. #37230
* Closes: #37252

Lead-authored-by: Kevin Gurney <kgurney@mathworks.com>
Co-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
@kevingurney kevingurney self-assigned this Aug 21, 2023
kevingurney pushed a commit that referenced this issue Aug 21, 2023
…4` construction function (#37287)

### Rationale for this change

To add support for `arrow.array.Time64Array`, we will need to add support for a `arrow.type.Time64Type` class and associated `arrow.time64` construction function to the MATLAB interface.

### What changes are included in this PR?

1. New `arrow.type.Time64Type` class.
2. New `arrow.time64` construction function that returns an `arrow.type.Time64Type` instance.

**Example**

```matlab
>> type = arrow.time64(TimeUnit="Nanosecond")

type = 

  Time64Type with properties:

          ID: Time64
    TimeUnit: Nanosecond

>> class(type)

ans =

    'arrow.type.Time64Type'
```

### Are these changes tested?

Yes.

1. Added a new test class `tTime64Type`.
2. Added new tests for `Time64` type ID enumeration to `tID`.

### Are there any user-facing changes?

Yes.

1. `arrow.time64` construction function
3. `arrow.type.Time64Type` class

### Future Directions

1. #37229
2. #37230 
3. Add `arrow.array.Time64Array` class  

* Closes: #37232

Authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
@kevingurney kevingurney removed their assignment Aug 22, 2023
kevingurney added a commit that referenced this issue Aug 23, 2023
…2` construction function (#37348)

### Rationale for this change

In support of adding `arrow.array.Date32Array`, this pull request adds a new `arrow.type.Date32Type` class and associated `arrow.date32` construction function to the MATLAB interface.

### What changes are included in this PR?

1. New `arrow.type.Date32Type` class.
2. New `arrow.date32` construction function that returns an `arrow.type.Date32Type` instance.
3. New `arrow.type.ID.Date32` type enumeration value.
4. Added an abstract `arrow.type.DateType` class which `arrow.type.Date32Type` inherits from. `arrow.type.Date64Type` will also inherit from this class to share the `DateUnit` property. This mirrors the implementation of the `Time32Type` and `Time64Type` classes inheriting from an abstract `arrow.type.TimeType` class to share the `TimeUnit` property.

**Example**

```matlab
>> type = arrow.date32()

type = 

  Date32Type with properties:

          ID: Date32
    DateUnit: Day
```

### Are these changes tested?

Yes.

1. Added a new `tDate32Type` test class.
2. Updated the `tID` test class to include `arrow.type.ID.Date32`. 

### Are there any user-facing changes?

Yes.

1. There is a new public `arrow.type.Date32Type` class.
2. There is a new public `arrow.date32` construction function.
3. There is a new `arrow.type.ID.Date32` type enumeration value.

### Future Directions

1. #37230
2. Add `arrow.array.Date32Array` class.
3. Add `arrow.array.Date64Array` class.
* Closes: #37229

Lead-authored-by: Kevin Gurney <kgurney@mathworks.com>
Co-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
kou pushed a commit that referenced this issue Aug 30, 2023
### Rationale for this change

Now that `arrow.type.Date32Type` class has been added to the MATLAB Interface (#37348), we can add the `arrow.array.Date32Array` class.

`Date32Array`s can be created from MATLAB [`datetime`](https://www.mathworks.com/help/matlab/ref/datetime.html) values. 

### What changes are included in this PR?

1. Added a new `arrow.array.Date32Array` class.
2. Added a new `arrow.type.traits.Date32Traits` class.
3. Added `arrow.type.Date32Type` support to `arrow.type.traits.traits` function.
4. Fixed typo `arrray` in `tTime32Array` test class.
5. Fixed bug in `numeric_array.h` where the `CType` rather than the `ArrowType` was being used to determine the `DataType` of an array class that is a `NumericArray<T>`.

`Date32Array`s can be created from MATLAB [`datetime`](https://www.mathworks.com/help/matlab/ref/datetime.html) values using the `fromMATLAB` method. `Date32Array`s can be converted to MATLAB `datetime` values using the `toMATLAB` method.

**Example**
```matlab
>> dates = [datetime(2021, 1, 2, 3, 4, 5), datetime(2023, 1, 1), datetime(1989, 2, 3, 10, 10, 10)]'

dates = 

  3x1 datetime array

   02-Jan-2021 03:04:05
   01-Jan-2023 00:00:00
   03-Feb-1989 10:10:10

>> array = arrow.array.Date32Array.fromMATLAB(dates)                                               

array = 

[
  2021-01-02,
  2023-01-01,
  1989-02-03
]

>> array.toMATLAB()                                                                                

ans = 

  3x1 datetime array

   02-Jan-2021
   01-Jan-2023
   03-Feb-1989
``` 

### Are these changes tested?

Yes.

1. Added a new `tDate32Array` test class.
2. Added `Date32` related test to `ttraits.m`.
6. Added a new `tDate32Traits.m` test class.

### Are there any user-facing changes?

Yes.

1. Users can now create `arrow.array.Date32Array`s  from MATLAB `datetime`s.

### Future Directions

1. #37230
2. Add `arrow.array.Date64Array`.
3. Add a way to extract the raw `int32` values from an `arrow.array.Date32Array` without converting to a MATLAB `datetime` using `toMATLAB`.

### Notes

1. Thank you @ sgilmore10 for your help with this pull request!
* Closes: #37367

Lead-authored-by: Kevin Gurney <kgurney@mathworks.com>
Co-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
@kevingurney kevingurney self-assigned this Sep 5, 2023
kevingurney added a commit that referenced this issue Sep 5, 2023
…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 <kgurney@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
@kevingurney kevingurney added this to the 14.0.0 milestone Sep 5, 2023
loicalleyne pushed a commit to loicalleyne/arrow that referenced this issue Nov 13, 2023
… class (apache#37236)

### Rationale for this change

To simplify the implementation of `Time32Type`, `Time64Type`, `Date32Type`, and `Date64Type`, it would be helpful to create an abstract `arrow.type.TemporalType` class that the date and time types can inherit from.

As a first step, we can modify the implementation of `TimestampType` to inherit from `TemporalType`.

This mimics the class inheritance hierarchy from the C++ libraries.

### What changes are included in this PR?

1. Added a new MATLAB class called `arrow.type.TemporalType`. It inherits from `arrow.type.FixedWidthType` and defines one read-only property: `TimeUnit`.
2. Modified the MATLAB class `arrow.type.TimestampType` to inherit from `arrow.type.TemporalType` instead of `arrow.type.FixedWidthType`.
3. Renamed the  C++ `proxy::TimestampType` methods `timeUnit()` and `timeZone()` to `getTimeUnit()` and `getTimeZone()`.

### Are these changes tested?

Yes. The existing tests in `tTimetampType.m` cover these changes.

### Are there any user-facing changes?

No.

### Future Directions

1. Add `arrow.type.Time32Type` (apache#37231)
2. Add `arrow.type.Time64Type` (apache#37225)
3. Add `arrow.type.Date32Type` (apache#37229), 
4. Add `arrow.type.Time64Type` (apache#37230).
5. Add `arrow.array.Time32Array`
6. Add `arrow.array.Time64Array`
7. Add `arrow.array.Date32Array`
8. Add `arrow.array.Date64Array`
* Closes: apache#37234

Lead-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Co-authored-by: Kevin Gurney <kgurney@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
loicalleyne pushed a commit to loicalleyne/arrow that referenced this issue Nov 13, 2023
….time32` construction function (apache#37250)

### Rationale for this change

To support the addition of `arrow.array.Time32Array`, this pull request adds a new `arrow.type.Time32Type` class and associated `arrow.time32` construction function to the MATLAB interface.

### What changes are included in this PR?

1. New `arrow.type.Time32Type` class.
2. New `arrow.time32` construction function that returns an `arrow.type.Time32Type` instance.

**Example**

```matlab
>> type = arrow.time32(TimeUnit="Millisecond")

type = 

  Time32Type with properties:

          ID: Time32
    TimeUnit: Millisecond

>> class(type)

ans =

    'arrow.type.Time32Type'
```

### Are these changes tested?

Yes.

1. Added new tests for `Time32` type ID enumeration to `tID`.
2. Added a test class `tTimeUnit` for the new validation function `arrow.internal.validate.temporal.timeUnit`.
4. Added a new test class `tTime32Type`.

### Are there any user-facing changes?

Yes.

There are two new user-facing APIs:

1. `arrow.time32` construction function
2. `arrow.type.Time32Type` class

### Future Directions:

1. apache#37232
2. apache#37229
3.  apache#37230
4. apache#37251

### Notes

1. Thank you @ sgilmore10 for your help with this pull request!
* Closes: apache#37231

Lead-authored-by: Kevin Gurney <kgurney@mathworks.com>
Co-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
loicalleyne pushed a commit to loicalleyne/arrow that referenced this issue Nov 13, 2023
…apache#37256)

### Rationale for this change

The original motivation for adding the super-class `arrow.type.TemporalType` in apache#37236 was to define a common implementation for extracting the `Unit` property from `TimestampType`, `Time32Type`, `Time64Type`, `Date32Type`, and `Date64Type`. However, this approach doesn't work because the `Unit` property on `Date32Type` and `Date64Type` is a `DateUnit`, while the `Unit` property on the other three types is a`TimeUnit`. As a result, we cannot define a shared method for extracting the `Unit` property in `TemporalType`. 

Instead, we plan on making `arrow.type.TemporalType` a "tag"-class (i.e. it has no properties or methods) so it can be used to group the "temporal" types together to ease authoring conditional logical in client code. In a future PR, we plan on adding functions like `arrow.type.isTemporal`, `arrow.type.isNumeric`, etc. so that clients don't need to query the class type information directly (i.e. call `isa(type, "arrow.type.TemporalType")`). 

```matlab
function doStuff(arrowArray)
  import arrow.*

  arrowType = arrowArray.Type;
  if type.isTemporal(arrowType)
      ...
  else if type.isNumeric(arrowType)
      ...
  else 
      ...
  end
end
```

### What changes are included in this PR?

1. Removed the `TimeUnit` property from `arrow.type.TemporalType`
2. Added `TimeUnit` back as a property on `arrow.type.TimestampType` and `arrow.type.Time32Type`

### Are these changes tested?

Yes, the existing tests cover these changes.

### Are there any user-facing changes?

No.

### Future Directions
1. apache#37232
2. apache#37229
3. apache#37230

* Closes: apache#37251

Authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
loicalleyne pushed a commit to loicalleyne/arrow that referenced this issue Nov 13, 2023
…eType` (apache#37279)

### Rationale for this change

To reduce code duplication within `Time32Type` and `Time64Type`, we should add an abstract class called `arrow.type.TimeType` that implements  the getter method for the `TimeUnit` property. This class hierarchy will mirror the class hierarchy in the C++ arrow implementation.

### What changes are included in this PR?

1. Defined a new C++ proxy class for called `arrow::matlab::type::proxy::TimeType`. This class defines a `getTimeUnit` method.
2. Modified the C++ proxy class `Time32Type` to inherit from `arrow::matlab::type::proxy::TimeType`. Removed the `getTimeUnit` method from this class because it's now defined on `TimeType`.
3. Added a new MATLAB class called `arrow.type.TimeType`. It has one method: `get.TimeUnit`.
4. Modified `arrow.type.Time32Type` to inherit from `arrow.type.TimeType` and removed its `get.TimeUnit` method.

### Are these changes tested?

Yes, the existing tests cover these changes.

### Are there any user-facing changes?

No.

### Future Directions

1. apache#37232
2. apache#37229
3. apache#37230   
* Closes: apache#37262

Authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
loicalleyne pushed a commit to loicalleyne/arrow that referenced this issue Nov 13, 2023
…pache#37280)

### Rationale for this change

In support of adding  `arrow.type.Date32Type` and `arrow.type.Date64Type`, this pull request adds a `arrow.type.DateUnit` enumeration class mirroring the `arrow.type.TimeUnit` enumeration class.

`arrow.type.DateUnit` will have two values: `Day` and `Millisecond`.

### What changes are included in this PR?

1. Added a new enumeration class `arrow.type.DateUnit` which mirrors the `arrow.type.TimeUnit` enumeration class.

**Example**:

```matlab
>> day = arrow.type.DateUnit.Day

day = 

  DateUnit enumeration

    Day

>> millisecond = arrow.type.DateUnit.Millisecond

millisecond = 

  DateUnit enumeration

    Millisecond
```

### Are these changes tested?

Yes.

1. Added a new test class `tDateUnit` for `arrow.type.DateUnit` tests.
2. Updated code for `tTimeUnit` for consistency with `tDateUnit`.

### Are there any user-facing changes?

Yes.

1. There is now a new user-facing `arrow.type.DateUnit` enumeration class.

### Future Directions

1. Add an `arrow.internal.validate.temporal.dateUnit` helper function that mirrors `arrow.internal.validate.temporal.timeUnit`.
2. apache#37229
3. apache#37230
* Closes: apache#37252

Lead-authored-by: Kevin Gurney <kgurney@mathworks.com>
Co-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
loicalleyne pushed a commit to loicalleyne/arrow that referenced this issue Nov 13, 2023
….time64` construction function (apache#37287)

### Rationale for this change

To add support for `arrow.array.Time64Array`, we will need to add support for a `arrow.type.Time64Type` class and associated `arrow.time64` construction function to the MATLAB interface.

### What changes are included in this PR?

1. New `arrow.type.Time64Type` class.
2. New `arrow.time64` construction function that returns an `arrow.type.Time64Type` instance.

**Example**

```matlab
>> type = arrow.time64(TimeUnit="Nanosecond")

type = 

  Time64Type with properties:

          ID: Time64
    TimeUnit: Nanosecond

>> class(type)

ans =

    'arrow.type.Time64Type'
```

### Are these changes tested?

Yes.

1. Added a new test class `tTime64Type`.
2. Added new tests for `Time64` type ID enumeration to `tID`.

### Are there any user-facing changes?

Yes.

1. `arrow.time64` construction function
3. `arrow.type.Time64Type` class

### Future Directions

1. apache#37229
2. apache#37230 
3. Add `arrow.array.Time64Array` class  

* Closes: apache#37232

Authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
loicalleyne pushed a commit to loicalleyne/arrow that referenced this issue Nov 13, 2023
….date32` construction function (apache#37348)

### Rationale for this change

In support of adding `arrow.array.Date32Array`, this pull request adds a new `arrow.type.Date32Type` class and associated `arrow.date32` construction function to the MATLAB interface.

### What changes are included in this PR?

1. New `arrow.type.Date32Type` class.
2. New `arrow.date32` construction function that returns an `arrow.type.Date32Type` instance.
3. New `arrow.type.ID.Date32` type enumeration value.
4. Added an abstract `arrow.type.DateType` class which `arrow.type.Date32Type` inherits from. `arrow.type.Date64Type` will also inherit from this class to share the `DateUnit` property. This mirrors the implementation of the `Time32Type` and `Time64Type` classes inheriting from an abstract `arrow.type.TimeType` class to share the `TimeUnit` property.

**Example**

```matlab
>> type = arrow.date32()

type = 

  Date32Type with properties:

          ID: Date32
    DateUnit: Day
```

### Are these changes tested?

Yes.

1. Added a new `tDate32Type` test class.
2. Updated the `tID` test class to include `arrow.type.ID.Date32`. 

### Are there any user-facing changes?

Yes.

1. There is a new public `arrow.type.Date32Type` class.
2. There is a new public `arrow.date32` construction function.
3. There is a new `arrow.type.ID.Date32` type enumeration value.

### Future Directions

1. apache#37230
2. Add `arrow.array.Date32Array` class.
3. Add `arrow.array.Date64Array` class.
* Closes: apache#37229

Lead-authored-by: Kevin Gurney <kgurney@mathworks.com>
Co-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
loicalleyne pushed a commit to loicalleyne/arrow that referenced this issue Nov 13, 2023
…37445)

### Rationale for this change

Now that `arrow.type.Date32Type` class has been added to the MATLAB Interface (apache#37348), we can add the `arrow.array.Date32Array` class.

`Date32Array`s can be created from MATLAB [`datetime`](https://www.mathworks.com/help/matlab/ref/datetime.html) values. 

### What changes are included in this PR?

1. Added a new `arrow.array.Date32Array` class.
2. Added a new `arrow.type.traits.Date32Traits` class.
3. Added `arrow.type.Date32Type` support to `arrow.type.traits.traits` function.
4. Fixed typo `arrray` in `tTime32Array` test class.
5. Fixed bug in `numeric_array.h` where the `CType` rather than the `ArrowType` was being used to determine the `DataType` of an array class that is a `NumericArray<T>`.

`Date32Array`s can be created from MATLAB [`datetime`](https://www.mathworks.com/help/matlab/ref/datetime.html) values using the `fromMATLAB` method. `Date32Array`s can be converted to MATLAB `datetime` values using the `toMATLAB` method.

**Example**
```matlab
>> dates = [datetime(2021, 1, 2, 3, 4, 5), datetime(2023, 1, 1), datetime(1989, 2, 3, 10, 10, 10)]'

dates = 

  3x1 datetime array

   02-Jan-2021 03:04:05
   01-Jan-2023 00:00:00
   03-Feb-1989 10:10:10

>> array = arrow.array.Date32Array.fromMATLAB(dates)                                               

array = 

[
  2021-01-02,
  2023-01-01,
  1989-02-03
]

>> array.toMATLAB()                                                                                

ans = 

  3x1 datetime array

   02-Jan-2021
   01-Jan-2023
   03-Feb-1989
``` 

### Are these changes tested?

Yes.

1. Added a new `tDate32Array` test class.
2. Added `Date32` related test to `ttraits.m`.
6. Added a new `tDate32Traits.m` test class.

### Are there any user-facing changes?

Yes.

1. Users can now create `arrow.array.Date32Array`s  from MATLAB `datetime`s.

### Future Directions

1. apache#37230
2. Add `arrow.array.Date64Array`.
3. Add a way to extract the raw `int32` values from an `arrow.array.Date32Array` without converting to a MATLAB `datetime` using `toMATLAB`.

### Notes

1. Thank you @ sgilmore10 for your help with this pull request!
* Closes: apache#37367

Lead-authored-by: Kevin Gurney <kgurney@mathworks.com>
Co-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
loicalleyne pushed a commit to loicalleyne/arrow that referenced this issue Nov 13, 2023
….date64` construction function (apache#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. apache#37572
2. apache#37577
* Closes: apache#37230

Authored-by: Kevin Gurney <kgurney@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
dgreiss pushed a commit to dgreiss/arrow that referenced this issue Feb 19, 2024
…37445)

### Rationale for this change

Now that `arrow.type.Date32Type` class has been added to the MATLAB Interface (apache#37348), we can add the `arrow.array.Date32Array` class.

`Date32Array`s can be created from MATLAB [`datetime`](https://www.mathworks.com/help/matlab/ref/datetime.html) values. 

### What changes are included in this PR?

1. Added a new `arrow.array.Date32Array` class.
2. Added a new `arrow.type.traits.Date32Traits` class.
3. Added `arrow.type.Date32Type` support to `arrow.type.traits.traits` function.
4. Fixed typo `arrray` in `tTime32Array` test class.
5. Fixed bug in `numeric_array.h` where the `CType` rather than the `ArrowType` was being used to determine the `DataType` of an array class that is a `NumericArray<T>`.

`Date32Array`s can be created from MATLAB [`datetime`](https://www.mathworks.com/help/matlab/ref/datetime.html) values using the `fromMATLAB` method. `Date32Array`s can be converted to MATLAB `datetime` values using the `toMATLAB` method.

**Example**
```matlab
>> dates = [datetime(2021, 1, 2, 3, 4, 5), datetime(2023, 1, 1), datetime(1989, 2, 3, 10, 10, 10)]'

dates = 

  3x1 datetime array

   02-Jan-2021 03:04:05
   01-Jan-2023 00:00:00
   03-Feb-1989 10:10:10

>> array = arrow.array.Date32Array.fromMATLAB(dates)                                               

array = 

[
  2021-01-02,
  2023-01-01,
  1989-02-03
]

>> array.toMATLAB()                                                                                

ans = 

  3x1 datetime array

   02-Jan-2021
   01-Jan-2023
   03-Feb-1989
``` 

### Are these changes tested?

Yes.

1. Added a new `tDate32Array` test class.
2. Added `Date32` related test to `ttraits.m`.
6. Added a new `tDate32Traits.m` test class.

### Are there any user-facing changes?

Yes.

1. Users can now create `arrow.array.Date32Array`s  from MATLAB `datetime`s.

### Future Directions

1. apache#37230
2. Add `arrow.array.Date64Array`.
3. Add a way to extract the raw `int32` values from an `arrow.array.Date32Array` without converting to a MATLAB `datetime` using `toMATLAB`.

### Notes

1. Thank you @ sgilmore10 for your help with this pull request!
* Closes: apache#37367

Lead-authored-by: Kevin Gurney <kgurney@mathworks.com>
Co-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
dgreiss pushed a commit to dgreiss/arrow that referenced this issue Feb 19, 2024
….date64` construction function (apache#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. apache#37572
2. apache#37577
* Closes: apache#37230

Authored-by: Kevin Gurney <kgurney@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
1 participant