Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.2k
ARROW-11705: [R] Support scalar value recycling in RecordBatch/Table$create()#10269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f17c4ad9ad7264ed665950dc7666830ff2bb7094cdd57c33cc4788250d298f749058399ad9a4965b18e5789e850f071f2e4aa1eebd148a8bc791aebe7ff7d8e3df47e95463e38b6de2cfff1377d044bfbFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -139,3 +139,48 @@ attr(is_writable_table, "fail") <- function(call, env){ | ||
| ) | ||
| } | ||
| #' Recycle scalar values in a list of arrays | ||
| #' | ||
| #' @param arrays List of arrays | ||
| #' @return List of arrays with any vector/Scalar/Array/ChunkedArray values of length 1 recycled | ||
| #' @keywords internal | ||
| recycle_scalars <- function(arrays){ | ||
| # Get lengths of items in arrays | ||
| arr_lens <- map_int(arrays, NROW) | ||
thisisnic marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| is_scalar <- arr_lens == 1 | ||
| if (length(arrays) > 1 && any(is_scalar) && !all(is_scalar)) { | ||
| # Recycling not supported for tibbles and data.frames | ||
| if (all(map_lgl(arrays, ~inherits(.x, "data.frame")))) { | ||
| abort(c( | ||
| "All input tibbles or data.frames must have the same number of rows", | ||
| x = paste( | ||
| "Number of rows in longest and shortest inputs:", | ||
| oxford_paste(c(max(arr_lens), min(arr_lens))) | ||
| ) | ||
| )) | ||
| } | ||
| max_array_len <- max(arr_lens) | ||
| arrays[is_scalar] <- lapply(arrays[is_scalar], repeat_value_as_array, max_array_len) | ||
| } | ||
| arrays | ||
| } | ||
| #' Take an object of length 1 and repeat it. | ||
| #' | ||
| #' @param object Object of length 1 to be repeated - vector, `Scalar`, `Array`, or `ChunkedArray` | ||
| #' @param n Number of repetitions | ||
| #' | ||
| #' @return `Array` of length `n` | ||
| #' | ||
| #' @keywords internal | ||
| repeat_value_as_array <- function(object, n) { | ||
| if (inherits(object, "ChunkedArray")) { | ||
| return(Scalar$create(object$chunks[[1]])$as_array(n)) | ||
| } | ||
| return(Scalar$create(object)$as_array(n)) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.