-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
use vctrs:::vec_order_locs() in group_by() and vctrs:::vec_order_radix() in arrange() #5808
Conversation
@DavisVaughan this does not seem to affect the tests, so presumably the tests don't take into account the C locale order thing. So we probably need more tests. |
Maybe # we can't just use vec_compare_proxy(data) because we need to apply
# direction for each column, so we get a list of proxies instead
# and then mimic vctrs:::order_proxy
#
# should really be map2(quosures, directions, ...)
proxies <- map2(data, directions, function(column, direction) {
proxy <- vec_proxy_order(column)
desc <- identical(direction, "desc")
if (is.data.frame(proxy)) {
proxy <- order(vec_order(proxy,
direction = direction,
na_value = if(desc) "smallest" else "largest"
))
} else if(desc) {
proxy <- desc(proxy)
}
proxy
})
exec("order", !!!unname(proxies), decreasing = FALSE, na.last = TRUE) |
you can do that with |
Let's go then :p |
again, using |
This helps #4962 |
split_id$loc <- new_list_of(split_id$loc, ptype = integer()) | ||
|
||
vec_slice(split_id, vec_order(split_id$key)) | ||
split_id <- vctrs:::vec_order_locs(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DavisVaughan will this change the behaviour of group_by()
? i.e. does it change the ordering of character vectors to always use the C locale?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
library(dplyr)
df <- tibble(g = c("a", "A", "B", "b"), x = 1:4)
df
#> # A tibble: 4 x 2
#> g x
#> <chr> <int>
#> 1 a 1
#> 2 A 2
#> 3 B 3
#> 4 b 4
# Master
df %>%
group_by(g) %>%
summarise(x = x)
#> # A tibble: 4 x 2
#> g x
#> <chr> <int>
#> 1 a 1
#> 2 A 2
#> 3 b 4
#> 4 B 3
# This PR
df %>%
group_by(g) %>%
summarise(x = x)
#> # A tibble: 4 x 2
#> g x
#> <chr> <int>
#> 1 A 2
#> 2 B 3
#> 3 a 1
#> 4 b 4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could have an option to eventually sort the grouping data after the fact if really we wanted to maintain bw compat ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
group_by()
could also get a .locale
argument? The groups would be created and sorted in the locale specified (again, defaulting to C), which you'd see the effects of when you do a summarise()
closes #4406
vs on master:
Created on 2021-03-10 by the reprex package (v0.3.0)