-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Closed
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
475962a
Add functions for extracting time/date components
thisisnic 51f3aca
Implement day_of_week so it matches lubridate::wday
thisisnic a4bd4b8
Sort out spacing
thisisnic 5621cd6
Add bindings for hour
thisisnic ab8abfd
Add in implementation of second, update offset func, separate tests
thisisnic 4803b8b
Entirely refactor wday formulation so it is achievable via Expressions
thisisnic 7539b76
Separate out tests and add an extra week_start one
thisisnic c6e20b2
Call nse_func directly when expecting an error
thisisnic e66ac3d
Add test for if there is a timezone aware timestamp
thisisnic 08d44ba
Can't extract date from date32
thisisnic a98623f
Fix test
thisisnic 942e92f
Update error message
thisisnic 86af140
Rearrange and tidy comments
thisisnic 583a996
Remove unnecessary field ref creation
thisisnic e8d7a5f
Add comment that certain functions defined in dplyr-functions.R
thisisnic bc0f851
Massively simplify arrow::wday -> lubridate::wday code
thisisnic 7390eaa
Add link to ticket that affects supporting label arg
thisisnic 9452071
Simplify expression further
thisisnic fb4bc02
Simplyify further
thisisnic f08cfdc
Reference correct file
thisisnic 5719c03
Add ticket numbers to unsupported features
thisisnic 0ce4c5a
Update r/R/dplyr-functions.R
thisisnic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Show resolved
Hide resolved
|
||
| ) | ||
| }) | ||
|
|
||
| # 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.
Show resolved
Hide resolved
|
||
| ) | ||
| }) | ||
nealrichardson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
nealrichardson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
| ) | ||
| }) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.