Skip to content
Merged
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
4 changes: 2 additions & 2 deletions r/src/arrowExports.cpp

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

2 changes: 2 additions & 0 deletions r/src/r_to_arrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ RVectorType GetVectorType(SEXP x) {
return FACTOR;
} else if (Rf_inherits(x, "Date")) {
return DATE_INT;
} else if (Rf_inherits(x, "POSIXct")) {
return POSIXCT;
Comment on lines +96 to +97
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, huh I wonder if this type is new? Or maybe I "just" forgot about it when I made these changes?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🤖 says that it's not new, but historically, POSIXct was always REALSXP (backed by a double) until R 4.5.2, but now for zero-length POSIXct objects that's no longer the case, so it needs checking in the INTSXP path.

Or, with more detail:

So in R 4.5.0, R changed as.POSIXct({}) (i.e., zero-length POSIXct) to be internally stored as integer (INTSXP) rather than double (REALSXP). This is a deliberate change for consistency - zero-length date-time objects don't need the full double precision since they have no actual values to store.

}
return INT32;
case STRSXP:
Expand Down
11 changes: 11 additions & 0 deletions r/tests/testthat/test-Array.R
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,17 @@ test_that("array uses local timezone for POSIXct without timezone", {
})
})

test_that("zero-length POSIXct can be converted (GH-48832)", {
# In R 4.5.2+, zero-length POSIXct vectors are integer type, not double
x <- as.POSIXct(x = NULL)

# Should behave the same as non-empty POSIXct with empty tzone
expect_type_equal(infer_type(x), timestamp("us"))
arr <- Array$create(x)
expect_equal(arr$length(), 0L)
expect_type_equal(arr, timestamp("us"))
})

test_that("Timezone handling in Arrow roundtrip (ARROW-3543)", {
# Write a feather file as that's what the initial bug report used
df <- tibble::tibble(
Expand Down
10 changes: 10 additions & 0 deletions r/tests/testthat/test-parquet.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ test_that("write_parquet() can truncate timestamps", {
expect_equal(as.data.frame(tab), as.data.frame(new))
})

test_that("write_parquet() works with zero-length POSIXct (GH-48832)", {
# In R 4.5.2+, zero-length POSIXct vectors are integer type, not double
tf <- tempfile()
on.exit(unlink(tf))

expect_no_error(write_parquet(data.frame(x = as.POSIXct(x = NULL)), tf))
result <- read_parquet(tf)
expect_equal(nrow(result), 0)
})

test_that("make_valid_parquet_version()", {
expect_equal(
make_valid_parquet_version("1.0"),
Expand Down
Loading