jorisvandenbossche commented on a change in pull request #10507:
URL: https://github.com/apache/arrow/pull/10507#discussion_r649723619



##########
File path: r/R/dplyr-functions.R
##########
@@ -442,3 +442,37 @@ nse_funcs$strptime <- function(x, format = "%Y-%m-%d 
%H:%M:%S", tz = NULL, unit
 
   Expression$create("strptime", x, options = list(format = format, unit = 
unit))
 }
+
+nse_funcs$wday <- function(x, label = FALSE, abbr = TRUE, week_start = 
getOption("lubridate.week.start", 7)) {
+  if (label) {
+    arrow_not_supported("Label argument")
+  }
+  offset <- get_date_offset(week_start)
+  Expression$create("add", Expression$create("day_of_week", x), 
Expression$scalar(offset))
+}
+
+#' Get date offset
+#' 
+#' Arrow's `day_of_week` kernel counts from 0 (Monday) to 6 (Sunday), whereas
+#' `lubridate::wday` counts from 1 to 7, and allows users to specify which day
+#' of the week is first (Sunday by default).  This function converts the 
returned

Review comment:
       I was going to mention that we actually also have an "ISO weekday" in 
the C++ kernels, but only as field in the `iso_calendar` kernel, and not as 
separate one. We could also add `iso_day_of_week` if that helps, or even just 
make `day_of_week` follow the ISO conventions. Because the 0 (monday) - 6 
(sunday) might be something Python specific.
   
   But then looked at what C++ does, and there the default is actually 0 
(sunday) - 6 (saturday), so yet something else ;) (although I see that also 
Postgres uses that for `dow`)
   
   In the end, once you have it in one form, it's an easy conversion to any of 
the other of course, so it might not matter that much.
   
   

##########
File path: r/R/expression.R
##########
@@ -28,8 +28,17 @@
   # stringr spellings of those
   "str_length" = "utf8_length",
   "str_to_lower" = "utf8_lower",
-  "str_to_upper" = "utf8_upper"
+  "str_to_upper" = "utf8_upper",
   # str_trim is defined in dplyr.R
+  "year" = "year",
+  "isoyear" = "iso_year",
+  "quarter" = "quarter",
+  "month" = "month",
+  "day" = "day",
+  "yday" = "day_of_year",
+  "isoweek" = "iso_week",
+  "minute" = "minute",

Review comment:
       "hour" is missing here?

##########
File path: r/R/expression.R
##########
@@ -28,8 +28,17 @@
   # stringr spellings of those
   "str_length" = "utf8_length",
   "str_to_lower" = "utf8_lower",
-  "str_to_upper" = "utf8_upper"
+  "str_to_upper" = "utf8_upper",
   # str_trim is defined in dplyr.R
+  "year" = "year",
+  "isoyear" = "iso_year",
+  "quarter" = "quarter",
+  "month" = "month",
+  "day" = "day",
+  "yday" = "day_of_year",
+  "isoweek" = "iso_week",
+  "minute" = "minute",
+  "second" = "second"

Review comment:
       Note that second might do something different. I think "second" in 
lubridate is the equivalent of "second + subsecond" in arrow

##########
File path: r/R/expression.R
##########
@@ -28,8 +28,17 @@
   # stringr spellings of those
   "str_length" = "utf8_length",
   "str_to_lower" = "utf8_lower",
-  "str_to_upper" = "utf8_upper"
+  "str_to_upper" = "utf8_upper",
   # str_trim is defined in dplyr.R
+  "year" = "year",
+  "isoyear" = "iso_year",
+  "quarter" = "quarter",
+  "month" = "month",
+  "day" = "day",
+  "yday" = "day_of_year",
+  "isoweek" = "iso_week",
+  "minute" = "minute",
+  "second" = "second"

Review comment:
       What do you mean exactly with rounding? A quick try gives me:
   
   ```
   > second(ymd_hms("2011-06-04 12:00:01.123456"))
   [1] 1.123456
   ```
   
   which seems to give all decimals

##########
File path: r/R/expression.R
##########
@@ -28,8 +28,17 @@
   # stringr spellings of those
   "str_length" = "utf8_length",
   "str_to_lower" = "utf8_lower",
-  "str_to_upper" = "utf8_upper"
+  "str_to_upper" = "utf8_upper",
   # str_trim is defined in dplyr.R
+  "year" = "year",
+  "isoyear" = "iso_year",
+  "quarter" = "quarter",
+  "month" = "month",
+  "day" = "day",
+  "yday" = "day_of_year",
+  "isoweek" = "iso_week",
+  "minute" = "minute",
+  "second" = "second"

Review comment:
       I don't think lubridate / R supports nanosecond resolution




-- 
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to