dragosmg commented on a change in pull request #12707:
URL: https://github.com/apache/arrow/pull/12707#discussion_r837716368
##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -261,6 +261,20 @@ register_bindings_duration <- function() {
time2 <- build_expr("cast", time2, options = cast_options(to_type =
timestamp(timezone = "UTC")))
}
+ # if time1 or time2 are timestamps they cannot be expressed in "s" /seconds
+ # otherwise they cannot be added subtracted with durations
+ # TODO delete the casting to "us" once
+ # https://issues.apache.org/jira/browse/ARROW-16060 is solved
+ if (inherits(time1, "Expression") &&
+ time1$type_id() %in% Type[c("TIMESTAMP")] && time1$type()$unit() !=
2L) {
+ time1 <- build_expr("cast", time1, options = cast_options(to_type =
timestamp("us")))
+ }
+
+ if (inherits(time2, "Expression") &&
+ time2$type_id() %in% Type[c("TIMESTAMP")] && time2$type()$unit() !=
2L) {
+ time2 <- build_expr("cast", time2, options = cast_options(to_type =
timestamp("us")))
+ }
+
Review comment:
We do need them. They are used when we pass a `Date` to `decimal_date()`
which ultimately passes it down to `difftime` which ultimately calls `-` which
then errors.
```r
test_df <- tibble(
a = c(2007.38998954347, 1970.77732069883, 2020.96061799722,
2009.43465948477, 1975.71251467871, NA),
b = as.POSIXct(
c("2007-05-23 08:18:30", "1970-10-11 17:19:45", "2020-12-17 14:04:06",
"2009-06-08 15:37:01", "1975-09-18 01:37:42", NA)
),
c = as.Date(
c("2007-05-23", "1970-10-11", "2020-12-17", "2009-06-08",
"1975-09-18", NA)
)
)
test_df %>%
arrow_table() %>%
mutate(
decimal_date_from_date = decimal_date(c)
) %>%
collect()
Error in `handle_csv_read_error()` at r/R/dplyr-collect.R:33:6:
! NotImplemented: Function 'subtract_checked' has no kernel matching input
types (array[date32[day]], array[timestamp[s]])
(...)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]