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

Accept lists in select() #265

Merged
merged 4 commits into from
Jun 28, 2023
Merged

Accept lists in select() #265

merged 4 commits into from
Jun 28, 2023

Conversation

etiennebacher
Copy link
Collaborator

@etiennebacher etiennebacher commented Jun 27, 2023

Related to #259 (I couldn't deprecate construct_ProtoExprArray though so no problem to close this PR if you want to do it all at once in another PR).

New behaviour:

library(polars)
l_expr = list(
  pl$col("a"),
  pl$col("b")
)

pl$DataFrame(a = 1:3, b = 1:3, c = 1:3)$select(l_expr)
#> shape: (3, 2)
#> ┌─────┬─────┐
#> │ a   ┆ b   │
#> │ --- ┆ --- │
#> │ i32 ┆ i32 │
#> ╞═════╪═════╡
#> │ 1   ┆ 1   │
#> │ 2   ┆ 2   │
#> │ 3   ┆ 3   │
#> └─────┴─────┘
pl$DataFrame(a = 1:3, b = 1:3, c = 1:3)$select(l_expr, "c")
#> shape: (3, 3)
#> ┌─────┬─────┬─────┐
#> │ a   ┆ b   ┆ c   │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ i32 ┆ i32 │
#> ╞═════╪═════╪═════╡
#> │ 1   ┆ 1   ┆ 1   │
#> │ 2   ┆ 2   ┆ 2   │
#> │ 3   ┆ 3   ┆ 3   │
#> └─────┴─────┴─────┘

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.

awesome 🏆 🚀

@etiennebacher etiennebacher merged commit c42c139 into main Jun 28, 2023
8 checks passed
@etiennebacher etiennebacher deleted the select-list-expr branch June 28, 2023 07:32
Comment on lines +169 to +189
test_that("select with list of exprs", {
l_expr = list(pl$col("mpg"), pl$col("hp"))
l_expr2 = list(pl$col("mpg", "hp"))
l_expr3 = list(pl$col("mpg"))
l_expr4 = list(c("mpg", "hp"))
l_expr5 = list("mpg", "hp")

x1 = pl$DataFrame(mtcars)$select(l_expr)
x2 = pl$DataFrame(mtcars)$select(l_expr2)
x3 = pl$DataFrame(mtcars)$select(l_expr3, pl$col("hp"))
x4 = pl$DataFrame(mtcars)$select(pl$col("hp"), l_expr3)
x5 = pl$DataFrame(mtcars)$select(l_expr4)
x6 = pl$DataFrame(mtcars)$select(l_expr5)

expect_equal(x1$columns, c("mpg", "hp"))
expect_equal(x2$columns, c("mpg", "hp"))
expect_equal(x3$columns, c("mpg", "hp"))
expect_equal(x4$columns, c("mpg", "hp"))
expect_equal(x5$columns, c("mpg", "hp"))
expect_equal(x6$columns, c("mpg", "hp"))
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose these tests can be simplify by patrick.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've never used patrick, I find the tests hard to read (but feel free to modify those ofc)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't mind patrick for large combinatorial tests. Looks neat. I find, that if a patrick test fails, and it is not immediately clear to me why, then I will spend more time than normal to debug the test.

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

3 participants