polars-df 0.21.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/Cargo.lock +1 -1
- data/ext/polars/Cargo.toml +7 -1
- data/ext/polars/src/conversion/mod.rs +92 -4
- data/ext/polars/src/exceptions.rs +1 -0
- data/ext/polars/src/expr/array.rs +73 -4
- data/ext/polars/src/expr/binary.rs +26 -1
- data/ext/polars/src/expr/bitwise.rs +39 -0
- data/ext/polars/src/expr/categorical.rs +20 -0
- data/ext/polars/src/expr/datatype.rs +24 -1
- data/ext/polars/src/expr/datetime.rs +58 -0
- data/ext/polars/src/expr/general.rs +84 -5
- data/ext/polars/src/expr/list.rs +24 -0
- data/ext/polars/src/expr/meta.rs +11 -0
- data/ext/polars/src/expr/mod.rs +1 -0
- data/ext/polars/src/expr/name.rs +8 -0
- data/ext/polars/src/expr/rolling.rs +20 -0
- data/ext/polars/src/expr/string.rs +59 -0
- data/ext/polars/src/expr/struct.rs +9 -1
- data/ext/polars/src/functions/io.rs +19 -0
- data/ext/polars/src/functions/lazy.rs +4 -0
- data/ext/polars/src/lazyframe/general.rs +51 -0
- data/ext/polars/src/lib.rs +119 -10
- data/ext/polars/src/map/dataframe.rs +2 -2
- data/ext/polars/src/map/series.rs +1 -1
- data/ext/polars/src/series/aggregation.rs +44 -0
- data/ext/polars/src/series/general.rs +64 -4
- data/lib/polars/array_expr.rb +382 -3
- data/lib/polars/array_name_space.rb +281 -0
- data/lib/polars/binary_expr.rb +67 -0
- data/lib/polars/binary_name_space.rb +43 -0
- data/lib/polars/cat_expr.rb +224 -0
- data/lib/polars/cat_name_space.rb +138 -0
- data/lib/polars/config.rb +2 -2
- data/lib/polars/convert.rb +6 -6
- data/lib/polars/data_frame.rb +684 -19
- data/lib/polars/data_type_expr.rb +52 -0
- data/lib/polars/data_types.rb +14 -2
- data/lib/polars/date_time_expr.rb +251 -0
- data/lib/polars/date_time_name_space.rb +299 -0
- data/lib/polars/expr.rb +1213 -180
- data/lib/polars/functions/datatype.rb +21 -0
- data/lib/polars/functions/lazy.rb +13 -0
- data/lib/polars/io/csv.rb +1 -1
- data/lib/polars/io/json.rb +4 -4
- data/lib/polars/io/ndjson.rb +4 -4
- data/lib/polars/io/parquet.rb +27 -5
- data/lib/polars/lazy_frame.rb +936 -20
- data/lib/polars/list_expr.rb +196 -4
- data/lib/polars/list_name_space.rb +201 -4
- data/lib/polars/meta_expr.rb +64 -0
- data/lib/polars/name_expr.rb +36 -0
- data/lib/polars/schema.rb +79 -3
- data/lib/polars/selector.rb +72 -0
- data/lib/polars/selectors.rb +3 -3
- data/lib/polars/series.rb +1051 -54
- data/lib/polars/string_expr.rb +411 -6
- data/lib/polars/string_name_space.rb +722 -49
- data/lib/polars/struct_expr.rb +103 -0
- data/lib/polars/struct_name_space.rb +19 -1
- data/lib/polars/utils/various.rb +18 -1
- data/lib/polars/utils.rb +5 -1
- data/lib/polars/version.rb +1 -1
- data/lib/polars.rb +2 -0
- metadata +4 -1
data/ext/polars/src/lib.rs
CHANGED
@@ -28,6 +28,7 @@ use dataframe::RbDataFrame;
|
|
28
28
|
use error::RbPolarsErr;
|
29
29
|
use exceptions::{RbTypeError, RbValueError};
|
30
30
|
use expr::RbExpr;
|
31
|
+
use expr::datatype::RbDataTypeExpr;
|
31
32
|
use expr::rb_exprs_to_exprs;
|
32
33
|
use expr::selector::RbSelector;
|
33
34
|
use functions::string_cache::RbStringCacheHolder;
|
@@ -221,6 +222,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
221
222
|
class.define_method("peak_max", method!(RbExpr::peak_max, 0))?;
|
222
223
|
class.define_method("arg_max", method!(RbExpr::arg_max, 0))?;
|
223
224
|
class.define_method("arg_min", method!(RbExpr::arg_min, 0))?;
|
225
|
+
class.define_method("index_of", method!(RbExpr::index_of, 1))?;
|
224
226
|
class.define_method("search_sorted", method!(RbExpr::search_sorted, 3))?;
|
225
227
|
class.define_method("gather", method!(RbExpr::gather, 1))?;
|
226
228
|
class.define_method("get", method!(RbExpr::get, 1))?;
|
@@ -240,6 +242,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
240
242
|
class.define_method("var", method!(RbExpr::var, 1))?;
|
241
243
|
class.define_method("is_unique", method!(RbExpr::is_unique, 0))?;
|
242
244
|
class.define_method("is_between", method!(RbExpr::is_between, 3))?;
|
245
|
+
class.define_method("is_close", method!(RbExpr::is_close, 4))?;
|
243
246
|
class.define_method("approx_n_unique", method!(RbExpr::approx_n_unique, 0))?;
|
244
247
|
class.define_method("is_first_distinct", method!(RbExpr::is_first_distinct, 0))?;
|
245
248
|
class.define_method("is_last_distinct", method!(RbExpr::is_last_distinct, 0))?;
|
@@ -251,6 +254,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
251
254
|
class.define_method("append", method!(RbExpr::append, 2))?;
|
252
255
|
class.define_method("rechunk", method!(RbExpr::rechunk, 0))?;
|
253
256
|
class.define_method("round", method!(RbExpr::round, 2))?;
|
257
|
+
class.define_method("round_sig_figs", method!(RbExpr::round_sig_figs, 1))?;
|
254
258
|
class.define_method("floor", method!(RbExpr::floor, 0))?;
|
255
259
|
class.define_method("ceil", method!(RbExpr::ceil, 0))?;
|
256
260
|
class.define_method("clip", method!(RbExpr::clip, 2))?;
|
@@ -258,6 +262,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
258
262
|
class.define_method("sin", method!(RbExpr::sin, 0))?;
|
259
263
|
class.define_method("cos", method!(RbExpr::cos, 0))?;
|
260
264
|
class.define_method("tan", method!(RbExpr::tan, 0))?;
|
265
|
+
class.define_method("cot", method!(RbExpr::cot, 0))?;
|
261
266
|
class.define_method("arcsin", method!(RbExpr::arcsin, 0))?;
|
262
267
|
class.define_method("arccos", method!(RbExpr::arccos, 0))?;
|
263
268
|
class.define_method("arctan", method!(RbExpr::arctan, 0))?;
|
@@ -267,15 +272,20 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
267
272
|
class.define_method("arcsinh", method!(RbExpr::arcsinh, 0))?;
|
268
273
|
class.define_method("arccosh", method!(RbExpr::arccosh, 0))?;
|
269
274
|
class.define_method("arctanh", method!(RbExpr::arctanh, 0))?;
|
275
|
+
class.define_method("degrees", method!(RbExpr::degrees, 0))?;
|
276
|
+
class.define_method("radians", method!(RbExpr::radians, 0))?;
|
270
277
|
class.define_method("sign", method!(RbExpr::sign, 0))?;
|
271
278
|
class.define_method("is_duplicated", method!(RbExpr::is_duplicated, 0))?;
|
272
279
|
class.define_method("over", method!(RbExpr::over, 1))?;
|
273
|
-
class.define_method("
|
274
|
-
class.define_method("
|
275
|
-
class.define_method("
|
280
|
+
class.define_method("rolling", method!(RbExpr::rolling, 4))?;
|
281
|
+
class.define_method("and_", method!(RbExpr::and_, 1))?;
|
282
|
+
class.define_method("or_", method!(RbExpr::or_, 1))?;
|
283
|
+
class.define_method("xor_", method!(RbExpr::xor_, 1))?;
|
276
284
|
class.define_method("is_in", method!(RbExpr::is_in, 2))?;
|
277
285
|
class.define_method("repeat_by", method!(RbExpr::repeat_by, 1))?;
|
278
286
|
class.define_method("pow", method!(RbExpr::pow, 1))?;
|
287
|
+
class.define_method("sqrt", method!(RbExpr::sqrt, 0))?;
|
288
|
+
class.define_method("cbrt", method!(RbExpr::cbrt, 0))?;
|
279
289
|
class.define_method("cum_sum", method!(RbExpr::cum_sum, 1))?;
|
280
290
|
class.define_method("cum_max", method!(RbExpr::cum_max, 1))?;
|
281
291
|
class.define_method("cum_min", method!(RbExpr::cum_min, 1))?;
|
@@ -297,6 +307,8 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
297
307
|
class.define_method("str_strip_prefix", method!(RbExpr::str_strip_prefix, 1))?;
|
298
308
|
class.define_method("str_strip_suffix", method!(RbExpr::str_strip_suffix, 1))?;
|
299
309
|
class.define_method("str_slice", method!(RbExpr::str_slice, 2))?;
|
310
|
+
class.define_method("str_head", method!(RbExpr::str_head, 1))?;
|
311
|
+
class.define_method("str_tail", method!(RbExpr::str_tail, 1))?;
|
300
312
|
class.define_method("str_to_uppercase", method!(RbExpr::str_to_uppercase, 0))?;
|
301
313
|
class.define_method("str_to_lowercase", method!(RbExpr::str_to_lowercase, 0))?;
|
302
314
|
// class.define_method("str_to_titlecase", method!(RbExpr::str_to_titlecase, 0))?;
|
@@ -304,17 +316,25 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
304
316
|
class.define_method("str_len_chars", method!(RbExpr::str_len_chars, 0))?;
|
305
317
|
class.define_method("str_replace_n", method!(RbExpr::str_replace_n, 4))?;
|
306
318
|
class.define_method("str_replace_all", method!(RbExpr::str_replace_all, 3))?;
|
319
|
+
class.define_method("str_normalize", method!(RbExpr::str_normalize, 1))?;
|
307
320
|
class.define_method("str_reverse", method!(RbExpr::str_reverse, 0))?;
|
308
321
|
class.define_method("str_zfill", method!(RbExpr::str_zfill, 1))?;
|
309
322
|
class.define_method("str_pad_start", method!(RbExpr::str_pad_start, 2))?;
|
310
323
|
class.define_method("str_pad_end", method!(RbExpr::str_pad_end, 2))?;
|
311
324
|
class.define_method("str_contains", method!(RbExpr::str_contains, 3))?;
|
325
|
+
class.define_method("str_find", method!(RbExpr::str_find, 3))?;
|
312
326
|
class.define_method("str_ends_with", method!(RbExpr::str_ends_with, 1))?;
|
313
327
|
class.define_method("str_starts_with", method!(RbExpr::str_starts_with, 1))?;
|
314
|
-
class.define_method("
|
315
|
-
class.define_method("
|
316
|
-
class.define_method("
|
328
|
+
class.define_method("arr_len", method!(RbExpr::arr_len, 0))?;
|
329
|
+
class.define_method("arr_max", method!(RbExpr::arr_max, 0))?;
|
330
|
+
class.define_method("arr_min", method!(RbExpr::arr_min, 0))?;
|
331
|
+
class.define_method("arr_sum", method!(RbExpr::arr_sum, 0))?;
|
332
|
+
class.define_method("arr_std", method!(RbExpr::arr_std, 1))?;
|
333
|
+
class.define_method("arr_var", method!(RbExpr::arr_var, 1))?;
|
334
|
+
class.define_method("arr_mean", method!(RbExpr::arr_mean, 0))?;
|
335
|
+
class.define_method("arr_median", method!(RbExpr::arr_median, 0))?;
|
317
336
|
class.define_method("arr_unique", method!(RbExpr::arr_unique, 1))?;
|
337
|
+
class.define_method("arr_n_unique", method!(RbExpr::arr_n_unique, 0))?;
|
318
338
|
class.define_method("arr_to_list", method!(RbExpr::arr_to_list, 0))?;
|
319
339
|
class.define_method("arr_all", method!(RbExpr::arr_all, 0))?;
|
320
340
|
class.define_method("arr_any", method!(RbExpr::arr_any, 0))?;
|
@@ -326,6 +346,11 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
326
346
|
class.define_method("arr_join", method!(RbExpr::arr_join, 2))?;
|
327
347
|
class.define_method("arr_contains", method!(RbExpr::arr_contains, 2))?;
|
328
348
|
class.define_method("arr_count_matches", method!(RbExpr::arr_count_matches, 1))?;
|
349
|
+
class.define_method("arr_to_struct", method!(RbExpr::arr_to_struct, 1))?;
|
350
|
+
class.define_method("arr_slice", method!(RbExpr::arr_slice, 3))?;
|
351
|
+
class.define_method("arr_tail", method!(RbExpr::arr_tail, 2))?;
|
352
|
+
class.define_method("arr_shift", method!(RbExpr::arr_shift, 1))?;
|
353
|
+
class.define_method("arr_explode", method!(RbExpr::arr_explode, 0))?;
|
329
354
|
class.define_method("binary_contains", method!(RbExpr::bin_contains, 1))?;
|
330
355
|
class.define_method("binary_ends_with", method!(RbExpr::bin_ends_with, 1))?;
|
331
356
|
class.define_method("binary_starts_with", method!(RbExpr::bin_starts_with, 1))?;
|
@@ -345,6 +370,8 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
345
370
|
"binary_base64_decode",
|
346
371
|
method!(RbExpr::bin_base64_decode, 1),
|
347
372
|
)?;
|
373
|
+
class.define_method("bin_reinterpret", method!(RbExpr::bin_reinterpret, 2))?;
|
374
|
+
class.define_method("bin_size_bytes", method!(RbExpr::bin_size_bytes, 0))?;
|
348
375
|
class.define_method(
|
349
376
|
"str_json_path_match",
|
350
377
|
method!(RbExpr::str_json_path_match, 1),
|
@@ -353,7 +380,6 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
353
380
|
class.define_method("str_extract_all", method!(RbExpr::str_extract_all, 1))?;
|
354
381
|
class.define_method("str_extract_groups", method!(RbExpr::str_extract_groups, 1))?;
|
355
382
|
class.define_method("str_count_matches", method!(RbExpr::str_count_matches, 2))?;
|
356
|
-
class.define_method("strftime", method!(RbExpr::dt_to_string, 1))?;
|
357
383
|
class.define_method("str_split", method!(RbExpr::str_split, 1))?;
|
358
384
|
class.define_method(
|
359
385
|
"str_split_inclusive",
|
@@ -368,10 +394,21 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
368
394
|
class.define_method("str_to_decimal", method!(RbExpr::str_to_decimal, 1))?;
|
369
395
|
class.define_method("str_contains_any", method!(RbExpr::str_contains_any, 2))?;
|
370
396
|
class.define_method("str_replace_many", method!(RbExpr::str_replace_many, 3))?;
|
397
|
+
class.define_method("str_extract_many", method!(RbExpr::str_extract_many, 3))?;
|
398
|
+
class.define_method("str_find_many", method!(RbExpr::str_find_many, 3))?;
|
399
|
+
class.define_method("str_escape_regex", method!(RbExpr::str_escape_regex, 0))?;
|
371
400
|
class.define_method("list_len", method!(RbExpr::list_len, 0))?;
|
372
401
|
class.define_method("list_contains", method!(RbExpr::list_contains, 2))?;
|
373
402
|
class.define_method("list_count_matches", method!(RbExpr::list_count_matches, 1))?;
|
403
|
+
class.define_method(
|
404
|
+
"dt_add_business_days",
|
405
|
+
method!(RbExpr::dt_add_business_days, 4),
|
406
|
+
)?;
|
407
|
+
class.define_method("strftime", method!(RbExpr::dt_to_string, 1))?;
|
408
|
+
class.define_method("dt_millennium", method!(RbExpr::dt_millennium, 0))?;
|
409
|
+
class.define_method("dt_century", method!(RbExpr::dt_century, 0))?;
|
374
410
|
class.define_method("dt_year", method!(RbExpr::dt_year, 0))?;
|
411
|
+
class.define_method("dt_is_business_day", method!(RbExpr::dt_is_business_day, 2))?;
|
375
412
|
class.define_method("dt_is_leap_year", method!(RbExpr::dt_is_leap_year, 0))?;
|
376
413
|
class.define_method("dt_iso_year", method!(RbExpr::dt_iso_year, 0))?;
|
377
414
|
class.define_method("dt_quarter", method!(RbExpr::dt_quarter, 0))?;
|
@@ -425,6 +462,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
425
462
|
class.define_method("dt_base_utc_offset", method!(RbExpr::dt_base_utc_offset, 0))?;
|
426
463
|
class.define_method("dt_dst_offset", method!(RbExpr::dt_dst_offset, 0))?;
|
427
464
|
class.define_method("dt_round", method!(RbExpr::dt_round, 1))?;
|
465
|
+
class.define_method("dt_replace", method!(RbExpr::dt_replace, 8))?;
|
428
466
|
class.define_method("dt_combine", method!(RbExpr::dt_combine, 2))?;
|
429
467
|
class.define_method("map_batches", method!(RbExpr::map_batches, 5))?;
|
430
468
|
class.define_method("dot", method!(RbExpr::dot, 1))?;
|
@@ -452,6 +490,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
452
490
|
method!(RbExpr::rolling_quantile_by, 6),
|
453
491
|
)?;
|
454
492
|
class.define_method("rolling_skew", method!(RbExpr::rolling_skew, 4))?;
|
493
|
+
class.define_method("rolling_kurtosis", method!(RbExpr::rolling_kurtosis, 5))?;
|
455
494
|
class.define_method("lower_bound", method!(RbExpr::lower_bound, 0))?;
|
456
495
|
class.define_method("upper_bound", method!(RbExpr::upper_bound, 0))?;
|
457
496
|
class.define_method("list_max", method!(RbExpr::list_max, 0))?;
|
@@ -464,11 +503,16 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
464
503
|
method!(RbExpr::list_sample_fraction, 4),
|
465
504
|
)?;
|
466
505
|
class.define_method("list_gather", method!(RbExpr::list_gather, 2))?;
|
506
|
+
class.define_method("list_gather_every", method!(RbExpr::list_gather_every, 2))?;
|
467
507
|
class.define_method("list_to_array", method!(RbExpr::list_to_array, 1))?;
|
468
508
|
class.define_method("list_mean", method!(RbExpr::list_mean, 0))?;
|
509
|
+
class.define_method("list_median", method!(RbExpr::list_median, 0))?;
|
510
|
+
class.define_method("list_std", method!(RbExpr::list_std, 1))?;
|
511
|
+
class.define_method("list_var", method!(RbExpr::list_var, 1))?;
|
469
512
|
class.define_method("list_tail", method!(RbExpr::list_tail, 1))?;
|
470
513
|
class.define_method("list_sort", method!(RbExpr::list_sort, 2))?;
|
471
514
|
class.define_method("list_reverse", method!(RbExpr::list_reverse, 0))?;
|
515
|
+
class.define_method("list_n_unique", method!(RbExpr::list_n_unique, 0))?;
|
472
516
|
class.define_method("list_unique", method!(RbExpr::list_unique, 1))?;
|
473
517
|
class.define_method("list_set_operation", method!(RbExpr::list_set_operation, 2))?;
|
474
518
|
class.define_method("list_get", method!(RbExpr::list_get, 2))?;
|
@@ -491,6 +535,11 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
491
535
|
class.define_method("kurtosis", method!(RbExpr::kurtosis, 2))?;
|
492
536
|
class.define_method("str_join", method!(RbExpr::str_join, 2))?;
|
493
537
|
class.define_method("cat_get_categories", method!(RbExpr::cat_get_categories, 0))?;
|
538
|
+
class.define_method("cat_len_bytes", method!(RbExpr::cat_len_bytes, 0))?;
|
539
|
+
class.define_method("cat_len_chars", method!(RbExpr::cat_len_chars, 0))?;
|
540
|
+
class.define_method("cat_starts_with", method!(RbExpr::cat_starts_with, 1))?;
|
541
|
+
class.define_method("cat_ends_with", method!(RbExpr::cat_ends_with, 1))?;
|
542
|
+
class.define_method("cat_slice", method!(RbExpr::cat_slice, 2))?;
|
494
543
|
class.define_method("reshape", method!(RbExpr::reshape, 1))?;
|
495
544
|
class.define_method("cum_count", method!(RbExpr::cum_count, 1))?;
|
496
545
|
class.define_method("to_physical", method!(RbExpr::to_physical, 0))?;
|
@@ -498,6 +547,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
498
547
|
class.define_method("sample_n", method!(RbExpr::sample_n, 4))?;
|
499
548
|
class.define_method("sample_frac", method!(RbExpr::sample_frac, 4))?;
|
500
549
|
class.define_method("ewm_mean", method!(RbExpr::ewm_mean, 4))?;
|
550
|
+
class.define_method("ewm_mean_by", method!(RbExpr::ewm_mean_by, 2))?;
|
501
551
|
class.define_method("ewm_std", method!(RbExpr::ewm_std, 5))?;
|
502
552
|
class.define_method("ewm_var", method!(RbExpr::ewm_var, 5))?;
|
503
553
|
class.define_method("extend_constant", method!(RbExpr::extend_constant, 2))?;
|
@@ -516,16 +566,45 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
516
566
|
method!(RbExpr::struct_rename_fields, 1),
|
517
567
|
)?;
|
518
568
|
class.define_method("struct_json_encode", method!(RbExpr::struct_json_encode, 0))?;
|
569
|
+
class.define_method("struct_with_fields", method!(RbExpr::struct_with_fields, 1))?;
|
519
570
|
class.define_method("log", method!(RbExpr::log, 1))?;
|
571
|
+
class.define_method("log1p", method!(RbExpr::log1p, 0))?;
|
520
572
|
class.define_method("exp", method!(RbExpr::exp, 0))?;
|
521
573
|
class.define_method("entropy", method!(RbExpr::entropy, 2))?;
|
522
574
|
class.define_method("_hash", method!(RbExpr::hash, 4))?;
|
523
575
|
class.define_method("set_sorted_flag", method!(RbExpr::set_sorted_flag, 1))?;
|
524
576
|
class.define_method("replace", method!(RbExpr::replace, 2))?;
|
525
577
|
class.define_method("replace_strict", method!(RbExpr::replace_strict, 4))?;
|
578
|
+
class.define_method("hist", method!(RbExpr::hist, 4))?;
|
526
579
|
class.define_method("into_selector", method!(RbExpr::into_selector, 0))?;
|
527
580
|
class.define_singleton_method("new_selector", function!(RbExpr::new_selector, 1))?;
|
528
581
|
|
582
|
+
// bitwise
|
583
|
+
class.define_method("bitwise_count_ones", method!(RbExpr::bitwise_count_ones, 0))?;
|
584
|
+
class.define_method(
|
585
|
+
"bitwise_count_zeros",
|
586
|
+
method!(RbExpr::bitwise_count_zeros, 0),
|
587
|
+
)?;
|
588
|
+
class.define_method(
|
589
|
+
"bitwise_leading_ones",
|
590
|
+
method!(RbExpr::bitwise_leading_ones, 0),
|
591
|
+
)?;
|
592
|
+
class.define_method(
|
593
|
+
"bitwise_leading_zeros",
|
594
|
+
method!(RbExpr::bitwise_leading_zeros, 0),
|
595
|
+
)?;
|
596
|
+
class.define_method(
|
597
|
+
"bitwise_trailing_ones",
|
598
|
+
method!(RbExpr::bitwise_trailing_ones, 0),
|
599
|
+
)?;
|
600
|
+
class.define_method(
|
601
|
+
"bitwise_trailing_zeros",
|
602
|
+
method!(RbExpr::bitwise_trailing_zeros, 0),
|
603
|
+
)?;
|
604
|
+
class.define_method("bitwise_and", method!(RbExpr::bitwise_and, 0))?;
|
605
|
+
class.define_method("bitwise_or", method!(RbExpr::bitwise_or, 0))?;
|
606
|
+
class.define_method("bitwise_xor", method!(RbExpr::bitwise_xor, 0))?;
|
607
|
+
|
529
608
|
// meta
|
530
609
|
class.define_method("meta_pop", method!(RbExpr::meta_pop, 1))?;
|
531
610
|
class.define_method("meta_eq", method!(RbExpr::meta_eq, 1))?;
|
@@ -541,6 +620,11 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
541
620
|
"meta_is_regex_projection",
|
542
621
|
method!(RbExpr::meta_is_regex_projection, 0),
|
543
622
|
)?;
|
623
|
+
class.define_method(
|
624
|
+
"meta_is_column_selection",
|
625
|
+
method!(RbExpr::meta_is_column_selection, 1),
|
626
|
+
)?;
|
627
|
+
class.define_method("meta_is_literal", method!(RbExpr::meta_is_literal, 1))?;
|
544
628
|
class.define_method("meta_tree_format", method!(RbExpr::meta_tree_format, 1))?;
|
545
629
|
|
546
630
|
// name
|
@@ -550,6 +634,8 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
550
634
|
class.define_method("name_suffix", method!(RbExpr::name_suffix, 1))?;
|
551
635
|
class.define_method("name_to_lowercase", method!(RbExpr::name_to_lowercase, 0))?;
|
552
636
|
class.define_method("name_to_uppercase", method!(RbExpr::name_to_uppercase, 0))?;
|
637
|
+
class.define_method("name_prefix_fields", method!(RbExpr::name_prefix_fields, 1))?;
|
638
|
+
class.define_method("name_suffix_fields", method!(RbExpr::name_suffix_fields, 1))?;
|
553
639
|
|
554
640
|
// maybe add to different class
|
555
641
|
let class = module.define_module("Plr")?;
|
@@ -605,6 +691,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
605
691
|
function!(functions::aggregation::mean_horizontal, 2),
|
606
692
|
)?;
|
607
693
|
class.define_singleton_method("as_struct", function!(functions::lazy::as_struct, 1))?;
|
694
|
+
class.define_singleton_method("field", function!(functions::lazy::field, 1))?;
|
608
695
|
class.define_singleton_method("coalesce", function!(functions::lazy::coalesce, 1))?;
|
609
696
|
class.define_singleton_method("arg_where", function!(functions::lazy::arg_where, 1))?;
|
610
697
|
class.define_singleton_method(
|
@@ -631,6 +718,10 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
631
718
|
)?;
|
632
719
|
class.define_singleton_method("duration", function!(functions::lazy::duration, 9))?;
|
633
720
|
class.define_singleton_method("ipc_schema", function!(functions::io::read_ipc_schema, 1))?;
|
721
|
+
class.define_singleton_method(
|
722
|
+
"read_parquet_metadata",
|
723
|
+
function!(functions::io::read_parquet_metadata, 1),
|
724
|
+
)?;
|
634
725
|
class.define_singleton_method(
|
635
726
|
"parquet_schema",
|
636
727
|
function!(functions::io::read_parquet_schema, 1),
|
@@ -742,6 +833,8 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
742
833
|
)?;
|
743
834
|
class.define_method("sort", method!(RbLazyFrame::sort, 5))?;
|
744
835
|
class.define_method("sort_by_exprs", method!(RbLazyFrame::sort_by_exprs, 5))?;
|
836
|
+
class.define_method("top_k", method!(RbLazyFrame::top_k, 3))?;
|
837
|
+
class.define_method("bottom_k", method!(RbLazyFrame::bottom_k, 3))?;
|
745
838
|
class.define_method("cache", method!(RbLazyFrame::cache, 0))?;
|
746
839
|
class.define_method("collect", method!(RbLazyFrame::collect, 0))?;
|
747
840
|
class.define_method("sink_parquet", method!(RbLazyFrame::sink_parquet, 9))?;
|
@@ -749,6 +842,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
749
842
|
class.define_method("sink_csv", method!(RbLazyFrame::sink_csv, -1))?;
|
750
843
|
class.define_method("sink_json", method!(RbLazyFrame::sink_json, 4))?;
|
751
844
|
class.define_method("filter", method!(RbLazyFrame::filter, 1))?;
|
845
|
+
class.define_method("remove", method!(RbLazyFrame::remove, 1))?;
|
752
846
|
class.define_method("select", method!(RbLazyFrame::select, 1))?;
|
753
847
|
class.define_method("select_seq", method!(RbLazyFrame::select_seq, 1))?;
|
754
848
|
class.define_method("group_by", method!(RbLazyFrame::group_by, 2))?;
|
@@ -760,6 +854,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
760
854
|
class.define_method("with_context", method!(RbLazyFrame::with_context, 1))?;
|
761
855
|
class.define_method("join_asof", method!(RbLazyFrame::join_asof, 14))?;
|
762
856
|
class.define_method("join", method!(RbLazyFrame::join, 11))?;
|
857
|
+
class.define_method("join_where", method!(RbLazyFrame::join_where, 3))?;
|
763
858
|
class.define_method("with_column", method!(RbLazyFrame::with_column, 1))?;
|
764
859
|
class.define_method("with_columns", method!(RbLazyFrame::with_columns, 1))?;
|
765
860
|
class.define_method(
|
@@ -781,6 +876,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
781
876
|
class.define_method("explode", method!(RbLazyFrame::explode, 1))?;
|
782
877
|
class.define_method("null_count", method!(RbLazyFrame::null_count, 0))?;
|
783
878
|
class.define_method("unique", method!(RbLazyFrame::unique, 3))?;
|
879
|
+
class.define_method("drop_nans", method!(RbLazyFrame::drop_nans, 1))?;
|
784
880
|
class.define_method("drop_nulls", method!(RbLazyFrame::drop_nulls, 1))?;
|
785
881
|
class.define_method("slice", method!(RbLazyFrame::slice, 2))?;
|
786
882
|
class.define_method("tail", method!(RbLazyFrame::tail, 1))?;
|
@@ -855,7 +951,8 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
855
951
|
class.define_method("estimated_size", method!(RbSeries::estimated_size, 0))?;
|
856
952
|
class.define_method("get_fmt", method!(RbSeries::get_fmt, 2))?;
|
857
953
|
class.define_method("rechunk", method!(RbSeries::rechunk, 1))?;
|
858
|
-
class.define_method("
|
954
|
+
class.define_method("get_index", method!(RbSeries::get_index, 1))?;
|
955
|
+
class.define_method("get_index_signed", method!(RbSeries::get_index_signed, 1))?;
|
859
956
|
class.define_method("bitand", method!(RbSeries::bitand, 1))?;
|
860
957
|
class.define_method("bitor", method!(RbSeries::bitor, 1))?;
|
861
958
|
class.define_method("bitxor", method!(RbSeries::bitxor, 1))?;
|
@@ -869,6 +966,12 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
869
966
|
class.define_method("max", method!(RbSeries::max, 0))?;
|
870
967
|
class.define_method("min", method!(RbSeries::min, 0))?;
|
871
968
|
class.define_method("sum", method!(RbSeries::sum, 0))?;
|
969
|
+
class.define_method("first", method!(RbSeries::first, 0))?;
|
970
|
+
class.define_method("last", method!(RbSeries::last, 0))?;
|
971
|
+
class.define_method("approx_n_unique", method!(RbSeries::approx_n_unique, 0))?;
|
972
|
+
class.define_method("bitwise_and", method!(RbSeries::bitwise_and, 0))?;
|
973
|
+
class.define_method("bitwise_or", method!(RbSeries::bitwise_or, 0))?;
|
974
|
+
class.define_method("bitwise_xor", method!(RbSeries::bitwise_xor, 0))?;
|
872
975
|
class.define_method("n_chunks", method!(RbSeries::n_chunks, 0))?;
|
873
976
|
class.define_method("append", method!(RbSeries::append, 1))?;
|
874
977
|
class.define_method("extend", method!(RbSeries::extend, 1))?;
|
@@ -898,7 +1001,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
898
1001
|
class.define_method("gt_eq", method!(RbSeries::gt_eq, 1))?;
|
899
1002
|
class.define_method("lt", method!(RbSeries::lt, 1))?;
|
900
1003
|
class.define_method("lt_eq", method!(RbSeries::lt_eq, 1))?;
|
901
|
-
class.define_method("
|
1004
|
+
class.define_method("not_", method!(RbSeries::not_, 0))?;
|
902
1005
|
class.define_method("to_s", method!(RbSeries::to_s, 0))?;
|
903
1006
|
class.define_method("len", method!(RbSeries::len, 0))?;
|
904
1007
|
class.define_method("to_a", method!(RbSeries::to_a, 0))?;
|
@@ -915,6 +1018,9 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
915
1018
|
class.define_method("skew", method!(RbSeries::skew, 1))?;
|
916
1019
|
class.define_method("kurtosis", method!(RbSeries::kurtosis, 2))?;
|
917
1020
|
class.define_method("cast", method!(RbSeries::cast, 2))?;
|
1021
|
+
class.define_method("get_chunks", method!(RbSeries::get_chunks, 0))?;
|
1022
|
+
class.define_method("is_sorted", method!(RbSeries::is_sorted, 2))?;
|
1023
|
+
class.define_method("clear", method!(RbSeries::clear, 0))?;
|
918
1024
|
class.define_method("time_unit", method!(RbSeries::time_unit, 0))?;
|
919
1025
|
class.define_method("scatter", method!(RbSeries::scatter, 2))?;
|
920
1026
|
|
@@ -1152,7 +1258,10 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
1152
1258
|
)?;
|
1153
1259
|
|
1154
1260
|
// data type expr
|
1155
|
-
let
|
1261
|
+
let class = module.define_class("RbDataTypeExpr", ruby.class_object())?;
|
1262
|
+
class.define_singleton_method("from_dtype", function!(RbDataTypeExpr::from_dtype, 1))?;
|
1263
|
+
class.define_singleton_method("of_expr", function!(RbDataTypeExpr::of_expr, 1))?;
|
1264
|
+
class.define_method("collect_dtype", method!(RbDataTypeExpr::collect_dtype, 1))?;
|
1156
1265
|
|
1157
1266
|
// selector
|
1158
1267
|
let class = module.define_class("RbSelector", ruby.class_object())?;
|
@@ -6,14 +6,14 @@ use polars_core::series::SeriesIter;
|
|
6
6
|
use super::*;
|
7
7
|
use crate::{RbDataFrame, RbPolarsErr, RbSeries, Wrap};
|
8
8
|
|
9
|
-
fn get_iters(df: &DataFrame) -> Vec<SeriesIter
|
9
|
+
fn get_iters(df: &DataFrame) -> Vec<SeriesIter<'_>> {
|
10
10
|
df.get_columns()
|
11
11
|
.iter()
|
12
12
|
.map(|s| s.as_materialized_series().iter())
|
13
13
|
.collect()
|
14
14
|
}
|
15
15
|
|
16
|
-
fn get_iters_skip(df: &DataFrame, skip: usize) -> Vec<std::iter::Skip<SeriesIter
|
16
|
+
fn get_iters_skip(df: &DataFrame, skip: usize) -> Vec<std::iter::Skip<SeriesIter<'_>>> {
|
17
17
|
df.get_columns()
|
18
18
|
.iter()
|
19
19
|
.map(|s| s.as_materialized_series().iter().skip(skip))
|
@@ -999,7 +999,7 @@ impl<'a> ApplyLambda<'a> for StringChunked {
|
|
999
999
|
}
|
1000
1000
|
}
|
1001
1001
|
|
1002
|
-
fn iter_struct(ca: &StructChunked) -> impl Iterator<Item = AnyValue
|
1002
|
+
fn iter_struct(ca: &StructChunked) -> impl Iterator<Item = AnyValue<'_>> {
|
1003
1003
|
(0..ca.len()).map(|i| unsafe { ca.get_any_value_unchecked(i) })
|
1004
1004
|
}
|
1005
1005
|
|
@@ -3,6 +3,10 @@ use crate::prelude::*;
|
|
3
3
|
use crate::{RbResult, RbSeries};
|
4
4
|
use magnus::{IntoValue, Value};
|
5
5
|
|
6
|
+
fn scalar_to_rb(scalar: RbResult<Scalar>) -> RbResult<Value> {
|
7
|
+
Ok(Wrap(scalar?.as_any_value()).into_value())
|
8
|
+
}
|
9
|
+
|
6
10
|
impl RbSeries {
|
7
11
|
pub fn any(&self, ignore_nulls: bool) -> RbResult<Option<bool>> {
|
8
12
|
let binding = self.series.borrow();
|
@@ -118,4 +122,44 @@ impl RbSeries {
|
|
118
122
|
)
|
119
123
|
.into_value())
|
120
124
|
}
|
125
|
+
|
126
|
+
pub fn first(&self) -> RbResult<Value> {
|
127
|
+
scalar_to_rb(Ok(self.series.borrow().first()))
|
128
|
+
}
|
129
|
+
|
130
|
+
pub fn last(&self) -> RbResult<Value> {
|
131
|
+
scalar_to_rb(Ok(self.series.borrow().last()))
|
132
|
+
}
|
133
|
+
|
134
|
+
pub fn approx_n_unique(&self) -> RbResult<IdxSize> {
|
135
|
+
Ok(self
|
136
|
+
.series
|
137
|
+
.borrow()
|
138
|
+
.approx_n_unique()
|
139
|
+
.map_err(RbPolarsErr::from)?)
|
140
|
+
}
|
141
|
+
|
142
|
+
pub fn bitwise_and(&self) -> RbResult<Value> {
|
143
|
+
scalar_to_rb(Ok(self
|
144
|
+
.series
|
145
|
+
.borrow()
|
146
|
+
.and_reduce()
|
147
|
+
.map_err(RbPolarsErr::from)?))
|
148
|
+
}
|
149
|
+
|
150
|
+
pub fn bitwise_or(&self) -> RbResult<Value> {
|
151
|
+
scalar_to_rb(Ok(self
|
152
|
+
.series
|
153
|
+
.borrow()
|
154
|
+
.or_reduce()
|
155
|
+
.map_err(RbPolarsErr::from)?))
|
156
|
+
}
|
157
|
+
|
158
|
+
pub fn bitwise_xor(&self) -> RbResult<Value> {
|
159
|
+
scalar_to_rb(Ok(self
|
160
|
+
.series
|
161
|
+
.borrow()
|
162
|
+
.xor_reduce()
|
163
|
+
.map_err(RbPolarsErr::from)?))
|
164
|
+
}
|
121
165
|
}
|
@@ -1,8 +1,11 @@
|
|
1
|
-
use magnus::{Error, IntoValue, Value, exception};
|
1
|
+
use magnus::{Error, IntoValue, RArray, Value, exception, value::ReprValue};
|
2
2
|
use polars::prelude::*;
|
3
3
|
use polars::series::IsSorted;
|
4
|
+
use polars_core::utils::flatten::flatten_series;
|
4
5
|
|
5
6
|
use crate::conversion::*;
|
7
|
+
use crate::exceptions::RbIndexError;
|
8
|
+
use crate::rb_modules;
|
6
9
|
use crate::{RbDataFrame, RbPolarsErr, RbResult, RbSeries};
|
7
10
|
|
8
11
|
impl RbSeries {
|
@@ -84,8 +87,39 @@ impl RbSeries {
|
|
84
87
|
}
|
85
88
|
}
|
86
89
|
|
87
|
-
pub fn
|
88
|
-
|
90
|
+
pub fn get_index(&self, index: usize) -> RbResult<Value> {
|
91
|
+
let binding = self.series.borrow();
|
92
|
+
let av = match binding.get(index) {
|
93
|
+
Ok(v) => v,
|
94
|
+
Err(PolarsError::OutOfBounds(err)) => {
|
95
|
+
return Err(RbIndexError::new_err(err.to_string()));
|
96
|
+
}
|
97
|
+
Err(e) => return Err(RbPolarsErr::from(e).into()),
|
98
|
+
};
|
99
|
+
|
100
|
+
match av {
|
101
|
+
AnyValue::List(s) | AnyValue::Array(s, _) => {
|
102
|
+
let rbseries = RbSeries::new(s);
|
103
|
+
rb_modules::utils().funcall("wrap_s", (rbseries,))
|
104
|
+
}
|
105
|
+
_ => Ok(Wrap(av).into_value()),
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
pub fn get_index_signed(&self, index: isize) -> RbResult<Value> {
|
110
|
+
let index = if index < 0 {
|
111
|
+
match self.len().checked_sub(index.unsigned_abs()) {
|
112
|
+
Some(v) => v,
|
113
|
+
None => {
|
114
|
+
return Err(RbIndexError::new_err(
|
115
|
+
polars_err!(oob = index, self.len()).to_string(),
|
116
|
+
));
|
117
|
+
}
|
118
|
+
}
|
119
|
+
} else {
|
120
|
+
usize::try_from(index).unwrap()
|
121
|
+
};
|
122
|
+
self.get_index(index)
|
89
123
|
}
|
90
124
|
|
91
125
|
pub fn bitand(&self, other: &RbSeries) -> RbResult<Self> {
|
@@ -279,7 +313,7 @@ impl RbSeries {
|
|
279
313
|
}
|
280
314
|
}
|
281
315
|
|
282
|
-
pub fn
|
316
|
+
pub fn not_(&self) -> RbResult<Self> {
|
283
317
|
let binding = self.series.borrow();
|
284
318
|
let bool = binding.bool().map_err(RbPolarsErr::from)?;
|
285
319
|
Ok((!bool).into_series().into())
|
@@ -370,6 +404,32 @@ impl RbSeries {
|
|
370
404
|
Ok(out.into())
|
371
405
|
}
|
372
406
|
|
407
|
+
pub fn get_chunks(&self) -> RbResult<RArray> {
|
408
|
+
flatten_series(&self.series.borrow())
|
409
|
+
.into_iter()
|
410
|
+
.map(|s| rb_modules::utils().funcall::<_, _, Value>("wrap_s", (Self::new(s),)))
|
411
|
+
.collect()
|
412
|
+
}
|
413
|
+
|
414
|
+
pub fn is_sorted(&self, descending: bool, nulls_last: bool) -> RbResult<bool> {
|
415
|
+
let options = SortOptions {
|
416
|
+
descending,
|
417
|
+
nulls_last,
|
418
|
+
multithreaded: true,
|
419
|
+
maintain_order: false,
|
420
|
+
limit: None,
|
421
|
+
};
|
422
|
+
Ok(self
|
423
|
+
.series
|
424
|
+
.borrow()
|
425
|
+
.is_sorted(options)
|
426
|
+
.map_err(RbPolarsErr::from)?)
|
427
|
+
}
|
428
|
+
|
429
|
+
pub fn clear(&self) -> Self {
|
430
|
+
self.series.borrow().clear().into()
|
431
|
+
}
|
432
|
+
|
373
433
|
pub fn time_unit(&self) -> Option<String> {
|
374
434
|
if let DataType::Datetime(tu, _) | DataType::Duration(tu) = self.series.borrow().dtype() {
|
375
435
|
Some(
|