rok commented on code in PR #12154:
URL: https://github.com/apache/arrow/pull/12154#discussion_r843855659
##########
r/R/dplyr-funcs-datetime.R:
##########
@@ -166,6 +166,73 @@ register_bindings_datetime <- function() {
(inherits(x, "Expression") && x$type_id() %in% Type[c("TIMESTAMP")])
})
+ register_binding("round_date", function(x, unit = "second",
+ week_start =
getOption("lubridate.week.start", 7)) {
+ opts <- parse_period_unit(unit)
+ if (opts$unit == 7L) {
+ if (week_start == 7) { # Sunday
+ opts$week_starts_monday <- 0L
+ return(Expression$create("round_temporal", x, options = opts))
+
+ } else if (week_start == 1) { # Monday
+ opts$week_starts_monday <- 1L
+ return(Expression$create("round_temporal", x, options = opts))
+
+ } else { # other values of week_start
+
+ # create a duration object as an offset
+ shift <- build_expr(
+ "cast",
+ Scalar$create((as.integer(week_start) - 1L) * 86400L, int64()),
+ options = cast_options(to_type = duration(unit = "s"))
+ )
+
+ # add the offset, round, then subtract the offset
+ # [throws error: add_checked has no kernel for date32-array and
duration(s)-scalar]
+ interim <- build_expr("round_temporal", x + shift, options = opts)
+ return(interim - shift)
Review Comment:
Huh, that's
odd.`add_checked([date32/64](https://github.com/apache/arrow/blob/master/cpp/src/arrow/compute/kernels/scalar_temporal_test.cc#L1054-L1080)/[timestamp](https://github.com/apache/arrow/blob/master/cpp/src/arrow/compute/kernels/scalar_temporal_test.cc#L1139-L1179),
duration)` should work.
You rebased so these should be available.. Error is for `add_checked(array,
scalar)`?
We can have a discussion about `bool week_starts_monday` vs `week_start` as
temporal kernels are still experimental :).
--
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]