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

Enable $explode() for Data/LazyFrame #314

Merged
merged 5 commits into from
Jul 27, 2023
Merged

Enable $explode() for Data/LazyFrame #314

merged 5 commits into from
Jul 27, 2023

Conversation

etiennebacher
Copy link
Collaborator

To merge after #308. I just followed the code for sort_by()

library(polars)
df = pl$DataFrame(
  letters = c("a", "a", "b", "c"),
  numbers = list(1, NULL, c(4, 5), c(6, 7, 8)),
  numbers2 = list(1, NULL, c(4, 5), c(6, 7, 8))
)
df$explode("numbers", pl$col("numbers2"))
#> shape: (7, 3)
#> ┌─────────┬─────────┬──────────┐
#> │ letters ┆ numbers ┆ numbers2 │
#> │ ---     ┆ ---     ┆ ---      │
#> │ str     ┆ f64     ┆ f64      │
#> ╞═════════╪═════════╪══════════╡
#> │ a       ┆ 1.0     ┆ 1.0      │
#> │ a       ┆ null    ┆ null     │
#> │ b       ┆ 4.0     ┆ 4.0      │
#> │ b       ┆ 5.0     ┆ 5.0      │
#> │ c       ┆ 6.0     ┆ 6.0      │
#> │ c       ┆ 7.0     ┆ 7.0      │
#> │ c       ┆ 8.0     ┆ 8.0      │
#> └─────────┴─────────┴──────────┘

etiennebacher and others added 3 commits July 7, 2023 10:43
Merge branch 'main' into dataframe-explode

# Conflicts:
#	tests/testthat/test-lazy.R
@sorhawell
Copy link
Collaborator

sorhawell commented Jul 10, 2023

@etiennebacher I have improved robj_to! a bit . Ideally use of lapply(...,wrap_e_result) and ProtoExprArr can now be replaced with robj_to!(Vec, Expr) or robj_to!(Vec, ExprCol)[str_as_lit=FALSE].

robj_to! makes some very eleborate error messages with class

> err = pl$DataFrame(list(a = list(1:3,11:12)))$explode(list("a",complex())) |>
+   result() |>
+   unwrap_err()
> 
> #get contexts, call and info
> err$contexts()
$BadArgument
[1] "columns"

$Hint
[1] "element no. [2] "

$PlainErrorMessage
[1] "cannot be converted into an Expr"

$BadValue
[1] "Rvalue: [], Rsexp: Complexes, Rclass: [\"complex\"]"

$PlainErrorMessage
[1] "cannot make a column expression from:  cplx(0) "

> err$get_rcall()
[1] "unwrap_err(result(pl$DataFrame(list(a = list(1:3, 11:12)))$explode(list(\"a\", \n    complex()))))"
> err$get_rinfo()
[1] "in explode():"
> 

@sorhawell
Copy link
Collaborator

sorhawell commented Jul 10, 2023

showcase new catch any R error

> showcase = function() {
   stop("imma simple R err") |> 
     result() |>  #catch result and upgrade any raised error to RPolarsErr
     map_err(\(err) err$
               plain("happend while showcasing RPolarsErr")$
               when("talking about RPolarsErr")
     ) |>
     unwrap(" in showcase:")
}
> showcase()
Error: Execution halted with the following contexts
0: In R: in showcase:
0: During function call [showcase()]
1: When talking about RPolarsErr
2: happend while showcasing RPolarsErr
3: imma simple R err

@etiennebacher
Copy link
Collaborator Author

New error handling looks really nice!

@sorhawell sorhawell changed the title Enable $explode() for Data/LazyFrame MERGE AFTER 308: Enable $explode() for Data/LazyFrame Jul 17, 2023
Copy link
Collaborator

@sorhawell sorhawell left a comment

Choose a reason for hiding this comment

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

thanks @etiennebacher ! Looks good.

Requested to merge after 308. Merging whenever also ok I think.

@etiennebacher etiennebacher changed the title MERGE AFTER 308: Enable $explode() for Data/LazyFrame Enable $explode() for Data/LazyFrame Jul 27, 2023
@etiennebacher etiennebacher merged commit c24eb71 into main Jul 27, 2023
11 checks passed
@etiennebacher etiennebacher deleted the dataframe-explode branch July 27, 2023 18:18
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.

None yet

2 participants