paleolimbot commented on a change in pull request #12030:
URL: https://github.com/apache/arrow/pull/12030#discussion_r779211974
##########
File path: r/tests/testthat/test-csv.R
##########
@@ -290,6 +292,50 @@ test_that("more informative error when reading a CSV with
headers and schema", {
)
})
+test_that("CSV reader works on files with non-UTF-8 encoding", {
+ strings <- c("a", "\u00e9", "\U0001f4a9")
+ file_string <- paste0(
+ "col1,col2\n",
+ paste(strings, 1:30, sep = ",", collapse = "\n")
+ )
+ file_bytes_utf16 <- iconv(
+ file_string,
+ from = Encoding(file_string),
+ to = "UTF-16LE",
+ toRaw = TRUE
+ )[[1]]
+
+ tf <- tempfile()
+ on.exit(unlink(tf))
+ con <- file(tf, open = "wb")
+ writeBin(file_bytes_utf16, con)
+ close(con)
+
+ fs <- LocalFileSystem$create()
+ reader <- CsvTableReader$create(
+ fs$OpenInputStream(tf),
+ read_options = CsvReadOptions$create(encoding = "UTF-16LE")
+ )
Review comment:
Right...that's a good point! The current mode of failure is weird I
think...I'd prefer to error rather than return a column of a type that the user
didn't expect and didn't request. In something like readr you could error and
tell the user to use `schema = schema(latin1_chars = col_binary(), .default =
col_guess())`...the CSV reader interface doesn't really allow `col_guess()` or
`.default` to my knowledge.
--
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]