Skip to content

Commit

Permalink
using assert_that()
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Sep 27, 2019
1 parent 738ea6e commit 72caaab
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 19 deletions.
1 change: 1 addition & 0 deletions r/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ importFrom(rlang,dots_n)
importFrom(rlang,enquo)
importFrom(rlang,enquos)
importFrom(rlang,is_false)
importFrom(rlang,is_integerish)
importFrom(rlang,list2)
importFrom(rlang,quo_is_null)
importFrom(rlang,warn)
Expand Down
2 changes: 1 addition & 1 deletion r/R/arrow-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' @importFrom R6 R6Class
#' @importFrom purrr map map_int map2
#' @importFrom assertthat assert_that
#' @importFrom rlang list2 %||% is_false abort dots_n warn enquo quo_is_null enquos
#' @importFrom rlang list2 %||% is_false abort dots_n warn enquo quo_is_null enquos is_integerish
#' @importFrom Rcpp sourceCpp
#' @importFrom tidyselect vars_select
#' @useDynLib arrow, .registration = TRUE
Expand Down
18 changes: 5 additions & 13 deletions r/R/parquet.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ ParquetWriterProperties_Builder <- R6Class("ParquetWriterProperties_Builder", in
set_compression = function(table, compression){
if (is.character(compression) && is.null(names(compression)) && length(compression) == 1L) {
parquet___ArrowWriterProperties___Builder__default_compression(self, compression_from_name(compression))
} else if (inherits(compression, "Codec")) {
parquet___ArrowWriterProperties___Builder__default_compression(self, compression_from_name(compression$name))
} else {
column_names <- names(table)
if (is.character(compression) && is.null(names(compression)) && length(compression) == length(column_names)) {
Expand All @@ -98,9 +96,8 @@ ParquetWriterProperties_Builder <- R6Class("ParquetWriterProperties_Builder", in
},

set_compression_level = function(table, compression_level){
if (!rlang::is_integerish(compression_level)) {
abort("unsupported compression_level= specification")
}
assert_that(is_integerish(compression_level), msg = "unsupported compression_level= specification")

column_names <- names(table)
if (is.null(given_names <- names(compression_level))) {
if (length(compression_level) == 1L) {
Expand All @@ -116,9 +113,7 @@ ParquetWriterProperties_Builder <- R6Class("ParquetWriterProperties_Builder", in
},

set_dictionary = function(table, use_dictionary) {
if (!is.logical(use_dictionary)) {
abort("unsupported use_dictionary= specification")
}
assert_that(is.logical(use_dictionary), msg = "unsupported use_dictionary= specification")

column_names <- names(table)
if (is.null(given_names <- names(use_dictionary))) {
Expand All @@ -135,9 +130,7 @@ ParquetWriterProperties_Builder <- R6Class("ParquetWriterProperties_Builder", in
},

set_write_statistics = function(table, write_statistics) {
if (!is.logical(write_statistics)) {
abort("unsupported write_statistics= specification")
}
assert_that(is.logical(write_statistics), msg = "unsupported write_statistics= specification")

column_names <- names(table)
if (is.null(given_names <- names(write_statistics))) {
Expand Down Expand Up @@ -212,14 +205,13 @@ ParquetFileWriter$create <- function(
#' [Parquet](https://parquet.apache.org/) is a columnar storage file format.
#' This function enables you to write Parquet files from R.
#'
#' @param table An [arrow::Table][Table], or an object convertible to it with [to_arrow()]
#' @param table An [arrow::Table][Table], or an object convertible to it.
#' @param sink an [arrow::io::OutputStream][OutputStream] or a string which is interpreted as a file path
#' @param chunk_size chunk size. If NULL, the number of rows of the table is used
#'
#' @param version parquet version
#' @param compression compression specification. Possible values:
#' - a single string: uses that compression algorithm for all columns
#' - a single [Codec][Codec] instance: uses that compression algorithm for all columns
#' - an unnamed string vector: specify a compression algorithm for each, same order as the columns
#' - a named string vector: specify compression algorithm individually
#' @param compression_level compression level. A single integer, a named integer vector
Expand Down
3 changes: 1 addition & 2 deletions r/man/write_parquet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions r/tests/testthat/test-parquet.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ test_that("write_parquet() handles various compression= specs", {
# a single string
expect_error(write_parquet(tab, tf, compression = "snappy"), NA)

# a single Codec
expect_error(write_parquet(tab, tf, compression = Codec$create("snappy")), NA)

# one string per column
expect_error(write_parquet(tab, tf, compression = rep("snappy", 3L)), NA)

Expand Down

0 comments on commit 72caaab

Please sign in to comment.