thisisnic commented on a change in pull request #11432:
URL: https://github.com/apache/arrow/pull/11432#discussion_r729736504
##########
File path: r/R/util.R
##########
@@ -193,3 +193,16 @@ repeat_value_as_array <- function(object, n) {
}
return(Scalar$create(object)$as_array(n))
}
+
+handle_csv_read_error <- function(e, schema) {
+ msg <- conditionMessage(e)
+
+ if (grepl("conversion error", msg) && inherits(schema, "Schema")) {
+ abort(c(
+ msg,
+ i = "Did you check your CSV file doesn't have a header row?"
Review comment:
This is good, but I think we could get the phrasing a little tighter.
What are the exact circumstances that could trigger this error? What can we
suggest that the user does to make the code run as they would expect?
##########
File path: r/tests/testthat/test-csv.R
##########
@@ -266,6 +266,26 @@ test_that("Mix of guessing and declaring types", {
expect_identical(df, tbl[, c("dbl", "false", "chr")])
})
+test_that("more informative error when reading a CSV with headers and schema",
{
+ tf <- tempfile()
+ on.exit(unlink(tf))
+ share_data <- tibble::tibble(
Review comment:
For the sake of consistency, I would consider using the same toy
datasets most of the other tests are based on
##########
File path: r/tests/testthat/test-csv.R
##########
@@ -266,6 +266,26 @@ test_that("Mix of guessing and declaring types", {
expect_identical(df, tbl[, c("dbl", "false", "chr")])
})
+test_that("more informative error when reading a CSV with headers and schema",
{
+ tf <- tempfile()
+ on.exit(unlink(tf))
+ share_data <- tibble::tibble(
+ company = c("AMZN", "GOOG", "BKNG", "TSLA"),
+ price = c(3463.12, 2884.38, 2300.46, 732.39)
+ )
+
+ readr::write_csv(share_data, tf)
Review comment:
Is `readr` a dependency? If not, these tests will crash when installed
on a machine which is set up to install package dependencies to run tests.
--
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]