Skip to content

Commit

Permalink
refactor: simplify type check for struct nanoarrow_array_stream
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed May 6, 2024
1 parent c6b4ee7 commit 8de1e21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/as_polars.R
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ as_polars_df.nanoarrow_array = function(x, ...) {
#' @rdname as_polars_df
#' @export
as_polars_df.nanoarrow_array_stream = function(x, ...) {
if (!inherits(nanoarrow::infer_nanoarrow_ptype(x$get_schema()), "data.frame")) {
if (!identical(nanoarrow::nanoarrow_schema_parse(x$get_schema())$type, "struct")) {
Err_plain("Can't convert non-struct array stream to RPolarsDataFrame") |>
unwrap("in as_polars_df(<nanoarrow_array_stream>):")
}
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-arrow-c-interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ patrick::with_parameters_test_that("round trip arrow array stream",
as_polars_series()
)
)

expect_true(
as_polars_df(.vec)$equals(
as_polars_df(.vec) |>
nanoarrow::as_nanoarrow_array_stream(future = TRUE) |>
as_polars_df()
)
)
},
.vec = list(
1:5,
Expand Down

0 comments on commit 8de1e21

Please sign in to comment.