nealrichardson commented on code in PR #13160:
URL: https://github.com/apache/arrow/pull/13160#discussion_r922108970
##########
r/tests/testthat/test-dplyr-funcs-string.R:
##########
@@ -23,6 +23,14 @@ library(lubridate)
library(stringr)
library(stringi)
+tbl <- example_data
+# Add some better string data
+tbl$verses <- verses[[1]]
+# c(" a ", " b ", " c ", ...) increasing padding
+# nchar = 3 5 7 9 11 13 15 17 19 21
+tbl$padded_strings <- stringr::str_pad(letters[1:10], width = 2 * (1:10) + 1,
side = "both")
+tbl$some_grouping <- rep(c(1, 2), 5)
+
Review Comment:
Why is this needed? Isn't this a copy of helper-data.R?
##########
r/tests/testthat/test-dplyr-mutate.R:
##########
@@ -140,17 +140,6 @@ test_that("transmute() with unsupported arguments", {
)
})
-test_that("transmute() defuses dots arguments (ARROW-13262)", {
Review Comment:
We should keep this test, right? Just change the function to something made
up maybe.
##########
r/R/dplyr-funcs.R:
##########
@@ -58,15 +58,27 @@ NULL
#' @keywords internal
#'
register_binding <- function(fun_name, fun, registry = nse_funcs) {
- name <- gsub("^.*?::", "", fun_name)
- namespace <- gsub("::.*$", "", fun_name)
+ qualified_name <- fun_name
Review Comment:
Why not just keep it as `fun_name`? It's kinda odd when the first line of a
function just renames the function argument.
##########
r/R/dplyr-funcs.R:
##########
@@ -58,15 +58,27 @@ NULL
#' @keywords internal
#'
register_binding <- function(fun_name, fun, registry = nse_funcs) {
- name <- gsub("^.*?::", "", fun_name)
- namespace <- gsub("::.*$", "", fun_name)
+ qualified_name <- fun_name
+ unqualified_name <- gsub("^.*?::", "", qualified_name)
- previous_fun <- if (name %in% names(registry)) registry[[name]] else NULL
+ previous_fun <- registry[[unqualified_name]]
- if (is.null(fun) && !is.null(previous_fun)) {
- rm(list = name, envir = registry, inherits = FALSE)
+ # if the unqualified name exists in the registry, warn
+ if (!is.null(fun) && !is.null(previous_fun)) {
+ warn(
+ paste0(
+ "A \"",
+ unqualified_name,
+ "\" binding already exists in the registry and will be overwritten.")
+ )
+ }
+
+ # register both as `pkg::fun` and as `fun` if `qualified_name` is prefixed
+ if (grepl("::", qualified_name) && qualified_name != "::") {
Review Comment:
```suggestion
if (grepl("::", qualified_name)) {
```
##########
r/R/dplyr-funcs.R:
##########
@@ -58,15 +58,27 @@ NULL
#' @keywords internal
#'
register_binding <- function(fun_name, fun, registry = nse_funcs) {
- name <- gsub("^.*?::", "", fun_name)
- namespace <- gsub("::.*$", "", fun_name)
+ qualified_name <- fun_name
+ unqualified_name <- gsub("^.*?::", "", qualified_name)
Review Comment:
Don't need global substitution, and use `:+` to remove both `::` and `:::`
```suggestion
unqualified_name <- sub("^.*?:+", "", fun_name)
```
##########
r/tests/testthat/test-dplyr-summarize.R:
##########
@@ -459,6 +482,35 @@ test_that("quantile()", {
)
})
+test_that("quantile() with namespacing", {
+ suppressWarnings(
+ expect_warning(
+ expect_equal(
+ tbl %>%
+ group_by(some_grouping) %>%
+ summarize(
+ q_dbl = quantile(dbl, probs = 0.5, na.rm = TRUE, names = FALSE),
+ q_int = as.double(
+ quantile(int, probs = 0.5, na.rm = TRUE, names = FALSE)
+ )
+ ) %>%
+ arrange(some_grouping),
+ Table$create(tbl) %>%
+ group_by(some_grouping) %>%
+ summarize(
+ q_dbl = stats::quantile(dbl, probs = 0.5, na.rm = TRUE),
Review Comment:
Now this is a test you should do with separate namespaced and not versions
so you can test that both raise the warning.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]