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

Allow creation of empty DataFrame based on schema only #901

Merged
merged 2 commits into from
Mar 6, 2024

Conversation

etiennebacher
Copy link
Collaborator

Close #900

Copy link
Collaborator

@eitsupi eitsupi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@eitsupi eitsupi merged commit 7ceb83f into main Mar 6, 2024
18 checks passed
@eitsupi eitsupi deleted the empty-df-schema branch March 6, 2024 22:10
Copy link
Collaborator

@eitsupi eitsupi left a 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])
Copy link
Collaborator

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).

Comment on lines +175 to +181
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())
)
})
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't create 0-row DataFrame with the schema argument of pl$DataFrame()
2 participants