You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Jonathan Keane (Jira)" <ji...@apache.org> on 2022/03/09 15:25:00 UTC

[jira] [Resolved] (ARROW-15701) [R] month() should allow integer inputs

     [ https://issues.apache.org/jira/browse/ARROW-15701?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jonathan Keane resolved ARROW-15701.
------------------------------------
    Fix Version/s: 8.0.0
       Resolution: Fixed

Issue resolved by pull request 12482
[https://github.com/apache/arrow/pull/12482]

> [R] month() should allow integer inputs
> ---------------------------------------
>
>                 Key: ARROW-15701
>                 URL: https://issues.apache.org/jira/browse/ARROW-15701
>             Project: Apache Arrow
>          Issue Type: Sub-task
>          Components: R
>            Reporter: Dragoș Moldovan-Grünfeld
>            Assignee: Dragoș Moldovan-Grünfeld
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 8.0.0
>
>          Time Spent: 2h
>  Remaining Estimate: 0h
>
> *Conclusion*: we will implement this in the R bindings - month will allow integer input: {{month(int)}} will return {{int}} as long as {{int}} is between 1 and 12.
> ==================================
> 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)