thisisnic commented on a change in pull request #10507: URL: https://github.com/apache/arrow/pull/10507#discussion_r655221384
########## 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") Review comment: The label argument allows the return of the day of the week in the correct language. In `lubridate`, there's a whole lot of work around defining the locale and then setting the weekday names appropriately, though essentially, it just uses the format function to extract the relevant date. I think that we wouldn't want to implement this at the C++ level as it doesn't feel like it fits there as it's doing quite a lot more work than calculating a value, (i.e. returning locale-specific dates), and we could still achieve this with good performance at the R level by implementing this functionality using the ifelse kernel once its R bindings are implemented. How about if I leave it as unsupported now, but create a ticket to implement it later, that lists the ifelse R binding as a dependency? ########## 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") Review comment: Thanks, will do! ########## 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") Review comment: https://issues.apache.org/jira/browse/ARROW-13133 ########## File path: r/tests/testthat/test-dplyr-lubridate.R ########## @@ -0,0 +1,160 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +library(lubridate) +library(dplyr) + +test_date <- as.POSIXct("2017-01-01 00:00:12.3456789", tz = "") +test_df <- tibble::tibble(date = test_date) + +tz_aware_date <- ymd_hms("2017-01-01 00:00:12.3456789") +tz_aware_df <- tibble::tibble(date = tz_aware_date) + +test_that("timezone aware timestamps are not supported",{ + x <- Expression$field_ref("x") + expect_error( + Table$create(tz_aware_df) %>% + mutate(x = wday(date)) %>% + collect(), + "Timezone aware timestamps not supported" + ) +}) Review comment: I added in the above test to demonstrate the current/expected behaviour, but I'm not totally happy with this. I'm not sure what makes sense to do here. I need to properly catch up on the mailing list discussion on timezone aware timestamps to work out the likely possibilities and solutions, so will come back to this, but not happy with it as-is at the moment. ########## File path: r/tests/testthat/test-dplyr-lubridate.R ########## @@ -0,0 +1,175 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +library(lubridate) +library(dplyr) + +test_date <- as.POSIXct("2017-01-01 00:00:12.3456789", tz = "") +test_df <- tibble::tibble(date = test_date) + +test_that("timezone aware timestamps are not supported",{ + + tz_aware_date <- ymd_hms("2017-01-01") + tz_aware_df <- tibble::tibble(date = tz_aware_date) + + x <- Expression$field_ref("x") + expect_error( + Table$create(tz_aware_df) %>% + mutate(x = wday(date)) %>% + collect(), + "Timezone aware timestamps not supported" + ) +}) + +test_that("date32 objects are not supported",{ + + date <- ymd("2017-01-01") + df <- tibble::tibble(date = date) + + expect_error( + Table$create(df) %>% + mutate(x = year(date)) %>% + collect(), + "Function year has no kernel matching input types" + ) +}) + Review comment: Will open a JIRA to implement for these object types. ########## File path: r/tests/testthat/test-dplyr-lubridate.R ########## @@ -0,0 +1,160 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +library(lubridate) +library(dplyr) + +test_date <- as.POSIXct("2017-01-01 00:00:12.3456789", tz = "") +test_df <- tibble::tibble(date = test_date) + +tz_aware_date <- ymd_hms("2017-01-01 00:00:12.3456789") +tz_aware_df <- tibble::tibble(date = tz_aware_date) + +test_that("timezone aware timestamps are not supported",{ + x <- Expression$field_ref("x") + expect_error( + Table$create(tz_aware_df) %>% + mutate(x = wday(date)) %>% + collect(), + "Timezone aware timestamps not supported" + ) +}) Review comment: Not entirely sure, but I think when this is merged, it will allow the above issue to be resolved: https://issues.apache.org/jira/browse/ARROW-12980 ########## File path: r/tests/testthat/test-dplyr-lubridate.R ########## @@ -0,0 +1,175 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +library(lubridate) +library(dplyr) + +test_date <- as.POSIXct("2017-01-01 00:00:12.3456789", tz = "") +test_df <- tibble::tibble(date = test_date) + +test_that("timezone aware timestamps are not supported",{ + + tz_aware_date <- ymd_hms("2017-01-01") + tz_aware_df <- tibble::tibble(date = tz_aware_date) + + x <- Expression$field_ref("x") + expect_error( + Table$create(tz_aware_df) %>% + mutate(x = wday(date)) %>% + collect(), + "Timezone aware timestamps not supported" + ) +}) + +test_that("date32 objects are not supported",{ + + date <- ymd("2017-01-01") + df <- tibble::tibble(date = date) + + expect_error( + Table$create(df) %>% + mutate(x = year(date)) %>% + collect(), + "Function year has no kernel matching input types" + ) +}) + Review comment: https://issues.apache.org/jira/browse/ARROW-13138 -- 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