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

WIP: PoC for storing pure polars calls in attributes #103

Draft
wants to merge 53 commits into
base: main
Choose a base branch
from

Conversation

etiennebacher
Copy link
Owner

@etiennebacher etiennebacher commented Mar 23, 2024

Close #96

Example:

library(tidypolars)
library(dplyr, warn.conflicts = FALSE)

iris |> 
  as_polars_df() |> 
  select(starts_with(c("Sep", "Pet"))) |> 
  mutate(x = (Petal.Length / Petal.Width) > 3) |> 
  filter(between(Sepal.Length, 4.5, 6.5), Petal.Length < 5) |> 
  head() |> 
  show_query()
#> Pure polars expression:
#> 
#> <data>$
#>   select(c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"))$
#>   with_columns(x = p$col("Petal.Length")$div(p$col("Petal.Width"))$gt(3))$
#>   filter(p$col("Sepal.Length")$is_between(lower_bound = 4.5, upper_bound = 6.5, closed = "both"), p$col("Petal.Length")$lt(5))$
#>   head(n = 6L)

TODO:

  • wrap up, pass tests
  • prepare snapshot tests
  • refactor, add comments
  • potentially write a vignette for future self + interested readers
  • wrong query for bind_cols_polars()
  • class of original data shouldn't change
library(dplyr, warn.conflicts = FALSE)
library(tidypolars)

pl_relig_income <- as_polars_df(tidyr::relig_income)

class(pl_relig_income)
#> [1] "RPolarsDataFrame"

x <- pl_relig_income |>
  arrange(drat)

class(pl_relig_income)
#> [1] "tidypolars"       "RPolarsDataFrame"

@eitsupi
Copy link

eitsupi commented Mar 31, 2024

It may helpful the tidyquery package's code.
https://github.com/ianmcook/tidyquery

The tidyquery package generates a dplyr query string from an SQL string and executes the actual dplyr query, but I believe the query to be displayed and the query to be executed were constructed separately (rather than being evaluated as is after the string is assembled)

@etiennebacher etiennebacher marked this pull request as draft April 3, 2024 14:20
@etiennebacher

This comment was marked as outdated.

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.

Function to show pure polars code
2 participants