Repository: spark Updated Branches: refs/heads/branch-1.6 e65c88536 -> 93ef24638
[SPARK-12234][SPARKR] Fix ```subset``` function error when only set ```select``` argument Fix ```subset``` function error when only set ```select``` argument. Please refer to the [JIRA](https://issues.apache.org/jira/browse/SPARK-12234) about the error and how to reproduce it. cc sun-rui felixcheung shivaram Author: Yanbo Liang <[email protected]> Closes #10217 from yanboliang/spark-12234. (cherry picked from commit d9d354ed40eec56b3f03d32f4e2629d367b1bf02) Signed-off-by: Shivaram Venkataraman <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/93ef2463 Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/93ef2463 Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/93ef2463 Branch: refs/heads/branch-1.6 Commit: 93ef2463820928f434f9fb1542bc30cfb1cec9aa Parents: e65c885 Author: Yanbo Liang <[email protected]> Authored: Thu Dec 10 10:18:58 2015 -0800 Committer: Shivaram Venkataraman <[email protected]> Committed: Thu Dec 10 10:19:06 2015 -0800 ---------------------------------------------------------------------- R/pkg/R/DataFrame.R | 9 +++++++-- R/pkg/inst/tests/testthat/test_sparkSQL.R | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/93ef2463/R/pkg/R/DataFrame.R ---------------------------------------------------------------------- diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R index 81b4e6b..f4c4a25 100644 --- a/R/pkg/R/DataFrame.R +++ b/R/pkg/R/DataFrame.R @@ -1185,7 +1185,7 @@ setMethod("[", signature(x = "DataFrame", i = "Column"), #' #' Return subsets of DataFrame according to given conditions #' @param x A DataFrame -#' @param subset A logical expression to filter on rows +#' @param subset (Optional) A logical expression to filter on rows #' @param select expression for the single Column or a list of columns to select from the DataFrame #' @return A new DataFrame containing only the rows that meet the condition with selected columns #' @export @@ -1206,10 +1206,15 @@ setMethod("[", signature(x = "DataFrame", i = "Column"), #' df[df$age %in% c(19, 30), 1:2] #' subset(df, df$age %in% c(19, 30), 1:2) #' subset(df, df$age %in% c(19), select = c(1,2)) +#' subset(df, select = c(1,2)) #' } setMethod("subset", signature(x = "DataFrame"), function(x, subset, select, ...) { - x[subset, select, ...] + if (missing(subset)) { + x[, select, ...] + } else { + x[subset, select, ...] + } }) #' Select http://git-wip-us.apache.org/repos/asf/spark/blob/93ef2463/R/pkg/inst/tests/testthat/test_sparkSQL.R ---------------------------------------------------------------------- diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R index 222c04a..2051784 100644 --- a/R/pkg/inst/tests/testthat/test_sparkSQL.R +++ b/R/pkg/inst/tests/testthat/test_sparkSQL.R @@ -799,6 +799,10 @@ test_that("subsetting", { expect_equal(count(df6), 1) expect_equal(columns(df6), c("name", "age")) + df7 <- subset(df, select = "name") + expect_equal(count(df7), 3) + expect_equal(columns(df7), c("name")) + # Test base::subset is working expect_equal(nrow(subset(airquality, Temp > 80, select = c(Ozone, Temp))), 68) }) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
