polars-df 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +3 -0
- data/CHANGELOG.md +9 -0
- data/Cargo.lock +74 -3
- data/Cargo.toml +3 -0
- data/README.md +1 -1
- data/ext/polars/Cargo.toml +18 -1
- data/ext/polars/src/conversion.rs +115 -2
- data/ext/polars/src/dataframe.rs +228 -11
- data/ext/polars/src/error.rs +4 -0
- data/ext/polars/src/lazy/dataframe.rs +5 -5
- data/ext/polars/src/lazy/dsl.rs +157 -2
- data/ext/polars/src/lib.rs +185 -10
- data/ext/polars/src/list_construction.rs +100 -0
- data/ext/polars/src/series.rs +217 -29
- data/ext/polars/src/set.rs +91 -0
- data/ext/polars/src/utils.rs +19 -0
- data/lib/polars/batched_csv_reader.rb +1 -0
- data/lib/polars/cat_expr.rb +39 -0
- data/lib/polars/cat_name_space.rb +54 -0
- data/lib/polars/data_frame.rb +2384 -140
- data/lib/polars/date_time_expr.rb +1282 -7
- data/lib/polars/date_time_name_space.rb +1484 -0
- data/lib/polars/exceptions.rb +20 -0
- data/lib/polars/expr.rb +4374 -53
- data/lib/polars/expr_dispatch.rb +22 -0
- data/lib/polars/functions.rb +219 -0
- data/lib/polars/group_by.rb +518 -0
- data/lib/polars/io.rb +421 -2
- data/lib/polars/lazy_frame.rb +1267 -69
- data/lib/polars/lazy_functions.rb +412 -24
- data/lib/polars/lazy_group_by.rb +80 -0
- data/lib/polars/list_expr.rb +507 -5
- data/lib/polars/list_name_space.rb +346 -0
- data/lib/polars/meta_expr.rb +21 -0
- data/lib/polars/series.rb +2256 -242
- data/lib/polars/slice.rb +104 -0
- data/lib/polars/string_expr.rb +847 -10
- data/lib/polars/string_name_space.rb +690 -0
- data/lib/polars/struct_expr.rb +73 -0
- data/lib/polars/struct_name_space.rb +64 -0
- data/lib/polars/utils.rb +71 -3
- data/lib/polars/version.rb +2 -1
- data/lib/polars/when.rb +1 -0
- data/lib/polars/when_then.rb +1 -0
- data/lib/polars.rb +12 -10
- metadata +15 -2
data/ext/polars/src/lib.rs
CHANGED
@@ -4,7 +4,10 @@ mod dataframe;
|
|
4
4
|
mod error;
|
5
5
|
mod file;
|
6
6
|
mod lazy;
|
7
|
+
mod list_construction;
|
7
8
|
mod series;
|
9
|
+
mod set;
|
10
|
+
mod utils;
|
8
11
|
|
9
12
|
use batched_csv::RbBatchedCsv;
|
10
13
|
use conversion::*;
|
@@ -13,16 +16,32 @@ use error::{RbPolarsErr, RbValueError};
|
|
13
16
|
use file::get_file_like;
|
14
17
|
use lazy::dataframe::{RbLazyFrame, RbLazyGroupBy};
|
15
18
|
use lazy::dsl::{RbExpr, RbWhen, RbWhenThen};
|
19
|
+
use lazy::utils::rb_exprs_to_exprs;
|
16
20
|
use magnus::{
|
17
21
|
define_module, function, memoize, method, prelude::*, Error, RArray, RClass, RHash, RModule,
|
18
22
|
Value,
|
19
23
|
};
|
20
|
-
use polars::datatypes::DataType;
|
24
|
+
use polars::datatypes::{DataType, TimeUnit};
|
21
25
|
use polars::error::PolarsResult;
|
22
26
|
use polars::frame::DataFrame;
|
23
27
|
use polars::functions::{diag_concat_df, hor_concat_df};
|
28
|
+
use polars::prelude::{ClosedWindow, Duration, IntoSeries, TimeZone};
|
24
29
|
use series::RbSeries;
|
25
30
|
|
31
|
+
#[cfg(target_os = "linux")]
|
32
|
+
use jemallocator::Jemalloc;
|
33
|
+
|
34
|
+
#[cfg(not(target_os = "linux"))]
|
35
|
+
use mimalloc::MiMalloc;
|
36
|
+
|
37
|
+
#[global_allocator]
|
38
|
+
#[cfg(target_os = "linux")]
|
39
|
+
static GLOBAL: Jemalloc = Jemalloc;
|
40
|
+
|
41
|
+
#[global_allocator]
|
42
|
+
#[cfg(not(target_os = "linux"))]
|
43
|
+
static GLOBAL: MiMalloc = MiMalloc;
|
44
|
+
|
26
45
|
type RbResult<T> = Result<T, Error>;
|
27
46
|
|
28
47
|
fn module() -> RModule {
|
@@ -42,6 +61,9 @@ fn init() -> RbResult<()> {
|
|
42
61
|
module.define_singleton_method("_concat_series", function!(concat_series, 1))?;
|
43
62
|
module.define_singleton_method("_ipc_schema", function!(ipc_schema, 1))?;
|
44
63
|
module.define_singleton_method("_parquet_schema", function!(parquet_schema, 1))?;
|
64
|
+
module.define_singleton_method("_rb_date_range", function!(rb_date_range, 7))?;
|
65
|
+
module.define_singleton_method("_as_struct", function!(as_struct, 1))?;
|
66
|
+
module.define_singleton_method("_arg_where", function!(arg_where, 1))?;
|
45
67
|
|
46
68
|
let class = module.define_class("RbBatchedCsv", Default::default())?;
|
47
69
|
class.define_singleton_method("new", function!(RbBatchedCsv::new, -1))?;
|
@@ -50,7 +72,7 @@ fn init() -> RbResult<()> {
|
|
50
72
|
let class = module.define_class("RbDataFrame", Default::default())?;
|
51
73
|
class.define_singleton_method("new", function!(RbDataFrame::init, 1))?;
|
52
74
|
class.define_singleton_method("read_csv", function!(RbDataFrame::read_csv, -1))?;
|
53
|
-
class.define_singleton_method("read_parquet", function!(RbDataFrame::read_parquet,
|
75
|
+
class.define_singleton_method("read_parquet", function!(RbDataFrame::read_parquet, 7))?;
|
54
76
|
class.define_singleton_method("read_ipc", function!(RbDataFrame::read_ipc, 6))?;
|
55
77
|
class.define_singleton_method("read_hash", function!(RbDataFrame::read_hash, 1))?;
|
56
78
|
class.define_singleton_method("read_json", function!(RbDataFrame::read_json, 1))?;
|
@@ -60,7 +82,21 @@ fn init() -> RbResult<()> {
|
|
60
82
|
class.define_method("write_ndjson", method!(RbDataFrame::write_ndjson, 1))?;
|
61
83
|
class.define_method("write_csv", method!(RbDataFrame::write_csv, 10))?;
|
62
84
|
class.define_method("write_ipc", method!(RbDataFrame::write_ipc, 2))?;
|
85
|
+
class.define_method("row_tuple", method!(RbDataFrame::row_tuple, 1))?;
|
86
|
+
class.define_method("row_tuples", method!(RbDataFrame::row_tuples, 0))?;
|
63
87
|
class.define_method("write_parquet", method!(RbDataFrame::write_parquet, 5))?;
|
88
|
+
class.define_method("add", method!(RbDataFrame::add, 1))?;
|
89
|
+
class.define_method("sub", method!(RbDataFrame::sub, 1))?;
|
90
|
+
class.define_method("div", method!(RbDataFrame::div, 1))?;
|
91
|
+
class.define_method("mul", method!(RbDataFrame::mul, 1))?;
|
92
|
+
class.define_method("rem", method!(RbDataFrame::rem, 1))?;
|
93
|
+
class.define_method("add_df", method!(RbDataFrame::add_df, 1))?;
|
94
|
+
class.define_method("sub_df", method!(RbDataFrame::sub_df, 1))?;
|
95
|
+
class.define_method("div_df", method!(RbDataFrame::div_df, 1))?;
|
96
|
+
class.define_method("mul_df", method!(RbDataFrame::mul_df, 1))?;
|
97
|
+
class.define_method("rem_df", method!(RbDataFrame::rem_df, 1))?;
|
98
|
+
class.define_method("sample_n", method!(RbDataFrame::sample_n, 4))?;
|
99
|
+
class.define_method("sample_frac", method!(RbDataFrame::sample_frac, 4))?;
|
64
100
|
class.define_method("rechunk", method!(RbDataFrame::rechunk, 0))?;
|
65
101
|
class.define_method("to_s", method!(RbDataFrame::to_s, 0))?;
|
66
102
|
class.define_method("get_columns", method!(RbDataFrame::get_columns, 0))?;
|
@@ -74,7 +110,19 @@ fn init() -> RbResult<()> {
|
|
74
110
|
class.define_method("shape", method!(RbDataFrame::shape, 0))?;
|
75
111
|
class.define_method("height", method!(RbDataFrame::height, 0))?;
|
76
112
|
class.define_method("width", method!(RbDataFrame::width, 0))?;
|
113
|
+
class.define_method("hstack_mut", method!(RbDataFrame::hstack_mut, 1))?;
|
114
|
+
class.define_method("hstack", method!(RbDataFrame::hstack, 1))?;
|
115
|
+
class.define_method("extend", method!(RbDataFrame::extend, 1))?;
|
116
|
+
class.define_method("vstack_mut", method!(RbDataFrame::vstack_mut, 1))?;
|
117
|
+
class.define_method("vstack", method!(RbDataFrame::vstack, 1))?;
|
118
|
+
class.define_method("drop_in_place", method!(RbDataFrame::drop_in_place, 1))?;
|
119
|
+
class.define_method("drop_nulls", method!(RbDataFrame::drop_nulls, 1))?;
|
120
|
+
class.define_method("drop", method!(RbDataFrame::drop, 1))?;
|
77
121
|
class.define_method("select_at_idx", method!(RbDataFrame::select_at_idx, 1))?;
|
122
|
+
class.define_method(
|
123
|
+
"find_idx_by_name",
|
124
|
+
method!(RbDataFrame::find_idx_by_name, 1),
|
125
|
+
)?;
|
78
126
|
class.define_method("column", method!(RbDataFrame::column, 1))?;
|
79
127
|
class.define_method("select", method!(RbDataFrame::select, 1))?;
|
80
128
|
class.define_method("take", method!(RbDataFrame::take, 1))?;
|
@@ -116,6 +164,7 @@ fn init() -> RbResult<()> {
|
|
116
164
|
class.define_method("shrink_to_fit", method!(RbDataFrame::shrink_to_fit, 0))?;
|
117
165
|
class.define_method("transpose", method!(RbDataFrame::transpose, 2))?;
|
118
166
|
class.define_method("upsample", method!(RbDataFrame::upsample, 5))?;
|
167
|
+
class.define_method("to_struct", method!(RbDataFrame::to_struct, 1))?;
|
119
168
|
class.define_method("unnest", method!(RbDataFrame::unnest, 1))?;
|
120
169
|
|
121
170
|
let class = module.define_class("RbExpr", Default::default())?;
|
@@ -247,6 +296,14 @@ fn init() -> RbResult<()> {
|
|
247
296
|
class.define_method("str_contains", method!(RbExpr::str_contains, 2))?;
|
248
297
|
class.define_method("str_ends_with", method!(RbExpr::str_ends_with, 1))?;
|
249
298
|
class.define_method("str_starts_with", method!(RbExpr::str_starts_with, 1))?;
|
299
|
+
class.define_method("str_hex_encode", method!(RbExpr::str_hex_encode, 0))?;
|
300
|
+
class.define_method("str_hex_decode", method!(RbExpr::str_hex_decode, 1))?;
|
301
|
+
class.define_method("str_base64_encode", method!(RbExpr::str_base64_encode, 0))?;
|
302
|
+
class.define_method("str_base64_decode", method!(RbExpr::str_base64_decode, 1))?;
|
303
|
+
class.define_method(
|
304
|
+
"str_json_path_match",
|
305
|
+
method!(RbExpr::str_json_path_match, 1),
|
306
|
+
)?;
|
250
307
|
class.define_method("str_extract", method!(RbExpr::str_extract, 2))?;
|
251
308
|
class.define_method("str_extract_all", method!(RbExpr::str_extract_all, 1))?;
|
252
309
|
class.define_method("count_match", method!(RbExpr::count_match, 1))?;
|
@@ -304,6 +361,8 @@ fn init() -> RbResult<()> {
|
|
304
361
|
class.define_method("dt_tz_localize", method!(RbExpr::dt_tz_localize, 1))?;
|
305
362
|
class.define_method("dt_truncate", method!(RbExpr::dt_truncate, 2))?;
|
306
363
|
class.define_method("dt_round", method!(RbExpr::dt_round, 2))?;
|
364
|
+
class.define_method("dot", method!(RbExpr::dot, 1))?;
|
365
|
+
class.define_method("reinterpret", method!(RbExpr::reinterpret, 1))?;
|
307
366
|
class.define_method("mode", method!(RbExpr::mode, 0))?;
|
308
367
|
class.define_method("keep_name", method!(RbExpr::keep_name, 0))?;
|
309
368
|
class.define_method("prefix", method!(RbExpr::prefix, 1))?;
|
@@ -337,6 +396,7 @@ fn init() -> RbResult<()> {
|
|
337
396
|
class.define_method("lst_slice", method!(RbExpr::lst_slice, 2))?;
|
338
397
|
class.define_method("lst_eval", method!(RbExpr::lst_eval, 2))?;
|
339
398
|
class.define_method("cumulative_eval", method!(RbExpr::cumulative_eval, 3))?;
|
399
|
+
class.define_method("lst_to_struct", method!(RbExpr::lst_to_struct, 2))?;
|
340
400
|
class.define_method("rank", method!(RbExpr::rank, 2))?;
|
341
401
|
class.define_method("diff", method!(RbExpr::diff, 2))?;
|
342
402
|
class.define_method("pct_change", method!(RbExpr::pct_change, 1))?;
|
@@ -353,6 +413,7 @@ fn init() -> RbResult<()> {
|
|
353
413
|
class.define_method("ewm_mean", method!(RbExpr::ewm_mean, 3))?;
|
354
414
|
class.define_method("ewm_std", method!(RbExpr::ewm_std, 4))?;
|
355
415
|
class.define_method("ewm_var", method!(RbExpr::ewm_var, 4))?;
|
416
|
+
class.define_method("extend_constant", method!(RbExpr::extend_constant, 2))?;
|
356
417
|
class.define_method("any", method!(RbExpr::any, 0))?;
|
357
418
|
class.define_method("all", method!(RbExpr::all, 0))?;
|
358
419
|
class.define_method(
|
@@ -369,6 +430,7 @@ fn init() -> RbResult<()> {
|
|
369
430
|
)?;
|
370
431
|
class.define_method("log", method!(RbExpr::log, 1))?;
|
371
432
|
class.define_method("exp", method!(RbExpr::exp, 0))?;
|
433
|
+
class.define_method("entropy", method!(RbExpr::entropy, 2))?;
|
372
434
|
|
373
435
|
// meta
|
374
436
|
class.define_method("meta_pop", method!(RbExpr::meta_pop, 0))?;
|
@@ -386,6 +448,13 @@ fn init() -> RbResult<()> {
|
|
386
448
|
class.define_singleton_method("fold", function!(crate::lazy::dsl::fold, 3))?;
|
387
449
|
class.define_singleton_method("lit", function!(crate::lazy::dsl::lit, 1))?;
|
388
450
|
class.define_singleton_method("arange", function!(crate::lazy::dsl::arange, 3))?;
|
451
|
+
class.define_singleton_method("repeat", function!(crate::lazy::dsl::repeat, 2))?;
|
452
|
+
class.define_singleton_method("pearson_corr", function!(crate::lazy::dsl::pearson_corr, 3))?;
|
453
|
+
class.define_singleton_method(
|
454
|
+
"spearman_rank_corr",
|
455
|
+
function!(crate::lazy::dsl::spearman_rank_corr, 4),
|
456
|
+
)?;
|
457
|
+
class.define_singleton_method("cov", function!(crate::lazy::dsl::cov, 2))?;
|
389
458
|
class.define_singleton_method("when", function!(crate::lazy::dsl::when, 1))?;
|
390
459
|
class.define_singleton_method("concat_str", function!(crate::lazy::dsl::concat_str, 2))?;
|
391
460
|
class.define_singleton_method("concat_lst", function!(crate::lazy::dsl::concat_lst, 1))?;
|
@@ -469,6 +538,10 @@ fn init() -> RbResult<()> {
|
|
469
538
|
class.define_singleton_method("new_opt_f32", function!(RbSeries::new_opt_f32, 3))?;
|
470
539
|
class.define_singleton_method("new_opt_f64", function!(RbSeries::new_opt_f64, 3))?;
|
471
540
|
class.define_singleton_method("new_str", function!(RbSeries::new_str, 3))?;
|
541
|
+
class.define_singleton_method("new_object", function!(RbSeries::new_object, 3))?;
|
542
|
+
class.define_singleton_method("new_list", function!(RbSeries::new_list, 3))?;
|
543
|
+
class.define_singleton_method("new_opt_date", function!(RbSeries::new_opt_date, 3))?;
|
544
|
+
class.define_singleton_method("new_opt_datetime", function!(RbSeries::new_opt_datetime, 3))?;
|
472
545
|
class.define_method("is_sorted_flag", method!(RbSeries::is_sorted_flag, 0))?;
|
473
546
|
class.define_method(
|
474
547
|
"is_sorted_reverse_flag",
|
@@ -536,14 +609,85 @@ fn init() -> RbResult<()> {
|
|
536
609
|
class.define_method("kurtosis", method!(RbSeries::kurtosis, 2))?;
|
537
610
|
class.define_method("cast", method!(RbSeries::cast, 2))?;
|
538
611
|
class.define_method("time_unit", method!(RbSeries::time_unit, 0))?;
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
class.define_method("
|
543
|
-
class.define_method("
|
544
|
-
class.define_method("
|
545
|
-
class.define_method("
|
546
|
-
class.define_method("
|
612
|
+
class.define_method("set_at_idx", method!(RbSeries::set_at_idx, 2))?;
|
613
|
+
|
614
|
+
// eq
|
615
|
+
class.define_method("eq_u8", method!(RbSeries::eq_u8, 1))?;
|
616
|
+
class.define_method("eq_u16", method!(RbSeries::eq_u16, 1))?;
|
617
|
+
class.define_method("eq_u32", method!(RbSeries::eq_u32, 1))?;
|
618
|
+
class.define_method("eq_u64", method!(RbSeries::eq_u64, 1))?;
|
619
|
+
class.define_method("eq_i8", method!(RbSeries::eq_i8, 1))?;
|
620
|
+
class.define_method("eq_i16", method!(RbSeries::eq_i16, 1))?;
|
621
|
+
class.define_method("eq_i32", method!(RbSeries::eq_i32, 1))?;
|
622
|
+
class.define_method("eq_i64", method!(RbSeries::eq_i64, 1))?;
|
623
|
+
class.define_method("eq_f32", method!(RbSeries::eq_f32, 1))?;
|
624
|
+
class.define_method("eq_f64", method!(RbSeries::eq_f64, 1))?;
|
625
|
+
// class.define_method("eq_str", method!(RbSeries::eq_str, 1))?;
|
626
|
+
|
627
|
+
// neq
|
628
|
+
class.define_method("neq_u8", method!(RbSeries::neq_u8, 1))?;
|
629
|
+
class.define_method("neq_u16", method!(RbSeries::neq_u16, 1))?;
|
630
|
+
class.define_method("neq_u32", method!(RbSeries::neq_u32, 1))?;
|
631
|
+
class.define_method("neq_u64", method!(RbSeries::neq_u64, 1))?;
|
632
|
+
class.define_method("neq_i8", method!(RbSeries::neq_i8, 1))?;
|
633
|
+
class.define_method("neq_i16", method!(RbSeries::neq_i16, 1))?;
|
634
|
+
class.define_method("neq_i32", method!(RbSeries::neq_i32, 1))?;
|
635
|
+
class.define_method("neq_i64", method!(RbSeries::neq_i64, 1))?;
|
636
|
+
class.define_method("neq_f32", method!(RbSeries::neq_f32, 1))?;
|
637
|
+
class.define_method("neq_f64", method!(RbSeries::neq_f64, 1))?;
|
638
|
+
// class.define_method("neq_str", method!(RbSeries::neq_str, 1))?;
|
639
|
+
|
640
|
+
// gt
|
641
|
+
class.define_method("gt_u8", method!(RbSeries::gt_u8, 1))?;
|
642
|
+
class.define_method("gt_u16", method!(RbSeries::gt_u16, 1))?;
|
643
|
+
class.define_method("gt_u32", method!(RbSeries::gt_u32, 1))?;
|
644
|
+
class.define_method("gt_u64", method!(RbSeries::gt_u64, 1))?;
|
645
|
+
class.define_method("gt_i8", method!(RbSeries::gt_i8, 1))?;
|
646
|
+
class.define_method("gt_i16", method!(RbSeries::gt_i16, 1))?;
|
647
|
+
class.define_method("gt_i32", method!(RbSeries::gt_i32, 1))?;
|
648
|
+
class.define_method("gt_i64", method!(RbSeries::gt_i64, 1))?;
|
649
|
+
class.define_method("gt_f32", method!(RbSeries::gt_f32, 1))?;
|
650
|
+
class.define_method("gt_f64", method!(RbSeries::gt_f64, 1))?;
|
651
|
+
// class.define_method("gt_str", method!(RbSeries::gt_str, 1))?;
|
652
|
+
|
653
|
+
// gt_eq
|
654
|
+
class.define_method("gt_eq_u8", method!(RbSeries::gt_eq_u8, 1))?;
|
655
|
+
class.define_method("gt_eq_u16", method!(RbSeries::gt_eq_u16, 1))?;
|
656
|
+
class.define_method("gt_eq_u32", method!(RbSeries::gt_eq_u32, 1))?;
|
657
|
+
class.define_method("gt_eq_u64", method!(RbSeries::gt_eq_u64, 1))?;
|
658
|
+
class.define_method("gt_eq_i8", method!(RbSeries::gt_eq_i8, 1))?;
|
659
|
+
class.define_method("gt_eq_i16", method!(RbSeries::gt_eq_i16, 1))?;
|
660
|
+
class.define_method("gt_eq_i32", method!(RbSeries::gt_eq_i32, 1))?;
|
661
|
+
class.define_method("gt_eq_i64", method!(RbSeries::gt_eq_i64, 1))?;
|
662
|
+
class.define_method("gt_eq_f32", method!(RbSeries::gt_eq_f32, 1))?;
|
663
|
+
class.define_method("gt_eq_f64", method!(RbSeries::gt_eq_f64, 1))?;
|
664
|
+
// class.define_method("gt_eq_str", method!(RbSeries::gt_eq_str, 1))?;
|
665
|
+
|
666
|
+
// lt
|
667
|
+
class.define_method("lt_u8", method!(RbSeries::lt_u8, 1))?;
|
668
|
+
class.define_method("lt_u16", method!(RbSeries::lt_u16, 1))?;
|
669
|
+
class.define_method("lt_u32", method!(RbSeries::lt_u32, 1))?;
|
670
|
+
class.define_method("lt_u64", method!(RbSeries::lt_u64, 1))?;
|
671
|
+
class.define_method("lt_i8", method!(RbSeries::lt_i8, 1))?;
|
672
|
+
class.define_method("lt_i16", method!(RbSeries::lt_i16, 1))?;
|
673
|
+
class.define_method("lt_i32", method!(RbSeries::lt_i32, 1))?;
|
674
|
+
class.define_method("lt_i64", method!(RbSeries::lt_i64, 1))?;
|
675
|
+
class.define_method("lt_f32", method!(RbSeries::lt_f32, 1))?;
|
676
|
+
class.define_method("lt_f64", method!(RbSeries::lt_f64, 1))?;
|
677
|
+
// class.define_method("lt_str", method!(RbSeries::lt_str, 1))?;
|
678
|
+
|
679
|
+
// lt_eq
|
680
|
+
class.define_method("lt_eq_u8", method!(RbSeries::lt_eq_u8, 1))?;
|
681
|
+
class.define_method("lt_eq_u16", method!(RbSeries::lt_eq_u16, 1))?;
|
682
|
+
class.define_method("lt_eq_u32", method!(RbSeries::lt_eq_u32, 1))?;
|
683
|
+
class.define_method("lt_eq_u64", method!(RbSeries::lt_eq_u64, 1))?;
|
684
|
+
class.define_method("lt_eq_i8", method!(RbSeries::lt_eq_i8, 1))?;
|
685
|
+
class.define_method("lt_eq_i16", method!(RbSeries::lt_eq_i16, 1))?;
|
686
|
+
class.define_method("lt_eq_i32", method!(RbSeries::lt_eq_i32, 1))?;
|
687
|
+
class.define_method("lt_eq_i64", method!(RbSeries::lt_eq_i64, 1))?;
|
688
|
+
class.define_method("lt_eq_f32", method!(RbSeries::lt_eq_f32, 1))?;
|
689
|
+
class.define_method("lt_eq_f64", method!(RbSeries::lt_eq_f64, 1))?;
|
690
|
+
// class.define_method("lt_eq_str", method!(RbSeries::lt_eq_str, 1))?;
|
547
691
|
|
548
692
|
let class = module.define_class("RbWhen", Default::default())?;
|
549
693
|
class.define_method("_then", method!(RbWhen::then, 1))?;
|
@@ -641,3 +785,34 @@ fn parquet_schema(rb_f: Value) -> RbResult<Value> {
|
|
641
785
|
}
|
642
786
|
Ok(dict.into())
|
643
787
|
}
|
788
|
+
|
789
|
+
fn rb_date_range(
|
790
|
+
start: i64,
|
791
|
+
stop: i64,
|
792
|
+
every: String,
|
793
|
+
closed: Wrap<ClosedWindow>,
|
794
|
+
name: String,
|
795
|
+
tu: Wrap<TimeUnit>,
|
796
|
+
tz: Option<TimeZone>,
|
797
|
+
) -> RbSeries {
|
798
|
+
polars::time::date_range_impl(
|
799
|
+
&name,
|
800
|
+
start,
|
801
|
+
stop,
|
802
|
+
Duration::parse(&every),
|
803
|
+
closed.0,
|
804
|
+
tu.0,
|
805
|
+
tz,
|
806
|
+
)
|
807
|
+
.into_series()
|
808
|
+
.into()
|
809
|
+
}
|
810
|
+
|
811
|
+
fn as_struct(exprs: RArray) -> RbResult<RbExpr> {
|
812
|
+
let exprs = rb_exprs_to_exprs(exprs)?;
|
813
|
+
Ok(polars::lazy::dsl::as_struct(&exprs).into())
|
814
|
+
}
|
815
|
+
|
816
|
+
fn arg_where(condition: &RbExpr) -> RbExpr {
|
817
|
+
polars::lazy::dsl::arg_where(condition.inner.clone()).into()
|
818
|
+
}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
use magnus::Value;
|
2
|
+
use polars::prelude::*;
|
3
|
+
use polars_core::utils::CustomIterTools;
|
4
|
+
|
5
|
+
use crate::conversion::get_rbseq;
|
6
|
+
use crate::{RbPolarsErr, RbResult};
|
7
|
+
|
8
|
+
pub fn rb_seq_to_list(name: &str, seq: Value, dtype: &DataType) -> RbResult<Series> {
|
9
|
+
let (seq, len) = get_rbseq(seq)?;
|
10
|
+
|
11
|
+
let s = match dtype {
|
12
|
+
DataType::Int64 => {
|
13
|
+
let mut builder =
|
14
|
+
ListPrimitiveChunkedBuilder::<Int64Type>::new(name, len, len * 5, DataType::Int64);
|
15
|
+
for sub_seq in seq.each() {
|
16
|
+
let sub_seq = sub_seq?;
|
17
|
+
let (sub_seq, len) = get_rbseq(sub_seq)?;
|
18
|
+
|
19
|
+
// safety: we know the iterators len
|
20
|
+
let iter = unsafe {
|
21
|
+
sub_seq
|
22
|
+
.each()
|
23
|
+
.map(|v| {
|
24
|
+
let v = v.unwrap();
|
25
|
+
if v.is_nil() {
|
26
|
+
None
|
27
|
+
} else {
|
28
|
+
Some(v.try_convert::<i64>().unwrap())
|
29
|
+
}
|
30
|
+
})
|
31
|
+
.trust_my_length(len)
|
32
|
+
};
|
33
|
+
builder.append_iter(iter)
|
34
|
+
}
|
35
|
+
builder.finish().into_series()
|
36
|
+
}
|
37
|
+
DataType::Float64 => {
|
38
|
+
let mut builder = ListPrimitiveChunkedBuilder::<Float64Type>::new(
|
39
|
+
name,
|
40
|
+
len,
|
41
|
+
len * 5,
|
42
|
+
DataType::Float64,
|
43
|
+
);
|
44
|
+
for sub_seq in seq.each() {
|
45
|
+
let sub_seq = sub_seq?;
|
46
|
+
let (sub_seq, len) = get_rbseq(sub_seq)?;
|
47
|
+
// safety: we know the iterators len
|
48
|
+
let iter = unsafe {
|
49
|
+
sub_seq
|
50
|
+
.each()
|
51
|
+
.map(|v| {
|
52
|
+
let v = v.unwrap();
|
53
|
+
if v.is_nil() {
|
54
|
+
None
|
55
|
+
} else {
|
56
|
+
Some(v.try_convert::<f64>().unwrap())
|
57
|
+
}
|
58
|
+
})
|
59
|
+
.trust_my_length(len)
|
60
|
+
};
|
61
|
+
builder.append_iter(iter)
|
62
|
+
}
|
63
|
+
builder.finish().into_series()
|
64
|
+
}
|
65
|
+
DataType::Boolean => {
|
66
|
+
let mut builder = ListBooleanChunkedBuilder::new(name, len, len * 5);
|
67
|
+
for sub_seq in seq.each() {
|
68
|
+
let sub_seq = sub_seq?;
|
69
|
+
let (sub_seq, len) = get_rbseq(sub_seq)?;
|
70
|
+
// safety: we know the iterators len
|
71
|
+
let iter = unsafe {
|
72
|
+
sub_seq
|
73
|
+
.each()
|
74
|
+
.map(|v| {
|
75
|
+
let v = v.unwrap();
|
76
|
+
if v.is_nil() {
|
77
|
+
None
|
78
|
+
} else {
|
79
|
+
Some(v.try_convert::<bool>().unwrap())
|
80
|
+
}
|
81
|
+
})
|
82
|
+
.trust_my_length(len)
|
83
|
+
};
|
84
|
+
builder.append_iter(iter)
|
85
|
+
}
|
86
|
+
builder.finish().into_series()
|
87
|
+
}
|
88
|
+
DataType::Utf8 => {
|
89
|
+
return Err(RbPolarsErr::todo());
|
90
|
+
}
|
91
|
+
dt => {
|
92
|
+
return Err(RbPolarsErr::other(format!(
|
93
|
+
"cannot create list array from {:?}",
|
94
|
+
dt
|
95
|
+
)));
|
96
|
+
}
|
97
|
+
};
|
98
|
+
|
99
|
+
Ok(s)
|
100
|
+
}
|