[ https://issues.apache.org/jira/browse/ARROW-15858?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17511742#comment-17511742 ]
Dragoș Moldovan-Grünfeld commented on ARROW-15858: -------------------------------------------------- We can go via {{{}int64(){}}}, so not sure how to/ if we need to make this more robust. {code:r} library(arrow, warn.conflicts = FALSE) a <- as.difftime(32L, units = "secs") a #> Time difference of 32 secs Array$create(a) #> Array #> <int32> #> [ #> 32 #> ] Array$create(a, type = int64())$cast(duration("s")) #> Array #> <duration[s]> #> [ #> 32 #> ] {code} > [C++][R] Can't cast integer difftime to duration (but works with double) > ------------------------------------------------------------------------ > > Key: ARROW-15858 > URL: https://issues.apache.org/jira/browse/ARROW-15858 > Project: Apache Arrow > Issue Type: Bug > Components: C++, R > Reporter: Dragoș Moldovan-Grünfeld > Priority: Critical > > It's possible to cast doubles to durations, but not integers. This has been > found in the R code via the issues below: > The shortest reprex I can make is as follows: > {code:r} > # Successfully cast a double to a duration > vec_to_Array(as.difftime(32, units = "secs"), NULL)$cast(duration()) > #> Array > #> <duration[s]> > #> [ > #> 32 > #> ] > # Fail to do so with an integer > vec_to_Array(as.difftime(32L, units = "secs"), NULL)$cast(duration()) > #> Error: NotImplemented: Unsupported cast from int32 to duration using > function cast_duration > {code} > ---------------------------------------------------------------------------- > I would expect both {{a}} and {{b}} to create a {{duration}} object of 32 > seconds, but the second one returns an {{int32}} > {code:r} > library(arrow, warn.conflicts = FALSE) > a <- as.difftime(32, units = "secs") # i.e. a double > b <- as.difftime(32L, units = "secs") # i.e. an integer > Array$create(a) > #> Array > #> <duration[s]> > #> [ > #> 32 > #> ] > Array$create(b) > #> Array > #> <int32> > #> [ > #> 32 > #> ] > {code} > If I try to be explicit, I get somewhat of a clue why that might be happening: > {code:r} > > Array$create(a, type = duration()) > #> Array > #> <duration[s]> > #> [ > #> 32 > #> ] > Array$create(b, type = duration()) > #> Error: > #> ! NotImplemented: Extend > {code} > Nevertheless, the fallback to creating an integer was unexpected. -- This message was sent by Atlassian Jira (v8.20.1#820001)