Skip to content
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

GH-35534: [R] Ensure missing grouping variables are added to the beginning of the variable list #36305

Merged
merged 2 commits into from
Jun 27, 2023

Conversation

paleolimbot
Copy link
Member

@paleolimbot paleolimbot commented Jun 26, 2023

Rationale for this change

As reported by @eitsupi, dplyr adds missing grouping variables to the beginning of the variable list; however, we add them to the end of the variable list. Our general policy is to match dplyr's behaviour everywhere.

Before this PR:

library(arrow, warn.conflicts = FALSE)
#> Some features are not enabled in this build of Arrow. Run `arrow_info()` for more information.
library(dplyr, warn.conflicts = FALSE)

tibble::tibble(int = 1:4, chr = letters[1:4]) |> 
  group_by(chr) |> 
  select(int) |> 
  collect()
#> Adding missing grouping variables: `chr`
#> # A tibble: 4 × 2
#> # Groups:   chr [4]
#>   chr     int
#>   <chr> <int>
#> 1 a         1
#> 2 b         2
#> 3 c         3
#> 4 d         4

arrow_table(int = 1:4, chr = letters[1:4]) |> 
  group_by(chr) |> 
  select(int) |> 
  collect()
#> # A tibble: 4 × 2
#> # Groups:   chr [4]
#>     int chr  
#>   <int> <chr>
#> 1     1 a    
#> 2     2 b    
#> 3     3 c    
#> 4     4 d

After this PR:

library(arrow, warn.conflicts = FALSE)
#> Some features are not enabled in this build of Arrow. Run `arrow_info()` for more information.
library(dplyr, warn.conflicts = FALSE)

tibble::tibble(int = 1:4, chr = letters[1:4]) |> 
  group_by(chr) |> 
  select(int) |> 
  collect()
#> Adding missing grouping variables: `chr`
#> # A tibble: 4 × 2
#> # Groups:   chr [4]
#>   chr     int
#>   <chr> <int>
#> 1 a         1
#> 2 b         2
#> 3 c         3
#> 4 d         4

arrow_table(int = 1:4, chr = letters[1:4]) |> 
  group_by(chr) |> 
  select(int) |> 
  collect()
#> # A tibble: 4 × 2
#> # Groups:   chr [4]
#>   chr     int
#>   <chr> <int>
#> 1 a         1
#> 2 b         2
#> 3 c         3
#> 4 d         4

Are these changes tested?

Yes, a test was added.

Are there any user-facing changes?

Yes, column ordering will be different. This could be a breaking change because existing code that refers to columns by index may change; however, referring to a column by name is much more common.

@paleolimbot paleolimbot marked this pull request as draft June 26, 2023 14:43
@github-actions
Copy link

⚠️ GitHub issue #35534 has been automatically assigned in GitHub to PR creator.

@paleolimbot paleolimbot marked this pull request as ready for review June 26, 2023 17:02
Copy link
Member

@thisisnic thisisnic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for fixing this!

@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting committer review Awaiting committer review labels Jun 26, 2023
@paleolimbot paleolimbot merged commit 7de273b into apache:main Jun 27, 2023
13 checks passed
@paleolimbot paleolimbot removed the awaiting merge Awaiting merge label Jun 27, 2023
@conbench-apache-arrow
Copy link

Conbench analyzed the 6 benchmark runs on commit 7de273b4.

There was 1 benchmark result indicating a performance regression:

The full Conbench report has more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[R] Column order after group_by(foo) |> select(...) is different from dplyr
2 participants