Skip to content

Commit

Permalink
more fixes [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Jun 23, 2024
1 parent 7b174f5 commit bfb59c7
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 19 deletions.
2 changes: 1 addition & 1 deletion R/extendr-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ RPolarsDataFrame$estimated_size <- function() .Call(wrap__RPolarsDataFrame__esti

RPolarsDataFrame$null_count <- function() .Call(wrap__RPolarsDataFrame__null_count, self)

RPolarsDataFrame$unpivot <- function(on, index, value_name, variable_name, streamable) .Call(wrap__RPolarsDataFrame__unpivot, self, on, index, value_name, variable_name, streamable)
RPolarsDataFrame$unpivot <- function(on, index, value_name, variable_name) .Call(wrap__RPolarsDataFrame__unpivot, self, on, index, value_name, variable_name)

RPolarsDataFrame$pivot_expr <- function(on, index, values, maintain_order, sort_columns, aggregate_expr, separator) .Call(wrap__RPolarsDataFrame__pivot_expr, self, on, index, values, maintain_order, sort_columns, aggregate_expr, separator)

Expand Down
3 changes: 1 addition & 2 deletions src/rust/src/rdataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,13 @@ impl RPolarsDataFrame {
index: Robj,
value_name: Robj,
variable_name: Robj,
streamable: Robj,
) -> RResult<Self> {
let args = UnpivotArgs {
on: strings_to_smartstrings(robj_to!(Vec, String, on)?),
index: strings_to_smartstrings(robj_to!(Vec, String, index)?),
value_name: robj_to!(Option, String, value_name)?.map(|s| s.into()),
variable_name: robj_to!(Option, String, variable_name)?.map(|s| s.into()),
streamable: robj_to!(bool, streamable)?,
streamable: false,
};

self.0
Expand Down
219 changes: 219 additions & 0 deletions tests/testthat/_snaps/after-wrappers.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,179 @@
[181] "unique" "unique_counts" "upper_bound"
[184] "value_counts" "var" "xor"

---

Code
ls(.pr[[private_key]])
Output
[1] "abs" "add"
[3] "agg_groups" "alias"
[5] "all" "and"
[7] "any" "append"
[9] "approx_n_unique" "arccos"
[11] "arccosh" "arcsin"
[13] "arcsinh" "arctan"
[15] "arctanh" "arg_max"
[17] "arg_min" "arg_sort"
[19] "arg_unique" "arr_all"
[21] "arr_any" "arr_arg_max"
[23] "arr_arg_min" "arr_contains"
[25] "arr_count_matches" "arr_get"
[27] "arr_join" "arr_max"
[29] "arr_median" "arr_min"
[31] "arr_reverse" "arr_shift"
[33] "arr_sort" "arr_std"
[35] "arr_sum" "arr_to_list"
[37] "arr_to_struct" "arr_unique"
[39] "arr_var" "backward_fill"
[41] "bin_base64_decode" "bin_base64_encode"
[43] "bin_contains" "bin_ends_with"
[45] "bin_hex_decode" "bin_hex_encode"
[47] "bin_starts_with" "bottom_k"
[49] "cast" "cat_get_categories"
[51] "cat_set_ordering" "ceil"
[53] "clip" "clip_max"
[55] "clip_min" "col"
[57] "cols" "corr"
[59] "cos" "cosh"
[61] "count" "cov"
[63] "cum_count" "cum_max"
[65] "cum_min" "cum_prod"
[67] "cum_sum" "cumulative_eval"
[69] "cut" "diff"
[71] "div" "dot"
[73] "drop_nans" "drop_nulls"
[75] "dt_cast_time_unit" "dt_combine"
[77] "dt_convert_time_zone" "dt_day"
[79] "dt_epoch_seconds" "dt_hour"
[81] "dt_is_leap_year" "dt_iso_year"
[83] "dt_microsecond" "dt_millisecond"
[85] "dt_minute" "dt_month"
[87] "dt_nanosecond" "dt_offset_by"
[89] "dt_ordinal_day" "dt_quarter"
[91] "dt_replace_time_zone" "dt_round"
[93] "dt_second" "dt_strftime"
[95] "dt_time" "dt_timestamp"
[97] "dt_total_days" "dt_total_hours"
[99] "dt_total_microseconds" "dt_total_milliseconds"
[101] "dt_total_minutes" "dt_total_nanoseconds"
[103] "dt_total_seconds" "dt_truncate"
[105] "dt_week" "dt_weekday"
[107] "dt_with_time_unit" "dt_year"
[109] "dtype_cols" "entropy"
[111] "eq" "eq_missing"
[113] "ewm_mean" "ewm_std"
[115] "ewm_var" "exclude"
[117] "exclude_dtype" "exp"
[119] "explode" "extend_constant"
[121] "fill_nan" "fill_null"
[123] "fill_null_with_strategy" "filter"
[125] "first" "flatten"
[127] "floor" "floor_div"
[129] "forward_fill" "gather"
[131] "gather_every" "gt"
[133] "gt_eq" "hash"
[135] "head" "implode"
[137] "interpolate" "is_between"
[139] "is_duplicated" "is_finite"
[141] "is_first_distinct" "is_in"
[143] "is_infinite" "is_last_distinct"
[145] "is_nan" "is_not_nan"
[147] "is_not_null" "is_null"
[149] "is_unique" "kurtosis"
[151] "last" "len"
[153] "list_all" "list_any"
[155] "list_arg_max" "list_arg_min"
[157] "list_contains" "list_diff"
[159] "list_eval" "list_gather"
[161] "list_gather_every" "list_get"
[163] "list_join" "list_len"
[165] "list_max" "list_mean"
[167] "list_min" "list_n_unique"
[169] "list_reverse" "list_set_operation"
[171] "list_shift" "list_slice"
[173] "list_sort" "list_sum"
[175] "list_to_struct" "list_unique"
[177] "lit" "log"
[179] "log10" "lower_bound"
[181] "lt" "lt_eq"
[183] "map_batches" "map_batches_in_background"
[185] "map_elements_in_background" "max"
[187] "mean" "median"
[189] "meta_eq" "meta_has_multiple_outputs"
[191] "meta_is_regex_projection" "meta_output_name"
[193] "meta_pop" "meta_root_names"
[195] "meta_tree_format" "meta_undo_aliases"
[197] "min" "mode"
[199] "mul" "n_unique"
[201] "name_keep" "name_map"
[203] "name_prefix" "name_prefix_fields"
[205] "name_suffix" "name_suffix_fields"
[207] "name_to_lowercase" "name_to_uppercase"
[209] "nan_max" "nan_min"
[211] "neq" "neq_missing"
[213] "new_first" "new_last"
[215] "new_len" "not"
[217] "null_count" "or"
[219] "over" "pct_change"
[221] "peak_max" "peak_min"
[223] "pow" "print"
[225] "product" "qcut"
[227] "qcut_uniform" "quantile"
[229] "rank" "rechunk"
[231] "reinterpret" "rem"
[233] "rep" "repeat_by"
[235] "replace" "replace_strict"
[237] "reshape" "reverse"
[239] "rle" "rle_id"
[241] "rolling" "rolling_corr"
[243] "rolling_cov" "rolling_max"
[245] "rolling_max_by" "rolling_mean"
[247] "rolling_mean_by" "rolling_median"
[249] "rolling_median_by" "rolling_min"
[251] "rolling_min_by" "rolling_quantile"
[253] "rolling_quantile_by" "rolling_skew"
[255] "rolling_std" "rolling_std_by"
[257] "rolling_sum" "rolling_sum_by"
[259] "rolling_var" "rolling_var_by"
[261] "round" "sample_frac"
[263] "sample_n" "search_sorted"
[265] "shift" "shift_and_fill"
[267] "shrink_dtype" "shuffle"
[269] "sign" "sin"
[271] "sinh" "skew"
[273] "slice" "sort_by"
[275] "sort_with" "std"
[277] "str_base64_decode" "str_base64_encode"
[279] "str_contains" "str_contains_any"
[281] "str_count_matches" "str_ends_with"
[283] "str_extract" "str_extract_all"
[285] "str_extract_groups" "str_find"
[287] "str_head" "str_hex_decode"
[289] "str_hex_encode" "str_join"
[291] "str_json_decode" "str_json_path_match"
[293] "str_len_bytes" "str_len_chars"
[295] "str_pad_end" "str_pad_start"
[297] "str_replace" "str_replace_all"
[299] "str_replace_many" "str_reverse"
[301] "str_slice" "str_split"
[303] "str_split_exact" "str_splitn"
[305] "str_starts_with" "str_strip_chars"
[307] "str_strip_chars_end" "str_strip_chars_start"
[309] "str_tail" "str_to_date"
[311] "str_to_datetime" "str_to_integer"
[313] "str_to_lowercase" "str_to_time"
[315] "str_to_titlecase" "str_to_uppercase"
[317] "str_zfill" "struct_field_by_name"
[319] "struct_rename_fields" "struct_with_fields"
[321] "sub" "sum"
[323] "tail" "tan"
[325] "tanh" "to_physical"
[327] "top_k" "unique"
[329] "unique_counts" "unique_stable"
[331] "upper_bound" "value_counts"
[333] "var" "xor"

# public and private methods of each class When

Code
Expand Down Expand Up @@ -360,6 +533,13 @@
[184] "upper_bound" "value_counts" "var"
[187] "when" "xor"

---

Code
ls(.pr[[private_key]])
Output
[1] "otherwise" "when"

# public and private methods of each class ChainedWhen

Code
Expand Down Expand Up @@ -443,6 +623,13 @@
[184] "upper_bound" "value_counts" "var"
[187] "when" "xor"

---

Code
ls(.pr[[private_key]])
Output
[1] "otherwise" "when"

# public and private methods of each class RField

Code
Expand Down Expand Up @@ -530,6 +717,38 @@
[193] "upper_bound" "value_counts" "var"
[196] "xor"

---

Code
ls(.pr[[private_key]])
Output
[1] "add" "alias"
[3] "all" "any"
[5] "append_mut" "arg_max"
[7] "arg_min" "can_fast_explode_flag"
[9] "chunk_lengths" "clear"
[11] "clone" "compare"
[13] "div" "dtype"
[15] "equals" "export_stream"
[17] "from_arrow_array_robj" "get_fmt"
[19] "import_stream" "is_sorted"
[21] "is_sorted_ascending_flag" "is_sorted_descending_flag"
[23] "len" "map_elements"
[25] "max" "mean"
[27] "median" "min"
[29] "mul" "n_chunks"
[31] "n_unique" "name"
[33] "new" "panic"
[35] "print" "rem"
[37] "rename_mut" "rep"
[39] "set_sorted_mut" "shape"
[41] "sleep" "sort"
[43] "std" "struct_fields"
[45] "sub" "sum"
[47] "to_fmt_char" "to_frame"
[49] "to_r" "value_counts"
[51] "var"

# public and private methods of each class RThreadHandle

Code
Expand Down
15 changes: 3 additions & 12 deletions tests/testthat/test-expr_datetime.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ test_that("dt$truncate", {

# use a dt namespace function
df = pl$DataFrame(datetime = s)$with_columns(
pl$col("datetime")$dt$truncate("4s")$alias("truncated_4s"),
pl$col("datetime")$dt$truncate("4s", offset("3s"))$alias("truncated_4s_offset_2s")
pl$col("datetime")$dt$truncate("4s")$alias("truncated_4s")
)

l_actual = df$to_list()
Expand All @@ -128,20 +127,16 @@ test_that("dt$round", {
s = pl$datetime_range(t1, t2, interval = "2s", time_unit = "ms")

# use a dt namespace function
## TODO contribute POLARS, offset makes little sense, it should be implemented
## before round not after.
df = pl$DataFrame(datetime = s)$with_columns(
pl$col("datetime")$dt$round("8s")$alias("truncated_4s"),
pl$col("datetime")$dt$round("8s", offset("4s1ms"))$alias("truncated_4s_offset_2s")
pl$col("datetime")$dt$round("8s")$alias("truncated_4s")
)

l_actual = df$to_list()
expect_identical(
lapply(l_actual, \(x) diff(x) |> as.numeric()),
list(
datetime = rep(2, 12),
truncated_4s = rep(c(0, 8, 0, 0), 3),
truncated_4s_offset_2s = rep(c(0, 8, 0, 0), 3)
truncated_4s = rep(c(0, 8, 0, 0), 3)
)
)

Expand All @@ -153,10 +148,6 @@ test_that("dt$round", {
pl$col("datetime")$dt$round(c("2s", "1h")),
"`every` must be a single non-NA character or difftime"
)
expect_grepl_error(
pl$col("datetime")$dt$round("1s", 42),
"`offset` must be a single non-NA character or difftime"
)
})

test_that("dt$combine", {
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-expr_expr.R
Original file line number Diff line number Diff line change
Expand Up @@ -896,14 +896,14 @@ test_that("Expr_sort", {
})


test_that("Expr_k_top", {
test_that("$top_k() works", {
l = list(a = c(6, 1, 0, NA, Inf, -Inf, NaN))

l_actual = pl$DataFrame(l)$select(
pl$col("a")$top_k(3)$alias("k_top"),
pl$col("a")$bottom_k(3)$alias("k_bot")
)
known = structure(list(k_top = c(NaN, Inf, 6), k_bot = c(NA, -Inf, 0)),
known = structure(list(k_top = c(NaN, Inf, 6), k_bot = c(-Inf, 0, 1)),
row.names = c(NA, -3L), class = "data.frame"
)
expect_equal(l_actual$to_data_frame(), known)
Expand Down Expand Up @@ -2913,8 +2913,8 @@ test_that("rle works", {
expect_equal(
df$select(pl$col("s")$rle())$unnest("s")$to_data_frame(),
data.frame(
lengths = c(2, 1, 1, 1, 1, 2),
values = c(1, 2, 1, NA, 1, 3)
len = c(2, 1, 1, 1, 1, 2),
value = c(1, 2, 1, NA, 1, 3)
)
)
})
Expand Down

0 comments on commit bfb59c7

Please sign in to comment.