diff --git a/h2o-py/h2o/frame.py b/h2o-py/h2o/frame.py index 590fbea94484..0f580cab982b 100644 --- a/h2o-py/h2o/frame.py +++ b/h2o-py/h2o/frame.py @@ -4668,12 +4668,12 @@ def match(self, table, nomatch=float("nan"), start_index=1): :examples: - >>> iris = h2o.import_file("http://h2o-public-test-data.s3.amazonaws.com/smalldata/iris/iris.csv") + >>> iris = h2o.import_file("h2o://iris") >>> match_col = iris["C5"].match(['Iris-setosa', 'Iris-versicolor']) >>> match_col.names = ['match'] >>> iris_match = iris.cbind(match_col) >>> iris_split = iris_match.split_frame(ratios=[0.05], seed=1)[0] - >>> print(iris_split) + >>> iris_split """ return H2OFrame._expr(expr=ExprNode("match", self, table, nomatch, start_index)) diff --git a/h2o-r/h2o-package/R/frame.R b/h2o-r/h2o-package/R/frame.R index f9f0da440112..0ac4f4ad1f42 100644 --- a/h2o-r/h2o-package/R/frame.R +++ b/h2o-r/h2o-package/R/frame.R @@ -863,11 +863,11 @@ cut.H2OFrame <- h2o.cut #' @examples #' \dontrun{ #' h2o.init() -#' iris <- as.h2o(iris) -#' match_col <- h2o.match(iris$Species, c("setosa", "versicolor", "setosa")) -#' iris_match <- h2o.cbind(iris, match_col) +#' frame <- as.h2o(iris) +#' match_col <- h2o.match(frame$Species, c("setosa", "versicolor", "setosa")) +#' iris_match <- h2o.cbind(frame, match_col) #' iris_split <- h2o.splitFrame(iris_match, ratios=0.05, seed=1) -#' print(iris_split[1]) +#' iris_split[1] #' } #' @export h2o.match <- function(x, table, nomatch=NA_integer_, start_index=1) { diff --git a/h2o-r/tests/testdir_munging/slice/runit_match.R b/h2o-r/tests/testdir_munging/slice/runit_match.R index 0c8bdb13c505..9f9c8e3ba308 100644 --- a/h2o-r/tests/testdir_munging/slice/runit_match.R +++ b/h2o-r/tests/testdir_munging/slice/runit_match.R @@ -4,32 +4,32 @@ source("../../../scripts/h2o-r-test-setup.R") test.match <- function() { - iris <- as.h2o(iris) + frame <- as.h2o(iris) # compare h2o and base %in% - h2o_in <- 'setosa' %in% iris$Species - base_in <- base::`%in%`("setosa", as.vector(iris$Species)) + h2o_in <- 'setosa' %in% frame$Species + base_in <- base::`%in%`("setosa", as.vector(frame$Species)) expect_equal(h2o_in, base_in) - sub_h2o_in <- iris$Species %in% c("setosa", "versicolor") - hh_in <- iris[sub_h2o_in,] + sub_h2o_in <- frame$Species %in% c("setosa", "versicolor") + hh_in <- frame[sub_h2o_in,] expect_equal(dim(hh_in), c(100, 5)) - sub_base_in <- base::`%in%`(as.vector(iris$Species), c("setosa", "versicolor")) - hh_in_base <- iris[as.h2o(sub_base_in),] + sub_base_in <- base::`%in%`(as.vector(frame$Species), c("setosa", "versicolor")) + hh_in_base <- frame[as.h2o(sub_base_in),] expect_equal(dim(hh_in_base), c(100, 5)) expect_equal(hh_in, hh_in_base) # compare h2o and base match # string values, default setting - sub_h2o_match <- h2o.match(iris$Species, c("setosa", "versicolor")) + sub_h2o_match <- h2o.match(frame$Species, c("setosa", "versicolor")) sub_h2o_match <- as.vector(sub_h2o_match) expect_equal(sub_h2o_match[1], 1) expect_equal(sub_h2o_match[51], 2) expect_equal(sub_h2o_match[101], NA_integer_) - sub_base_match <- base::match(as.vector(iris$Species), c("setosa", "versicolor")) + sub_base_match <- base::match(as.vector(frame$Species), c("setosa", "versicolor")) expect_equal(sub_base_match[1], 1) expect_equal(sub_base_match[51], 2) expect_equal(sub_base_match[101], NA_integer_) @@ -37,25 +37,25 @@ test.match <- function() { expect_equal(sub_h2o_match, sub_base_match) # string values, nomatch=0 - sub_h2o_match <- h2o.match(iris$Species, c("setosa", "versicolor"), nomatch=0) + sub_h2o_match <- h2o.match(frame$Species, c("setosa", "versicolor"), nomatch=0) sub_h2o_match <- as.vector(sub_h2o_match) expect_equal(sub_h2o_match[1], 1) expect_equal(sub_h2o_match[51], 2) expect_equal(sub_h2o_match[101], 0) # string values, start_index=0 - sub_h2o_match <- h2o.match(iris$Species, c("setosa", "versicolor"), start_index=0) + sub_h2o_match <- h2o.match(frame$Species, c("setosa", "versicolor"), start_index=0) sub_h2o_match <- as.vector(sub_h2o_match) expect_equal(sub_h2o_match[1], 0) expect_equal(sub_h2o_match[51], 1) expect_equal(sub_h2o_match[101], NA_integer_) - sub_h2o_in <- iris$Sepal.Length %in% c(5.1) - hh_in <- iris[sub_h2o_in,] + sub_h2o_in <- frame$Sepal.Length %in% c(5.1) + hh_in <- frame[sub_h2o_in,] expect_equal(dim(hh_in), c(9,5)) # numeric value, default setting - sub_h2o_match <- h2o.match(iris$Sepal.Length, c(5.1)) + sub_h2o_match <- h2o.match(frame$Sepal.Length, c(5.1)) sub_h2o_match <- as.vector(sub_h2o_match) expect_equal(sub_h2o_match[1], 1) expect_equal(sub_h2o_match[18], 1) @@ -63,15 +63,15 @@ test.match <- function() { expect_equal(sub_h2o_match[2], NA_integer_) # string values, duplicates in match values - sub_h2o_match <- h2o.match(iris$Species, c("setosa", "versicolor", "setosa")) + sub_h2o_match <- h2o.match(frame$Species, c("setosa", "versicolor", "setosa")) sub_h2o_match <- as.vector(sub_h2o_match) expect_equal(sub_h2o_match[1], 1) expect_equal(sub_h2o_match[51], 2) expect_equal(sub_h2o_match[101], NA_integer_) # test doc example - match_col <- h2o.match(iris$Species, c("setosa", "versicolor", "setosa")) - iris_match <- h2o.cbind(iris, match_col) + match_col <- h2o.match(frame$Species, c("setosa", "versicolor", "setosa")) + iris_match <- h2o.cbind(frame, match_col) splited <- h2o.splitFrame(iris_match, ratios=0.05, seed=1) print(splited[1]) }