-
Notifications
You must be signed in to change notification settings - Fork 36
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
Allow creation of empty DataFrame based on schema only #901
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but the review was insufficient.
return(.pr$DataFrame$default()) | ||
if (!is.null(schema)) { | ||
largs <- lapply(seq_along(schema), \(x) { | ||
pl$lit(numeric(0))$cast(schema[[x]])$alias(names(schema)[x]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use NULL
instead of numeric(0)
.
test_that("construct an empty DataFrame with schema only", { | ||
s <- as_polars_df(iris[, c(1, 2, 5)])$schema | ||
expect_identical( | ||
pl$DataFrame(schema = s)$to_list(), | ||
list(Sepal.Length = numeric(0), Sepal.Width = numeric(0), Species = factor()) | ||
) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More tests (more types) should be tested.
Close #900