Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions r/R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ repeat_value_as_array <- function(object, n) {
}

handle_csv_read_error <- function(msg, call, schema) {
if (grepl("conversion error to null", msg)) {
msg <- c(
msg,
i = paste(
"Column type was inferred as null because the first block of data",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Column type was inferred as null because the first block of data",
"Column type was inferred as `null` because the first block of data",

or maybe even NULL?

"contained only missing values. See `?csv_read_options` for how to",
"set a smaller value."
)
)
abort(msg, call = call)
}

if (grepl("conversion error", msg) && inherits(schema, "Schema")) {
msg <- c(
msg,
Expand Down
18 changes: 18 additions & 0 deletions r/tests/testthat/test-dataset-csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -711,3 +711,21 @@ test_that("open_dataset() with `decimal_point` argument", {
tibble(x = 1.2, y = "c")
)
})

test_that("more informative error when column inferred as null due to sparse data (GH-35806)", {
tf <- tempfile()
on.exit(unlink(tf))

writeLines(c("x,y", paste0(1:100, ",")), tf)
write("101,foo", tf, append = TRUE)

expect_error(
open_dataset(
tf,
format = "csv",
read_options = csv_read_options(block_size = 100L)
) |>
collect(),
"inferred as null"
)
})
Loading