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

Make it easier to create a DataFrame with a single list-column #794

Closed
etiennebacher opened this issue Feb 8, 2024 · 0 comments · Fixed by #796
Closed

Make it easier to create a DataFrame with a single list-column #794

etiennebacher opened this issue Feb 8, 2024 · 0 comments · Fixed by #796
Labels
enhancement New feature or request

Comments

@etiennebacher
Copy link
Collaborator

To create a DataFrame with a single list column, we need to wrap the input in list() which is annoying:

library(polars)
options(polars.do_not_repeat_call = TRUE)

pl$DataFrame(list(x = list(1:2, 3:10)))
#> shape: (2, 1)
#> ┌──────────────┐
#> │ x            │
#> │ ---          │
#> │ list[i32]    │
#> ╞══════════════╡
#> │ [1, 2]       │
#> │ [3, 4, … 10] │
#> └──────────────┘

# this should work
pl$DataFrame(x = list(1:2, 3:10))
#> Error: Execution halted with the following contexts
#>    0: In R: in $DataFrame():
#>    1: Encountered the following error in Rust-Polars:
#>          Series length 2 doesn't match the DataFrame height of 8

Note that there's no problem to create a DataFrame with >= 2 list-columns:

pl$DataFrame(x = list(1:2, 3:10), y = list(1:2, 3:10))
#> shape: (2, 2)
#> ┌──────────────┬──────────────┐
#> │ x            ┆ y            │
#> │ ---          ┆ ---          │
#> │ list[i32]    ┆ list[i32]    │
#> ╞══════════════╪══════════════╡
#> │ [1, 2]       ┆ [1, 2]       │
#> │ [3, 4, … 10] ┆ [3, 4, … 10] │
#> └──────────────┴──────────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant