[ 
https://issues.apache.org/jira/browse/ARROW-15996?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17511259#comment-17511259
 ] 

Joris Van den Bossche edited comment on ARROW-15996 at 3/23/22, 1:29 PM:
-------------------------------------------------------------------------

You don't necessarily have to do the division yourself, as we can casting 
durations from one unit to the other is supported (and will take care of 
rounding / erroring if data is lost):

{code}
In [15]: pa.array([1000000, 2000000], 
pa.time64('us')).cast(pa.int64()).cast(pa.duration('us')).cast(pa.duration('s'))
Out[15]: 
<pyarrow.lib.DurationArray object at 0x7fc37dca76a0>
[
  1,
  2
]
{code}

The same will be true if you get the duration by subtracting two times, as that 
will also not necessarily result in a second resolution duration.


was (Author: jorisvandenbossche):
You don't necessarily have to do the division yourself, as we can casting 
durations from one unit to the other is supported (and will take care of 
rounding / erroring if data is lost):

{code}
In [15]: pa.array([1000000, 2000000], 
pa.time64('us')).cast(pa.int64()).cast(pa.duration('us')).cast(pa.duration('s'))
Out[15]: 
<pyarrow.lib.DurationArray object at 0x7fc37dca76a0>
[
  1,
  2
]
{code}

> [C++] Support casting from time32 and time64 to duration
> --------------------------------------------------------
>
>                 Key: ARROW-15996
>                 URL: https://issues.apache.org/jira/browse/ARROW-15996
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: C++
>            Reporter: Dragoș Moldovan-Grünfeld
>            Priority: Critical
>
> It would be really helpful if we could convert {{time32}} and {{time64}} to 
> {{duration}}. For example, it could simplify the implementation of some of 
> the R bindings (e.g. {{difftime}}). 
> {code:r}
> library(arrow, warn.conflicts = FALSE)
> a <- Array$create(32000L)
> a
> #> Array
> #> <int32>
> #> [
> #>   32000
> #> ]
> a$cast(time32())
> #> Array
> #> <time32[ms]>
> #> [
> #>   00:00:32.000
> #> ]
> a$cast(int64())$cast(time64())
> #> Array
> #> <time64[ns]>
> #> [
> #>   00:00:00.000032000
> #> ]
> a$cast(time32())$cast(duration())
> #> Error: NotImplemented: Unsupported cast from time32[ms] to duration using 
> function cast_duration
> a$cast(int64())$cast(time64())$cast(duration())
> #> Error: NotImplemented: Unsupported cast from time64[ns] to duration using 
> function cast_duration
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to