1# Licensed to the Apache Software Foundation (ASF) under one 2# or more contributor license agreements. See the NOTICE file 3# distributed with this work for additional information 4# regarding copyright ownership. The ASF licenses this file 5# to you under the Apache License, Version 2.0 (the 6# "License"); you may not use this file except in compliance 7# with the License. You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, 12# software distributed under the License is distributed on an 13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14# KIND, either express or implied. See the License for the 15# specific language governing permissions and limitations 16# under the License. 17 18data_no_na <- c(2:10) 19data_na <- c(data_no_na, NA_real_) 20 21test_that("na.fail on Scalar", { 22 scalar_na <- Scalar$create(NA) 23 scalar_one <- Scalar$create(1) 24 expect_as_vector(na.fail(scalar_one), 1) 25 expect_error(na.fail(scalar_na), "missing values in object") 26}) 27 28test_that("na.omit on Array and ChunkedArray", { 29 compare_expression(na.omit(.input), data_no_na) 30 compare_expression(na.omit(.input), data_na, ignore_attr = TRUE) 31}) 32 33test_that("na.exclude on Array and ChunkedArray", { 34 compare_expression(na.exclude(.input), data_no_na) 35 compare_expression(na.exclude(.input), data_na, ignore_attr = TRUE) 36}) 37 38test_that("na.fail on Array and ChunkedArray", { 39 compare_expression(na.fail(.input), data_no_na, ignore_attr = TRUE) 40 compare_expression_error(na.fail(.input), data_na) 41}) 42 43test_that("na.fail on Scalar", { 44 scalar_one <- Scalar$create(1) 45 expect_error(na.fail(scalar_na), regexp = "missing values in object") 46 expect_as_vector(na.fail(scalar_one), na.fail(1)) 47}) 48 49test_that("na.omit on Table", { 50 tbl <- Table$create(example_data) 51 expect_equal( 52 as.data.frame(na.omit(tbl)), 53 na.omit(example_data), 54 # We don't include an attribute with the rows omitted 55 ignore_attr = "na.action" 56 ) 57}) 58 59test_that("na.exclude on Table", { 60 tbl <- Table$create(example_data) 61 expect_equal( 62 as.data.frame(na.exclude(tbl)), 63 na.exclude(example_data), 64 ignore_attr = "na.action" 65 ) 66}) 67 68test_that("na.fail on Table", { 69 tbl <- Table$create(example_data) 70 expect_error(na.fail(tbl), "missing values in object") 71}) 72 73test_that("na.omit on RecordBatch", { 74 batch <- record_batch(example_data) 75 expect_equal( 76 as.data.frame(na.omit(batch)), 77 na.omit(example_data), 78 ignore_attr = "na.action" 79 ) 80}) 81 82test_that("na.exclude on RecordBatch", { 83 batch <- record_batch(example_data) 84 expect_equal( 85 as.data.frame(na.exclude(batch)), 86 na.omit(example_data), 87 ignore_attr = "na.action" 88 ) 89}) 90 91test_that("na.fail on RecordBatch", { 92 batch <- record_batch(example_data) 93 expect_error(na.fail(batch), "missing values in object") 94}) 95