Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions R/pkg/R/DataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,8 @@ setMethod("names",
setMethod("names<-",
signature(x = "SparkDataFrame"),
function(x, value) {
if (!is.null(value)) {
sdf <- callJMethod(x@sdf, "toDF", as.list(value))
dataFrame(sdf)
}
colnames(x) <- value
x
})

#' @rdname columns
Expand Down
8 changes: 8 additions & 0 deletions R/pkg/inst/tests/testthat/test_sparkSQL.R
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,14 @@ test_that("names() colnames() set the column names", {
colnames(df) <- c("col3", "col4")
expect_equal(names(df)[1], "col3")

expect_error(names(df) <- NULL, "Invalid column names.")
expect_error(names(df) <- c("sepal.length", "sepal_width"),
"Column names cannot contain the '.' symbol.")
expect_error(names(df) <- c(1, 2), "Invalid column names.")
expect_error(names(df) <- c("a"),
"Column names must have the same length as the number of columns in the dataset.")
expect_error(names(df) <- c("1", NA), "Column names cannot be NA.")

expect_error(colnames(df) <- c("sepal.length", "sepal_width"),
"Column names cannot contain the '.' symbol.")
expect_error(colnames(df) <- c(1, 2), "Invalid column names.")
Expand Down