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
10 changes: 10 additions & 0 deletions r/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,23 @@

# arrow 25.0.1.9000

## Breaking changes

- The `.data.frame` argument to `map_batches()`, deprecated since 9.0.0, has
been removed. Call `collect()` on the result to get a data frame (#51655).

## Minor improvements and fixes

- Factor levels inside list columns are now unified across the whole column
when converting to R, so data read in multiple batches (e.g. via
`read_ipc_stream()` or `open_dataset()`) produces valid factors that can be
unnested. Similarly, `int64` and `uint32` values inside list columns are
converted to a single R type across the column (#50514).
- `pull()` on Arrow data no longer warns about a future change of default.
The planned switch to returning a `ChunkedArray` has been dropped, so
`pull()` will keep returning an R vector by default; use
`as_vector = FALSE` or `options(arrow.pull_as_vector = FALSE)` to get a
`ChunkedArray` (#51655).

# arrow 25.0.1

Expand Down
7 changes: 3 additions & 4 deletions r/R/arrow-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ supported_dplyr_methods <- list(
rename = NULL,
pull = c(
"the `name` argument is not supported;",
"returns an R vector by default but this behavior is deprecated and will",
"return an Arrow [ChunkedArray] in a future release. Provide",
"`as_vector = TRUE/FALSE` to control this behavior, or set",
"`options(arrow.pull_as_vector)` globally."
"returns an R vector by default. Provide `as_vector = FALSE`",
"to return an Arrow [ChunkedArray] instead, or set",
"`options(arrow.pull_as_vector = FALSE)` globally."
),
relocate = NULL,
compute = NULL,
Expand Down
10 changes: 1 addition & 9 deletions r/R/dataset-scan.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,9 @@ tail_from_batches <- function(batches, n) {
#' the result; use `FALSE` to evaluate `FUN` on all batches before returning
#' the reader.
#' @param ... Additional arguments passed to `FUN`
#' @param .data.frame Deprecated argument, ignored
#' @return An `arrow_dplyr_query`.
#' @export
map_batches <- function(X, FUN, ..., .schema = NULL, .lazy = TRUE, .data.frame = NULL) {
if (!is.null(.data.frame)) {
warning(
"The .data.frame argument is deprecated. ",
"Call collect() on the result to get a data.frame.",
call. = FALSE
)
}
map_batches <- function(X, FUN, ..., .schema = NULL, .lazy = TRUE) {
Comment thread
thisisnic marked this conversation as resolved.
FUN <- as_mapper(FUN)
reader <- as_record_batch_reader(X)
dots <- list2(...)
Expand Down
24 changes: 2 additions & 22 deletions r/R/dplyr-collect.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ compute.arrow_dplyr_query <- function(x, ...) {
}
compute.Dataset <- compute.RecordBatchReader <- compute.arrow_dplyr_query

pull.Dataset <- function(.data, var = -1, ..., as_vector = getOption("arrow.pull_as_vector")) {
pull.Dataset <- function(.data, var = -1, ..., as_vector = getOption("arrow.pull_as_vector", TRUE)) {
.data <- as_adq(.data)
var <- vars_pull(names(.data), !!enquo(var))
.data$selected_columns <- set_names(.data$selected_columns[var], var)
Expand All @@ -65,32 +65,12 @@ pull.Dataset <- function(.data, var = -1, ..., as_vector = getOption("arrow.pull
}
pull.RecordBatchReader <- pull.arrow_dplyr_query <- pull.Dataset

pull.ArrowTabular <- function(x, var = -1, ..., as_vector = getOption("arrow.pull_as_vector")) {
pull.ArrowTabular <- function(x, var = -1, ..., as_vector = getOption("arrow.pull_as_vector", TRUE)) {
out <- x[[vars_pull(names(x), !!enquo(var))]]
handle_pull_as_vector(out, as_vector)
}

handle_pull_as_vector <- function(out, as_vector) {
if (is.null(as_vector)) {

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.

I did some digging (well tasked a clanker to do the digging...) to see why we did this in the first place. Here it is for posterity (or some future clanker to dig it up). We originally proposed to do this since there wasn't another ergonomic way to get a chunked array, and unlike dbplyr where this was originally inspired by, Arrow has an in-memory representation, so there wasn't a requirement to turn it into an R vector.

It turns out that broke dependencies so we made it opt in at the time, though there has been consistent feedback that other engines like data.table also return just a vector (and conceptually dplyr does this with data.frames too, it strips the outer data.frameness).

I'm good with undeprecating this. Though I am slightly curious (and we should do this in a follow on if we do), do we now have a (more) ergonomic way to get a chunked array? is it pull(..., as_vector=FALSE)? or something else?

warn(
c(
paste(
"Default behavior of `pull()` on Arrow data is changing. Current",
"behavior of returning an R vector is deprecated, and in a future",
"release, it will return an Arrow `ChunkedArray`. To control this:"
),
i = paste(
"Specify `as_vector = TRUE` (the current default) or",
"`FALSE` (what it will change to) in `pull()`"
),
i = "Or, set `options(arrow.pull_as_vector)` globally"
),
.frequency = "regularly",
.frequency_id = "arrow.pull_as_vector",
class = "lifecycle_warning_deprecated"
)
as_vector <- TRUE
}
if (as_vector) {
out <- as.vector(out)
}
Expand Down
2 changes: 1 addition & 1 deletion r/R/dplyr-funcs-doc.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#' * [`inner_join()`][dplyr::inner_join()]: the `copy` argument is ignored
#' * [`left_join()`][dplyr::left_join()]: the `copy` argument is ignored
#' * [`mutate()`][dplyr::mutate()]
#' * [`pull()`][dplyr::pull()]: the `name` argument is not supported; returns an R vector by default but this behavior is deprecated and will return an Arrow [ChunkedArray] in a future release. Provide `as_vector = TRUE/FALSE` to control this behavior, or set `options(arrow.pull_as_vector)` globally.
#' * [`pull()`][dplyr::pull()]: the `name` argument is not supported; returns an R vector by default. Provide `as_vector = FALSE` to return an Arrow [ChunkedArray] instead, or set `options(arrow.pull_as_vector = FALSE)` globally.
#' * [`relocate()`][dplyr::relocate()]
#' * [`rename()`][dplyr::rename()]
#' * [`rename_with()`][dplyr::rename_with()]
Expand Down
2 changes: 1 addition & 1 deletion r/man/acero.Rd

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

4 changes: 1 addition & 3 deletions r/man/map_batches.Rd

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

4 changes: 0 additions & 4 deletions r/tests/testthat/helper-arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ Sys.setlocale("LC_COLLATE", "C")
# (R CMD check does this, but in case you're running outside of check)
Sys.setenv(LANGUAGE = "en")

# Set this option so that the deprecation warning isn't shown
# (except when we test for it)
options(arrow.pull_as_vector = FALSE)

with_language <- function(lang, expr) {
skip_on_cran()
skip_if_not(capabilities("NLS"))
Expand Down
26 changes: 15 additions & 11 deletions r/tests/testthat/test-dplyr-query.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,6 @@ test_that("pull", {
)
})

test_that("pull() shows a deprecation warning if the option isn't set", {
expect_warning(
vec <- tbl |>
arrow_table() |>
pull(as_vector = NULL),
"Current behavior of returning an R vector is deprecated"
)
# And the default is the old behavior, an R vector
expect_identical(vec, pull(tbl))
})

test_that("collect(as_data_frame=FALSE)", {
batch <- record_batch(tbl)

Expand Down Expand Up @@ -761,3 +750,18 @@ test_that("nested field ref error handling", {
"No match"
)
})

test_that("pull() returns an R vector by default", {
withr::local_options(arrow.pull_as_vector = NULL)
tab <- arrow_table(tbl)

expect_no_warning(out <- pull(tab, int))
expect_identical(out, tbl$int)
expect_no_warning(out <- pull(tab |> filter(int > 4), int))
expect_identical(out, tbl$int[!is.na(tbl$int) & tbl$int > 4])

expect_r6_class(pull(tab, int, as_vector = FALSE), "ChunkedArray")

withr::local_options(arrow.pull_as_vector = FALSE)
expect_r6_class(pull(tab, int), "ChunkedArray")
})
Loading