ianmcook commented on a change in pull request #9999:
URL: https://github.com/apache/arrow/pull/9999#discussion_r619432125



##########
File path: r/tests/testthat/test-dplyr-mutate.R
##########
@@ -415,3 +406,160 @@ test_that("mutate and write_dataset", {
       summarize(mean = mean(integer))
   )
 })
+
+# PACHA ADDITIONS ----
+# READ THIS CAREFULLY PLEASE, IT'S MY 1ST DAY WRITING THIS KIND OF SENSITIVE 
TESTS
+
+# similar to 
https://github.com/tidyverse/dplyr/blob/master/tests/testthat/test-mutate.r#L1-L10
+# the rest of that test belongs in L55-62 here
+test_that("empty mutate returns input", {
+  # dbl2 = 5, so I'm grouping by a constant
+  gtbl <- group_by(tbl, dbl2)
+
+  expect_dplyr_equal(input %>% mutate(!!!list()) %>% collect(), tbl)
+
+  expect_dplyr_equal(input %>% mutate() %>% collect(), gtbl)
+  expect_dplyr_equal(input %>% mutate(!!!list()) %>% collect(), gtbl)
+})
+
+# similar to 
https://github.com/tidyverse/dplyr/blob/master/tests/testthat/test-mutate.r#L12-L6
+test_that("rownames preserved", {
+  skip("Row names are not preserved")
+  df <- data.frame(x = c(1, 2), row.names = c("a", "b"))
+  expect_dplyr_equal(input %>% mutate(y = 2) %>% collect(), df)
+})
+
+# similar to 
https://github.com/tidyverse/dplyr/blob/master/tests/testthat/test-mutate.r#L18-L29
+test_that("mutations applied progressively", {
+  df <- tibble(x = 1)
+
+  expect_dplyr_equal(
+    input %>% mutate(y = x + 1, z = y + 1) %>% collect(),
+    df
+  )
+  expect_dplyr_equal(
+    input %>% mutate(x = x + 1, x = x + 1) %>% collect(),
+    df
+  )
+  expect_dplyr_equal(
+    input %>% mutate(y = x + 1, z = y + 1) %>% collect(),
+    df
+  )
+
+  df <- data.frame(x = 1, y = 2)
+  expect_dplyr_equal(
+    input %>% mutate(x2 = x, x3 = x2 + 1) %>% collect(),
+    df
+  )
+})
+
+# similar to # similar to 
https://github.com/tidyverse/dplyr/blob/master/tests/testthat/test-mutate.r#L31-L35
+# SEE LINE 175 IN THIS SCRIPT!
+# THIS WON'T WORK
+# https://issues.apache.org/jira/browse/ARROW-11705
+#  Error in UseMethod("mutate") :
+# no applicable method for 'mutate' applied to an object of class "c('double', 
'numeric')"
+# test_that("length-1 vectors are recycled (#152)", {
+#   df <- tibble(x = 1:4)
+#
+#   expect_dplyr_equal(
+#     collect(mutate(input, y = 1))$y,
+#     rep(1, 4)
+#   )
+# })
+
+# similar to 
https://github.com/tidyverse/dplyr/blob/master/tests/testthat/test-mutate.r#L37-L54
+test_that("can remove variables with NULL (dplyr #462)", {
+  df <- tibble(x = 1:3, y = 1:3)
+  gf <- group_by(df, x)
+
+  expect_dplyr_equal(input %>% mutate(y = NULL) %>% collect(), df[1])
+  expect_dplyr_equal(input %>% mutate(y = NULL) %>% collect(), gf[1])
+
+  # even if it doesn't exist
+  expect_dplyr_equal(input %>% mutate(z = NULL) %>% collect(), df)
+  # or was just created
+  expect_dplyr_equal(input %>% mutate(z = 1, z = NULL) %>% collect(), df)
+
+  # regression test for https://github.com/tidyverse/dplyr/issues/4974
+  expect_dplyr_equal(
+    data.frame(x = 1, y = 1) %>% mutate(z = 1, x = NULL, y = NULL) %>% 
collect(),
+    data.frame(z = 1)
+  )

Review comment:
       The ones below here also need to be fixed to use `expect_dplyr_equal()` 
properly




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to