paleolimbot commented on code in PR #33614:
URL: https://github.com/apache/arrow/pull/33614#discussion_r1072647286
##########
r/tests/testthat/test-dataset-csv.R:
##########
@@ -476,3 +476,87 @@ test_that("CSV reading/parsing/convert options can be
passed in as lists", {
expect_equal(ds1, ds2)
})
+
+test_that("open_delim_dataset params passed through to open_dataset", {
+ ds <- open_delim_dataset(csv_dir, delim = ",", partitioning = "part")
+ expect_r6_class(ds$format, "CsvFileFormat")
+ expect_r6_class(ds$filesystem, "LocalFileSystem")
+ expect_identical(names(ds), c(names(df1), "part"))
+ expect_identical(dim(ds), c(20L, 7L))
+
+ # quote
+ df <- data.frame(a = c(1, 2), b = c("'abc'", "'def'"))
+ dst_dir <- make_temp_dir()
+ dst_file <- file.path(dst_dir, "data.csv")
+ write.table(df, sep = ",", dst_file, row.names = FALSE, quote = FALSE)
+
+ ds_quote <- open_csv_dataset(dst_dir, quote = "'") %>% collect()
+ expect_equal(ds_quote$b, c("abc", "def"))
+
+ # na
+ ds <- open_csv_dataset(csv_dir, partitioning = "part", na = c("", "NA",
"FALSE")) %>% collect()
+ expect_identical(ds$lgl, c(
+ TRUE, NA, NA, TRUE, NA, TRUE, NA, NA, TRUE, NA, TRUE, NA, NA,
+ TRUE, NA, TRUE, NA, NA, TRUE, NA
+ ))
+
+ # col_names and skip
+ ds <- open_csv_dataset(
+ csv_dir,
+ partitioning = "part",
+ col_names = paste0("col_", 1:6),
+ skip = 1
+ ) %>% collect()
+
+ expect_named(ds, c("col_1", "col_2", "col_3", "col_4", "col_5", "col_6",
"part"))
+ expect_equal(nrow(ds), 20)
+
+ # col_types
+ df <- data.frame(a = c(1, NA, 2), b = c("'abc'", NA, "'def'"))
+ dst_dir <- make_temp_dir()
+ dst_file <- file.path(dst_dir, "data.csv")
+ write.table(df, sep = ",", dst_file, row.names = FALSE, quote = FALSE)
+
+ data_schema <- schema(a = string(), b = string())
+ ds_strings <- open_csv_dataset(dst_dir, col_types = data_schema)
+ expect_equal(ds_strings$schema, schema(a = string(), b = string()))
+
+ # skip_empty_rows
+ tf <- tempfile()
+ writeLines('"x"\n"y"\nNA\nNA\n"NULL"\n\n\n', tf)
Review Comment:
I see that we do `write.csv()` almost everywhere in test-csv.R for this, so
happy to defer this to later/if ever.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]