apache / apache/arrow

[R][C++] Discussion: Plans for date casting from int to support an origin option?

Open
#31,240 11 comments 0 reactions 0 assignees View on GitHub
Component: C++ Component: R Priority: Critical Type: enhancement
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 13h
Merged PRs (30d)
88

Description

2 questions:
- plans to support an origin option for int -> date32 casting?
- plans to support double -> date32 casting?
=======================
Currently the casting from integer to date works, but assumes epoch (1970-01-01) as the origin. 
```r

> a <- Array$create(32L)
> a$cast(date32())
Array

[
1970-02-02
]
```

Would it make sense to have an `origin` option that would allow the user to fine tune the casting? For example, in R the `base::as.Date()` function has such an argument
```r

> as.Date(32, origin = "1970-01-02")
[1] "1970-02-03"
```

We have a potential workaround in R (once we support date & duration arithmetic), but I was wondering if there might me more general interest for this.

A secondary aspect (as my R example shows) R support casting to date not only from integers, but also doubles. Would there be interesting in that? Need be I can split this into several tickets.

Are there any plans in either of these 2 directions?

**Reporter**: [Dragoș Moldovan-Grünfeld](https://issues.apache.org/jira/browse/ARROW-15798) / @dragosmg
**Watchers**: [Rok Mihevc](https://issues.apache.org/jira/browse/ARROW-15798) / @rok
#### Related issues:
- [[R] Update as.Date() to support direct casting from double/float](https://github.com/apache/arrow/issues/31248) (is depended upon by)
- [[R] Update as.Date() to support an origin different from epoch](https://github.com/apache/arrow/issues/31241) (is depended upon by)

**Note**: *This issue was originally created as [ARROW-15798](https://issues.apache.org/jira/browse/ARROW-15798). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the R examples using Array$create(), date32(), and base::as.Date(), then read related issues #31248 and #31241. The work needs an agreed scope for origin-aware integer casting and double-to-date32 casting before implementation can be considered done.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, r
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.