Skip to content
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

feat(r): Allow opt-out of warning for unregistered extension types #632

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 4 additions & 0 deletions r/R/convert-array.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#' dispatching on `to`: developers may implement their own S3 methods for
#' custom vector types.
#'
#' Note that unregistered extension types will by default issue a warning.
#' Use `options(nanoarrow.warn_unregistered_extension = FALSE)` to disable
#' this behaviour.
#'
#' @param array A [nanoarrow_array][as_nanoarrow_array].
#' @param to A target prototype object describing the type to which `array`
#' should be converted, or `NULL` to use the default conversion as
Expand Down
6 changes: 6 additions & 0 deletions r/R/extension.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ nanoarrow_extension_array <- function(storage_array, extension_name,
}

warn_unregistered_extension_type <- function(x) {
# Allow an opt-out of this warning for consumers that don't have
# control over their source and want to drop unknown extensions
if (!getOption("nanoarrow.warn_unregistered_extension", TRUE)) {
return()
}

# Warn that we're about to ignore an extension type
if (!is.null(x$name) && !identical(x$name, "")) {
warning(
Expand Down
4 changes: 4 additions & 0 deletions r/man/convert_array.Rd

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

14 changes: 14 additions & 0 deletions r/tests/testthat/test-extension.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ test_that("as_nanoarrow_array() dispatches on registered extension spec", {
)
})

test_that("inferring the type of an unregistered extension warns", {
expect_warning(
infer_nanoarrow_ptype(na_extension(na_int32(), "definitely not registered")),
"Converting unknown extension"
)

previous_opts <- options(nanoarrow.warn_unregistered_extension = FALSE)
on.exit(options(previous_opts))
expect_warning(
infer_nanoarrow_ptype(na_extension(na_int32(), "definitely not registered")),
NA
)
})

test_that("extensions can infer a schema of a nanoarrow_vctr() subclass", {
register_nanoarrow_extension(
"some_ext",
Expand Down
Loading