thisisnic commented on code in PR #14705:
URL: https://github.com/apache/arrow/pull/14705#discussion_r1034366489
##########
r/tests/testthat/test-dataset-csv.R:
##########
@@ -322,6 +320,49 @@ test_that("Column names can be inferred from schema", {
expect_equal(ds %>% collect(), tbl)
})
+test_that("Can use col_names readr parameter", {
+ expected_names <- c("my_int", "my_double")
+ ds <- open_dataset(
+ headerless_csv_dir,
+ format = "csv",
+ col_names = expected_names
+ )
+ expect_equal(names(ds), expected_names)
+ expect_equal(ds %>% collect(), set_names(tbl, expected_names))
+
+ # WITHOUT header, makes up names
+ ds <- open_dataset(
+ headerless_csv_dir,
+ format = "csv",
+ col_names = FALSE
+ )
+ expect_equal(names(ds), c("f0", "f1"))
+ expect_equal(ds %>% collect(), set_names(tbl, c("f0", "f1")))
+
+ # WITH header, gets names
+ ds <- open_dataset(
+ header_csv_dir,
+ format = "csv",
+ col_names = TRUE
+ )
+ expect_equal(names(ds), c("int", "dbl"))
+ expect_equal(ds %>% collect(), tbl)
+
+ ds <- open_dataset(
+ header_csv_dir,
+ format = "csv",
+ col_names = FALSE,
+ skip = 1
+ )
+ expect_equal(names(ds), c("f0", "f1"))
+ expect_equal(ds %>% collect(), set_names(tbl, c("f0", "f1")))
+
+ expect_error(
Review Comment:
The text of this error comes from C++ so we shouldn't test it in R; we could
either catch this error and add in a more R-style error message, or just test
that the code raises an error without testing the specific text of the error
itself.
--
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]