You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "Dragoș Moldovan-Grünfeld (Jira)" <ji...@apache.org> on 2022/02/16 13:27:00 UTC
[jira] [Created] (ARROW-15701) [C++][R] Should month allow integer inputs?
Dragoș Moldovan-Grünfeld created ARROW-15701:
------------------------------------------------
Summary: [C++][R] Should month allow integer inputs?
Key: ARROW-15701
URL: https://issues.apache.org/jira/browse/ARROW-15701
Project: Apache Arrow
Issue Type: Bug
Components: C++, R
Reporter: Dragoș Moldovan-Grünfeld
In R, more specifically in {{{}lubridate{}}}, {{month()}} can be used both to get and set the corresponding component of a date. This means {{month()}} accepts integer inputs.
{code:r}
suppressPackageStartupMessages(library(lubridate))
month(1:12)
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12
month(1:13)
#> Error in month.numeric(1:13): Values are not in 1:12
{code}
Solving this would allow us to implement bindings such as `semester()` in a manner closer to {{{}lubridate{}}}.
{code:r}
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(lubridate))
test_df <- tibble(
month_as_int = c(1:12, NA),
month_as_char_pad = ifelse(month_as_int < 10, paste0("0", month_as_int), month_as_int),
dates = as.Date(paste0("2021-", month_as_char_pad, "-15"))
)
test_df %>%
mutate(
sem_date = semester(dates),
sem_month_as_int = semester(month_as_int))
#> # A tibble: 13 × 5
#> month_as_int month_as_char_pad dates sem_date sem_month_as_int
#> <int> <chr> <date> <int> <int>
#> 1 1 01 2021-01-15 1 1
#> 2 2 02 2021-02-15 1 1
#> 3 3 03 2021-03-15 1 1
#> 4 4 04 2021-04-15 1 1
#> 5 5 05 2021-05-15 1 1
#> 6 6 06 2021-06-15 1 1
#> 7 7 07 2021-07-15 2 2
#> 8 8 08 2021-08-15 2 2
#> 9 9 09 2021-09-15 2 2
#> 10 10 10 2021-10-15 2 2
#> 11 11 11 2021-11-15 2 2
#> 12 12 12 2021-12-15 2 2
#> 13 NA <NA> NA NA NA
{code}
Currently attempts to use {{month()}} with integer inputs errors with:
{code:r}
Function 'month' has no kernel matching input types (array[int32])
{code}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)