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

rewrite as_polars_series() for nested types #1020

Closed
eitsupi opened this issue Apr 9, 2024 · 0 comments · Fixed by #1021
Closed

rewrite as_polars_series() for nested types #1020

eitsupi opened this issue Apr 9, 2024 · 0 comments · Fixed by #1021
Labels
enhancement New feature or request

Comments

@eitsupi
Copy link
Collaborator

eitsupi commented Apr 9, 2024

Related to #1012

Currently, due to the following processing, the types in list are processed ignoring the S3 method of as_polars_series, so appropriate type conversion is not performed.

Rtype::List => {
// Recusively handle elements of list
let result_series_vec: pl::PolarsResult<Vec<SeriesTree>> = collect_hinted_result(
x.len(),
x.as_list()
.unwrap()
.iter()
.map(|(name, robj)| recursive_robjname2series_tree(&robj, name)),
);
result_series_vec.map(|vst| {
if vst.is_empty() {
SeriesTree::SeriesEmptyVec // flag empty list() with this enum, to resolve polars type later
} else {
SeriesTree::SeriesVec(vst)
}
})
}

Like this:

polars::as_polars_series(list(data.frame(a = 1), data.frame(a = 2)))
#> polars Series: shape: (2,)
#> Series: '' [list[list[f64]]]
#> [
#>  [[1.0]]
#>  [[2.0]]
#> ]
arrow::as_arrow_array(list(data.frame(a = 1), data.frame(a = 2)))
#> ListArray
#> <list<item: struct<a: double>>>
#> [
#>   -- is_valid: all not null
#>   -- child 0 type: double
#>     [
#>       1
#>     ],
#>   -- is_valid: all not null
#>   -- child 0 type: double
#>     [
#>       2
#>     ]
#> ]
polars::as_polars_series(arrow::as_arrow_array(list(data.frame(a = 1), data.frame(a = 2))))
#> polars Series: shape: (2,)
#> Series: '' [list[struct[1]]]
#> [
#>  [{1.0}]
#>  [{2.0}]
#> ]

Created on 2024-04-09 with reprex v2.1.0

We probably need to use as_polars_series.list and a function that constructs Series from R list of RPolarsSeries in Rust side.

@eitsupi eitsupi added the enhancement New feature or request label Apr 9, 2024
@eitsupi eitsupi changed the title rewrite as_polars_series() rewrite as_polars_series() for nested types Apr 9, 2024
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