-
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
Do we have a way to create object
and struct
with classic R functions?
#1012
Comments
Are you looking for |
IIUC, the object type is Python-specific, not a real Apache Arrow type (so we don't support it). |
This is equivalent to calling a list: > pl$Series(values = data.frame(a = 1))
polars Series: shape: (1,)
Series: '' [list[f64]]
[
[1.0]
]
> pl$Series(values = list(a = 1))
polars Series: shape: (1,)
Series: '' [list[f64]]
[
[1.0]
] |
Oh, sorry. This is the one. Lines 367 to 371 in 3c0d0ec
|
Can we close this now that #1015 has been merged? |
That's something worth mentioning in the docs I think. I'll add that in #1014 and close this issue with this PR |
Actually it's hard to construct >>> pl.Series([{"a": 1, "b": ["x", "y"]}, {"a": 2, "b": ["z"]}])
shape: (2,)
Series: '' [struct[2]]
[
{1,["x", "y"]}
{2,["z"]}
] as_polars_series(
data.frame(a = 1:2, b = list(c("x", "y"), "z"))
)
polars Series: shape: (2,)
Series: '' [struct[3]]
[
{1,"x","z"}
{2,"y","z"}
] And it doesn't work for pl$DataFrame(
data.frame(a = 1)
)
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ f64 │
╞═════╡
│ 1.0 │
└─────┘ Maybe we should say that we can't reliably create a |
We should use the polars::as_polars_series(
data.frame(a = 1:2, b = list(c("x", "y"), "z"))
)
#> polars Series: shape: (2,)
#> Series: '' [struct[3]]
#> [
#> {1,"x","z"}
#> {2,"y","z"}
#> ]
polars::as_polars_series(
data.frame(a = 1:2, b = I(list(c("x", "y"), "z")))
)
#> polars Series: shape: (2,)
#> Series: '' [struct[2]]
#> [
#> {1,["x", "y"]}
#> {2,["z"]}
#> ]
polars::as_polars_series(
tibble::tibble(a = 1:2, b = list(c("x", "y"), "z"))
)
#> polars Series: shape: (2,)
#> Series: '' [struct[2]]
#> [
#> {1,["x", "y"]}
#> {2,["z"]}
#> ]
polars::as_polars_series(
data.table::data.table(a = 1:2, b = list(c("x", "y"), "z"))
)
#> polars Series: shape: (2,)
#> Series: '' [struct[2]]
#> [
#> {1,["x", "y"]}
#> {2,["z"]}
#> ] Created on 2024-04-10 with reprex v2.1.0
polars::pl$DataFrame(data.frame(a = 1))
#> shape: (1, 1)
#> ┌─────┐
#> │ a │
#> │ --- │
#> │ f64 │
#> ╞═════╡
#> │ 1.0 │
#> └─────┘
polars::pl$DataFrame(a = data.frame(a = 1))
#> shape: (1, 1)
#> ┌───────────┐
#> │ a │
#> │ --- │
#> │ struct[1] │
#> ╞═══════════╡
#> │ {1.0} │
#> └───────────┘ Created on 2024-04-10 with reprex v2.1.0 |
I don't think we have a way to create
object
andstruct
from our standardc()
andlist()
but maybe I'm missing something?It would be good to have a small table in the docs to show the equivalent (if any) of those:
The text was updated successfully, but these errors were encountered: