Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
ARROW-13022: [R] bindings for lubridate's year, isoyear, quarter, month, day, wday, yday, isoweek, hour, minute, and second functions#10507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
475962a51f3acaa4bd4b85621cd6ab8abfd4803b8b7539b76c6e20b2e66ac3d08d44baa98623f942e92f86af140583a996e8d7a5fbc0f8517390eaa9452071fb4bc02f08cfdc5719c030ce4c5aFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -29,8 +29,19 @@ | ||
| # stringr spellings of those | ||
| "str_length" = "utf8_length", | ||
| "str_to_lower" = "utf8_lower", | ||
| "str_to_upper" = "utf8_upper" | ||
| # str_trim is defined in dplyr.R | ||
| "str_to_upper" = "utf8_upper", | ||
| # str_trim is defined in dplyr-functions.R | ||
| "year" = "year", | ||
| "isoyear" = "iso_year", | ||
| "quarter" = "quarter", | ||
| "month" = "month", | ||
| "isoweek" = "iso_week", | ||
| "day" = "day", | ||
| # wday is defined in dplyr-functions.R | ||
| "yday" = "day_of_year", | ||
| "hour" = "hour", | ||
| # second is defined in dplyr-functions.R | ||
| "minute" = "minute" | ||
nealrichardson marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ) | ||
| .binary_function_map <- list( | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| # 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) | ||
| # We can support this feature after ARROW-12980 is merged | ||
| test_that("timezone aware timestamps are not supported",{ | ||
| tz_aware_date <- as.POSIXct("2017-01-01 00:00:12.3456789", tz = "BST") | ||
| tz_aware_df <- tibble::tibble(date = tz_aware_date) | ||
| expect_error( | ||
| Table$create(tz_aware_df) %>% | ||
| mutate(x = wday(date)) %>% | ||
| collect(), | ||
| "Cannot extract components from timestamp with specific timezone" | ||
nealrichardson marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ) | ||
| }) | ||
| # We can support this feature when ARROW-13138 is resolved | ||
| 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" | ||
nealrichardson marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ) | ||
| }) | ||
nealrichardson marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
nealrichardson marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| test_that("extract year from date", { | ||
| expect_dplyr_equal( | ||
| input %>% | ||
| mutate(x = year(date)) %>% | ||
| collect(), | ||
| test_df, | ||
| check.tzone = FALSE | ||
| ) | ||
| }) | ||
| test_that("extract isoyear from date", { | ||
| expect_dplyr_equal( | ||
| input %>% | ||
| mutate(x = isoyear(date)) %>% | ||
| collect(), | ||
| test_df | ||
| ) | ||
| }) | ||
| test_that("extract quarter from date", { | ||
| expect_dplyr_equal( | ||
| input %>% | ||
| mutate(x = quarter(date)) %>% | ||
| collect(), | ||
| test_df | ||
| ) | ||
| }) | ||
| test_that("extract month from date", { | ||
| expect_dplyr_equal( | ||
| input %>% | ||
| mutate(x = month(date)) %>% | ||
| collect(), | ||
| test_df | ||
| ) | ||
| }) | ||
| test_that("extract isoweek from date", { | ||
| expect_dplyr_equal( | ||
| input %>% | ||
| mutate(x = isoweek(date)) %>% | ||
| collect(), | ||
| test_df | ||
| ) | ||
| }) | ||
| test_that("extract day from date", { | ||
| expect_dplyr_equal( | ||
| input %>% | ||
| mutate(x = day(date)) %>% | ||
| collect(), | ||
| test_df | ||
| ) | ||
| }) | ||
| test_that("extract wday from date", { | ||
| expect_dplyr_equal( | ||
| input %>% | ||
| mutate(x = wday(date)) %>% | ||
| collect(), | ||
| test_df | ||
| ) | ||
| expect_dplyr_equal( | ||
| input %>% | ||
| mutate(x = wday(date, week_start = 3)) %>% | ||
| collect(), | ||
| test_df | ||
| ) | ||
| expect_dplyr_equal( | ||
| input %>% | ||
| mutate(x = wday(date, week_start = 1)) %>% | ||
| collect(), | ||
| test_df | ||
| ) | ||
| # We should be able to support the label argument after this ticket is resolved: | ||
| # https://issues.apache.org/jira/browse/ARROW-13133 | ||
| x <- Expression$field_ref("x") | ||
| expect_error( | ||
| nse_funcs$wday(x, label = TRUE), | ||
| "Label argument not supported by Arrow" | ||
| ) | ||
| }) | ||
| test_that("extract yday from date", { | ||
| expect_dplyr_equal( | ||
| input %>% | ||
| mutate(x = yday(date)) %>% | ||
| collect(), | ||
| test_df | ||
| ) | ||
| }) | ||
| test_that("extract hour from date", { | ||
| expect_dplyr_equal( | ||
| input %>% | ||
| mutate(x = hour(date)) %>% | ||
| collect(), | ||
| test_df | ||
| ) | ||
| }) | ||
| test_that("extract minute from date", { | ||
| expect_dplyr_equal( | ||
| input %>% | ||
| mutate(x = minute(date)) %>% | ||
| collect(), | ||
| test_df | ||
| ) | ||
| }) | ||
| test_that("extract second from date", { | ||
| expect_dplyr_equal( | ||
| input %>% | ||
| mutate(x = second(date)) %>% | ||
| collect(), | ||
| test_df, | ||
| # arrow supports nanosecond resolution but lubridate does not | ||
| tolerance = 1e-6 | ||
| ) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.