Skip to content

Commit

Permalink
ARROW-13624: [R] readr short type mapping has T and t backwards
Browse files Browse the repository at this point in the history
Closes #11327 from dragosmg/ARROW-13624_readr_time_col_types

Authored-by: Dragos Moldovan-Grünfeld <dragos.mold@gmail.com>
Signed-off-by: Neal Richardson <neal.p.richardson@gmail.com>
  • Loading branch information
dragosmg authored and nealrichardson committed Oct 6, 2021
1 parent a69884d commit bd541d1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
8 changes: 4 additions & 4 deletions r/R/csv.R
Expand Up @@ -61,8 +61,8 @@
#' * "l": `bool()`
#' * "f": `dictionary()`
#' * "D": `date32()`
#' * "T": `time32()`
#' * "t": `timestamp()`
#' * "T": `timestamp()`
#' * "t": `time32()`
#' * "_": `null()`
#' * "-": `null()`
#' * "?": infer the type from the data
Expand Down Expand Up @@ -569,8 +569,8 @@ readr_to_csv_convert_options <- function(na,
"l" = bool(),
"f" = dictionary(),
"D" = date32(),
"T" = time32(),
"t" = timestamp(),
"T" = timestamp(),
"t" = time32(),
"_" = null(),
"-" = null(),
"?" = NULL,
Expand Down
6 changes: 1 addition & 5 deletions r/man/arrow-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions r/man/read_delim_arrow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 28 additions & 2 deletions r/tests/testthat/test-csv.R
Expand Up @@ -222,8 +222,9 @@ test_that("read_csv_arrow() can read timestamps", {
df <- read_csv_arrow(tf, col_types = schema(time = timestamp(timezone = "UTC")))
expect_equal(tbl, df)

df <- read_csv_arrow(tf, col_types = "t", col_names = "time", skip = 1)
expect_equal(tbl, df, ignore_attr = "tzone") # col_types = "t" makes timezone-naive timestamp
# time zones are being read in as time zone-naive, hence ignore_attr = "tzone"
df <- read_csv_arrow(tf, col_types = "T", col_names = "time", skip = 1)
expect_equal(tbl, df, ignore_attr = "tzone")
})

test_that("read_csv_arrow(timestamp_parsers=)", {
Expand Down Expand Up @@ -329,3 +330,28 @@ test_that("Write a CSV file with invalid batch size", {
regexp = "batch_size not greater than 0"
)
})

test_that("time mapping work as expected (ARROW-13624)", {
tbl <- tibble::tibble(
dt = as.POSIXct(c("2020-07-20 16:20", NA), tz = "UTC"),
time = c(hms::as_hms("16:20:00"), NA)
)
tf <- tempfile()
on.exit(unlink(tf))
write.csv(tbl, tf, row.names = FALSE)

df <- read_csv_arrow(tf,
col_names = c("dt", "time"),
col_types = "Tt",
skip = 1
)

expect_error(
read_csv_arrow(tf,
col_names = c("dt", "time"),
col_types = "tT", skip = 1
)
)

expect_equal(df, tbl, ignore_attr = "tzone")
})

0 comments on commit bd541d1

Please sign in to comment.