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

refactor: several updates to dsl.rs #1093

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,5 @@ Collate:
'zzz.R'
Config/rextendr/version: 0.3.1
VignetteBuilder: knitr
Config/polars/LibVersion: 0.39.3
Config/polars/LibVersion: 0.39.4
Config/polars/RustToolchainVersion: nightly-2024-04-15
19 changes: 9 additions & 10 deletions R/expr__datetime.R
Original file line number Diff line number Diff line change
Expand Up @@ -535,21 +535,20 @@ ExprDT_nanosecond = function() {
#' as_polars_series(as.Date("2022-1-1"))$dt$epoch("d")
ExprDT_epoch = function(tu = c("us", "ns", "ms", "s", "d")) {
tu = tu[1]
uw = \(res) unwrap(res, "in $dt$epoch:")

# experimental rust-like error handling on R side for the fun of it, sorry
# jokes aside here the use case is to tie various rust functions together
# and add context to the error messages
expr_result = pcase(
!is_string(tu), Err("tu must be a string"),
tu %in% c("ms", "us", "ns"), .pr$Expr$timestamp(self, tu),
tu == "s", Ok(.pr$Expr$dt_epoch_seconds(self)),
tu == "d", Ok(self$cast(pl$Date)$cast(pl$Int32)),
pcase(
!is_string(tu), Err("tu must be a string") |> uw(),
tu %in% c("ms", "us", "ns"), .pr$Expr$dt_timestamp(self, tu) |> uw(),
tu == "s", .pr$Expr$dt_epoch_seconds(self),
tu == "d", self$cast(pl$Date)$cast(pl$Int32),
or_else = Err(
paste("tu must be one of 'ns', 'us', 'ms', 's', 'd', got", str_string(tu))
)
) |> map_err(\(err) paste("in $dt$epoch:", err))

unwrap(expr_result)
) |> uw()
)
}


Expand All @@ -574,7 +573,7 @@ ExprDT_epoch = function(tu = c("us", "ns", "ms", "s", "d")) {
#' pl$col("date")$dt$timestamp(tu = "ms")$alias("timestamp_ms")
#' )
ExprDT_timestamp = function(tu = c("ns", "us", "ms")) {
.pr$Expr$timestamp(self, tu[1]) |>
.pr$Expr$dt_timestamp(self, tu[1]) |>
map_err(\(err) paste("in $dt$timestamp:", err)) |>
unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion R/expr__meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ExprMeta_pop = function() {
#' e = (pl$col("alice") + pl$col("eve"))$alias("bob")
#' e$meta$root_names()
ExprMeta_root_names = function() {
.pr$Expr$meta_roots(self)
.pr$Expr$meta_root_names(self)
}


Expand Down
6 changes: 3 additions & 3 deletions R/extendr-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ RPolarsExpr$rolling_median <- function(window_size, weights, min_periods, center

RPolarsExpr$rolling_quantile <- function(quantile, interpolation, window_size, weights, min_periods, center, by, closed, warn_if_unsorted) .Call(wrap__RPolarsExpr__rolling_quantile, self, quantile, interpolation, window_size, weights, min_periods, center, by, closed, warn_if_unsorted)

RPolarsExpr$rolling_skew <- function(window_size_f, bias) .Call(wrap__RPolarsExpr__rolling_skew, self, window_size_f, bias)
RPolarsExpr$rolling_skew <- function(window_size, bias) .Call(wrap__RPolarsExpr__rolling_skew, self, window_size, bias)

RPolarsExpr$abs <- function() .Call(wrap__RPolarsExpr__abs, self)

Expand Down Expand Up @@ -820,7 +820,7 @@ RPolarsExpr$dt_microsecond <- function() .Call(wrap__RPolarsExpr__dt_microsecond

RPolarsExpr$dt_nanosecond <- function() .Call(wrap__RPolarsExpr__dt_nanosecond, self)

RPolarsExpr$timestamp <- function(tu) .Call(wrap__RPolarsExpr__timestamp, self, tu)
RPolarsExpr$dt_timestamp <- function(tu) .Call(wrap__RPolarsExpr__dt_timestamp, self, tu)

RPolarsExpr$dt_epoch_seconds <- function() .Call(wrap__RPolarsExpr__dt_epoch_seconds, self)

Expand Down Expand Up @@ -1096,7 +1096,7 @@ RPolarsExpr$meta_pop <- function() .Call(wrap__RPolarsExpr__meta_pop, self)

RPolarsExpr$meta_eq <- function(other) .Call(wrap__RPolarsExpr__meta_eq, self, other)

RPolarsExpr$meta_roots <- function() .Call(wrap__RPolarsExpr__meta_roots, self)
RPolarsExpr$meta_root_names <- function() .Call(wrap__RPolarsExpr__meta_root_names, self)

RPolarsExpr$meta_output_name <- function() .Call(wrap__RPolarsExpr__meta_output_name, self)

Expand Down
2 changes: 1 addition & 1 deletion src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "r-polars"
version = "0.39.3"
version = "0.39.4"
edition = "2021"
rust-version = "1.76.0"
publish = false
Expand Down
Loading
Loading