From 8565feaeae0ff07b48e48abb50eaa03703adfd6d Mon Sep 17 00:00:00 2001 From: Tmonster Date: Thu, 14 Sep 2023 13:08:32 +0200 Subject: [PATCH 1/4] add csv reading test for na.strings --- tests/testthat/test_read.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/testthat/test_read.R b/tests/testthat/test_read.R index cae7a3fb7..678bfd37a 100644 --- a/tests/testthat/test_read.R +++ b/tests/testthat/test_read.R @@ -108,5 +108,16 @@ test_that("duckdb_read_csv() works as expected", { res$Species <- as.factor(res$Species) expect_true(identical(res, iris)) + # test better na.strings handling + # see https://github.com/duckdb/duckdb/issues/8590 + tf3 <- tempfile() + na_strings <- data.frame(num=c(1, 2, NA), char=c('yes', 'no', NA), logi=c(TRUE, FALSE, NA)) + write.csv(na_strings, tf3, row.names = FALSE) + duckdb_read_csv(con, "na_table", tf3, na.strings = "-") + identical( + dbReadTable(con, "na_table"), + read.csv(tf3, na.strings = "-") + ) + dbDisconnect(con, shutdown = TRUE) }) \ No newline at end of file From 7faa9037bd6837308a6438589147072bc2d3e713 Mon Sep 17 00:00:00 2001 From: Tom Ebergen Date: Wed, 8 Nov 2023 15:21:35 +0100 Subject: [PATCH 2/4] test list type as well --- tests/testthat/test_read.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_read.R b/tests/testthat/test_read.R index 678bfd37a..0aeb145ea 100644 --- a/tests/testthat/test_read.R +++ b/tests/testthat/test_read.R @@ -111,7 +111,7 @@ test_that("duckdb_read_csv() works as expected", { # test better na.strings handling # see https://github.com/duckdb/duckdb/issues/8590 tf3 <- tempfile() - na_strings <- data.frame(num=c(1, 2, NA), char=c('yes', 'no', NA), logi=c(TRUE, FALSE, NA)) + na_strings <- data.frame(num=c(0.5, 2, NA), char=c('yes', 'no', NA), logi=c(TRUE, FALSE, NA), lisst=c(list(1), list(2, 3), NA)) write.csv(na_strings, tf3, row.names = FALSE) duckdb_read_csv(con, "na_table", tf3, na.strings = "-") identical( From b2be34db6276cf340d6654c0d8b521b760f9cdf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 8 Nov 2023 19:18:17 +0100 Subject: [PATCH 3/4] Add expectation --- tests/testthat/test_read.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_read.R b/tests/testthat/test_read.R index 0aeb145ea..b0a4ce743 100644 --- a/tests/testthat/test_read.R +++ b/tests/testthat/test_read.R @@ -114,7 +114,7 @@ test_that("duckdb_read_csv() works as expected", { na_strings <- data.frame(num=c(0.5, 2, NA), char=c('yes', 'no', NA), logi=c(TRUE, FALSE, NA), lisst=c(list(1), list(2, 3), NA)) write.csv(na_strings, tf3, row.names = FALSE) duckdb_read_csv(con, "na_table", tf3, na.strings = "-") - identical( + expect_identical( dbReadTable(con, "na_table"), read.csv(tf3, na.strings = "-") ) From de3dd414786b01b3abb9c4d099fa43cdc412bfa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Fri, 23 Feb 2024 18:00:15 +0100 Subject: [PATCH 4/4] More explicit test --- tests/testthat/test_read.R | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test_read.R b/tests/testthat/test_read.R index b0a4ce743..ad9fb0ee8 100644 --- a/tests/testthat/test_read.R +++ b/tests/testthat/test_read.R @@ -111,8 +111,13 @@ test_that("duckdb_read_csv() works as expected", { # test better na.strings handling # see https://github.com/duckdb/duckdb/issues/8590 tf3 <- tempfile() - na_strings <- data.frame(num=c(0.5, 2, NA), char=c('yes', 'no', NA), logi=c(TRUE, FALSE, NA), lisst=c(list(1), list(2, 3), NA)) - write.csv(na_strings, tf3, row.names = FALSE) + csv <- c( + '"num","char","logi","lisst.1","lisst.2","lisst.3","lisst.NA"', + '0.5,"yes",TRUE,1,2,3,NA', + '2,"no",FALSE,1,2,3,NA', + 'NA,NA,NA,1,2,3,NA' + ) + writeLines(csv, tf3) duckdb_read_csv(con, "na_table", tf3, na.strings = "-") expect_identical( dbReadTable(con, "na_table"), @@ -120,4 +125,4 @@ test_that("duckdb_read_csv() works as expected", { ) dbDisconnect(con, shutdown = TRUE) -}) \ No newline at end of file +})