# Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. test_that("various paths in arrow_eval", { expect_arrow_eval_error( assert_is(1, "character"), class = "validation_error" ) expect_arrow_eval_error( NoTaVaRiAbLe, class = "validation_error" ) expect_arrow_eval_error( match.arg("z", c("a", "b")), class = "validation_error" ) expect_arrow_eval_error( stop("something something NotImplementedError"), class = "arrow_not_supported" ) }) test_that("try_arrow_dplyr/abandon_ship adds the right message about collect()", { tester <- function(.data, arg) { try_arrow_dplyr({ if (arg == 0) { # This one just stops and doesn't recommend calling collect() validation_error("arg is 0") } else if (arg == 1) { # This one recommends calling collect() arrow_not_supported("arg == 1") } else { # Because this one has an alternative suggested, it adds "Or, collect()" arrow_not_supported( "arg greater than 0", body = c(">" = "Try setting arg to -1") ) } }) } skip_if_not_available("dataset") ds <- InMemoryDataset$create(arrow_table(x = 1)) for (i in 0:2) { expect_snapshot(tester(ds, i), error = TRUE) } }) test_that("dplyr verbs error clearly on empty column names", { skip_if_not_available("acero") # GH-40303 tbl <- example_data names(tbl)[1] <- "" # dplyr also refuses these ("Can't transform a data frame with `NA` or # `""` names."), but our wording differs since the input isn't a data frame tab <- arrow_table(tbl) msg <- "Can't transform data with empty" expect_error(tab |> mutate(z = dbl + 1), msg) expect_error(tab |> filter(dbl > 4), msg) expect_error(tab |> arrange(dbl), msg) expect_error(tab |> group_by(dbl), msg) # select() and rename() still work as an escape hatch, as in dplyr compare_dplyr_binding( .input |> select(-1) |> mutate(z = dbl + 1) |> collect(), tbl ) compare_dplyr_binding( .input |> rename(int = 1) |> mutate(z = dbl + 1) |> collect(), tbl ) })