polars-df 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/Cargo.lock +468 -538
  4. data/Cargo.toml +1 -0
  5. data/README.md +8 -7
  6. data/ext/polars/Cargo.toml +17 -10
  7. data/ext/polars/src/batched_csv.rs +26 -26
  8. data/ext/polars/src/conversion.rs +121 -93
  9. data/ext/polars/src/dataframe.rs +116 -71
  10. data/ext/polars/src/error.rs +0 -5
  11. data/ext/polars/src/expr/binary.rs +18 -6
  12. data/ext/polars/src/expr/datetime.rs +10 -12
  13. data/ext/polars/src/expr/general.rs +68 -284
  14. data/ext/polars/src/expr/list.rs +17 -9
  15. data/ext/polars/src/{expr.rs → expr/mod.rs} +4 -2
  16. data/ext/polars/src/expr/name.rs +44 -0
  17. data/ext/polars/src/expr/rolling.rs +196 -0
  18. data/ext/polars/src/expr/string.rs +85 -58
  19. data/ext/polars/src/file.rs +3 -3
  20. data/ext/polars/src/functions/aggregation.rs +35 -0
  21. data/ext/polars/src/functions/eager.rs +7 -31
  22. data/ext/polars/src/functions/io.rs +10 -10
  23. data/ext/polars/src/functions/lazy.rs +66 -41
  24. data/ext/polars/src/functions/meta.rs +30 -0
  25. data/ext/polars/src/functions/misc.rs +8 -0
  26. data/ext/polars/src/functions/mod.rs +5 -0
  27. data/ext/polars/src/functions/random.rs +6 -0
  28. data/ext/polars/src/functions/range.rs +46 -0
  29. data/ext/polars/src/functions/string_cache.rs +11 -0
  30. data/ext/polars/src/functions/whenthen.rs +7 -7
  31. data/ext/polars/src/lazyframe.rs +47 -42
  32. data/ext/polars/src/lib.rs +156 -72
  33. data/ext/polars/src/{apply → map}/dataframe.rs +28 -33
  34. data/ext/polars/src/{apply → map}/mod.rs +3 -3
  35. data/ext/polars/src/{apply → map}/series.rs +12 -16
  36. data/ext/polars/src/object.rs +1 -1
  37. data/ext/polars/src/rb_modules.rs +22 -7
  38. data/ext/polars/src/series/construction.rs +4 -4
  39. data/ext/polars/src/series/export.rs +2 -2
  40. data/ext/polars/src/series/set_at_idx.rs +33 -17
  41. data/ext/polars/src/series.rs +7 -27
  42. data/ext/polars/src/sql.rs +46 -0
  43. data/lib/polars/config.rb +530 -0
  44. data/lib/polars/data_frame.rb +115 -82
  45. data/lib/polars/date_time_expr.rb +13 -18
  46. data/lib/polars/date_time_name_space.rb +5 -25
  47. data/lib/polars/dynamic_group_by.rb +2 -2
  48. data/lib/polars/expr.rb +177 -94
  49. data/lib/polars/functions.rb +29 -37
  50. data/lib/polars/group_by.rb +38 -55
  51. data/lib/polars/io.rb +37 -2
  52. data/lib/polars/lazy_frame.rb +93 -66
  53. data/lib/polars/lazy_functions.rb +36 -48
  54. data/lib/polars/lazy_group_by.rb +7 -8
  55. data/lib/polars/list_expr.rb +12 -8
  56. data/lib/polars/list_name_space.rb +2 -2
  57. data/lib/polars/name_expr.rb +198 -0
  58. data/lib/polars/rolling_group_by.rb +2 -2
  59. data/lib/polars/series.rb +26 -13
  60. data/lib/polars/sql_context.rb +194 -0
  61. data/lib/polars/string_expr.rb +114 -60
  62. data/lib/polars/string_name_space.rb +19 -4
  63. data/lib/polars/utils.rb +12 -0
  64. data/lib/polars/version.rb +1 -1
  65. data/lib/polars.rb +3 -0
  66. metadata +18 -7
  67. /data/ext/polars/src/{apply → map}/lazy.rs +0 -0
@@ -1,4 +1,3 @@
1
- mod apply;
2
1
  mod batched_csv;
3
2
  mod conversion;
4
3
  mod dataframe;
@@ -8,10 +7,12 @@ mod file;
8
7
  mod functions;
9
8
  mod lazyframe;
10
9
  mod lazygroupby;
10
+ mod map;
11
11
  mod object;
12
12
  mod prelude;
13
13
  pub(crate) mod rb_modules;
14
14
  mod series;
15
+ mod sql;
15
16
  mod utils;
16
17
 
17
18
  use batched_csv::RbBatchedCsv;
@@ -20,11 +21,12 @@ use dataframe::RbDataFrame;
20
21
  use error::{RbPolarsErr, RbTypeError, RbValueError};
21
22
  use expr::rb_exprs_to_exprs;
22
23
  use expr::RbExpr;
23
- use functions::whenthen::{RbWhen, RbWhenThen};
24
+ use functions::whenthen::{RbThen, RbWhen};
24
25
  use lazyframe::RbLazyFrame;
25
26
  use lazygroupby::RbLazyGroupBy;
26
- use magnus::{define_module, function, method, prelude::*, Error};
27
+ use magnus::{define_module, function, method, prelude::*, Error, Ruby};
27
28
  use series::RbSeries;
29
+ use sql::RbSQLContext;
28
30
 
29
31
  #[cfg(target_os = "linux")]
30
32
  use jemallocator::Jemalloc;
@@ -43,15 +45,19 @@ static GLOBAL: MiMalloc = MiMalloc;
43
45
  type RbResult<T> = Result<T, Error>;
44
46
 
45
47
  #[magnus::init]
46
- fn init() -> RbResult<()> {
48
+ fn init(ruby: &Ruby) -> RbResult<()> {
47
49
  let module = define_module("Polars")?;
48
50
  module.define_singleton_method(
49
51
  "_dtype_cols",
50
52
  function!(crate::functions::lazy::dtype_cols2, 1),
51
53
  )?;
54
+ module.define_singleton_method(
55
+ "_concat_lf_diagonal",
56
+ function!(crate::functions::lazy::concat_lf_diagonal, 4),
57
+ )?;
52
58
  module.define_singleton_method(
53
59
  "_rb_duration",
54
- function!(crate::functions::lazy::duration, 8),
60
+ function!(crate::functions::lazy::duration, 9),
55
61
  )?;
56
62
  module.define_singleton_method(
57
63
  "_concat_df",
@@ -62,12 +68,12 @@ fn init() -> RbResult<()> {
62
68
  function!(crate::functions::lazy::concat_lf, 4),
63
69
  )?;
64
70
  module.define_singleton_method(
65
- "_diag_concat_df",
66
- function!(crate::functions::eager::diag_concat_df, 1),
71
+ "_concat_df_diagonal",
72
+ function!(crate::functions::eager::concat_df_diagonal, 1),
67
73
  )?;
68
74
  module.define_singleton_method(
69
- "_hor_concat_df",
70
- function!(crate::functions::eager::hor_concat_df, 1),
75
+ "_concat_df_horizontal",
76
+ function!(crate::functions::eager::concat_df_horizontal, 1),
71
77
  )?;
72
78
  module.define_singleton_method(
73
79
  "_concat_series",
@@ -87,15 +93,35 @@ fn init() -> RbResult<()> {
87
93
  )?;
88
94
  module.define_singleton_method(
89
95
  "_rb_date_range",
90
- function!(crate::functions::eager::date_range, 7),
96
+ function!(crate::functions::range::date_range, 6),
91
97
  )?;
92
98
  module.define_singleton_method(
93
99
  "_coalesce_exprs",
94
100
  function!(crate::functions::lazy::coalesce, 1),
95
101
  )?;
96
102
  module.define_singleton_method(
97
- "_sum_exprs",
98
- function!(crate::functions::lazy::sum_exprs, 1),
103
+ "_all_horizontal",
104
+ function!(crate::functions::aggregation::all_horizontal, 1),
105
+ )?;
106
+ module.define_singleton_method(
107
+ "_any_horizontal",
108
+ function!(crate::functions::aggregation::any_horizontal, 1),
109
+ )?;
110
+ module.define_singleton_method(
111
+ "_max_horizontal",
112
+ function!(crate::functions::aggregation::max_horizontal, 1),
113
+ )?;
114
+ module.define_singleton_method(
115
+ "_min_horizontal",
116
+ function!(crate::functions::aggregation::min_horizontal, 1),
117
+ )?;
118
+ module.define_singleton_method(
119
+ "_sum_horizontal",
120
+ function!(crate::functions::aggregation::sum_horizontal, 1),
121
+ )?;
122
+ module.define_singleton_method(
123
+ "_dtype_str_repr",
124
+ function!(crate::functions::misc::dtype_str_repr, 1),
99
125
  )?;
100
126
  module.define_singleton_method(
101
127
  "_as_struct",
@@ -109,17 +135,46 @@ fn init() -> RbResult<()> {
109
135
  "_get_idx_type",
110
136
  function!(crate::functions::meta::get_idx_type, 0),
111
137
  )?;
138
+ module.define_singleton_method(
139
+ "_threadpool_size",
140
+ function!(crate::functions::meta::threadpool_size, 0),
141
+ )?;
142
+ module.define_singleton_method(
143
+ "_enable_string_cache",
144
+ function!(crate::functions::string_cache::enable_string_cache, 0),
145
+ )?;
146
+ module.define_singleton_method(
147
+ "_disable_string_cache",
148
+ function!(crate::functions::string_cache::disable_string_cache, 0),
149
+ )?;
150
+ module.define_singleton_method(
151
+ "_using_string_cache",
152
+ function!(crate::functions::string_cache::using_string_cache, 0),
153
+ )?;
154
+ module.define_singleton_method(
155
+ "_set_float_fmt",
156
+ function!(crate::functions::meta::set_float_fmt, 1),
157
+ )?;
158
+ module.define_singleton_method(
159
+ "_get_float_fmt",
160
+ function!(crate::functions::meta::get_float_fmt, 0),
161
+ )?;
162
+ module.define_singleton_method(
163
+ "_set_random_seed",
164
+ function!(crate::functions::random::set_random_seed, 1),
165
+ )?;
112
166
 
113
- let class = module.define_class("RbBatchedCsv", Default::default())?;
167
+ let class = module.define_class("RbBatchedCsv", ruby.class_object())?;
114
168
  class.define_singleton_method("new", function!(RbBatchedCsv::new, -1))?;
115
169
  class.define_method("next_batches", method!(RbBatchedCsv::next_batches, 1))?;
116
170
 
117
- let class = module.define_class("RbDataFrame", Default::default())?;
171
+ let class = module.define_class("RbDataFrame", ruby.class_object())?;
118
172
  class.define_singleton_method("new", function!(RbDataFrame::init, 1))?;
119
173
  class.define_singleton_method("read_csv", function!(RbDataFrame::read_csv, -1))?;
120
174
  class.define_singleton_method("read_parquet", function!(RbDataFrame::read_parquet, 9))?;
121
175
  class.define_singleton_method("read_ipc", function!(RbDataFrame::read_ipc, 6))?;
122
176
  class.define_singleton_method("read_avro", function!(RbDataFrame::read_avro, 4))?;
177
+ class.define_singleton_method("read_rows", function!(RbDataFrame::read_rows, 3))?;
123
178
  class.define_singleton_method("read_hashes", function!(RbDataFrame::read_hashes, 3))?;
124
179
  class.define_singleton_method("read_hash", function!(RbDataFrame::read_hash, 1))?;
125
180
  class.define_singleton_method("read_json", function!(RbDataFrame::read_json, 1))?;
@@ -202,10 +257,10 @@ fn init() -> RbResult<()> {
202
257
  class.define_method("std", method!(RbDataFrame::std, 1))?;
203
258
  class.define_method("var", method!(RbDataFrame::var, 1))?;
204
259
  class.define_method("median", method!(RbDataFrame::median, 0))?;
205
- class.define_method("hmean", method!(RbDataFrame::hmean, 1))?;
206
- class.define_method("hmax", method!(RbDataFrame::hmax, 0))?;
207
- class.define_method("hmin", method!(RbDataFrame::hmin, 0))?;
208
- class.define_method("hsum", method!(RbDataFrame::hsum, 1))?;
260
+ class.define_method("mean_horizontal", method!(RbDataFrame::mean_horizontal, 1))?;
261
+ class.define_method("max_horizontal", method!(RbDataFrame::max_horizontal, 0))?;
262
+ class.define_method("min_horizontal", method!(RbDataFrame::min_horizontal, 0))?;
263
+ class.define_method("sum_horizontal", method!(RbDataFrame::sum_horizontal, 1))?;
209
264
  class.define_method("quantile", method!(RbDataFrame::quantile, 2))?;
210
265
  class.define_method("to_dummies", method!(RbDataFrame::to_dummies, 3))?;
211
266
  class.define_method("null_count", method!(RbDataFrame::null_count, 0))?;
@@ -217,7 +272,7 @@ fn init() -> RbResult<()> {
217
272
  class.define_method("to_struct", method!(RbDataFrame::to_struct, 1))?;
218
273
  class.define_method("unnest", method!(RbDataFrame::unnest, 1))?;
219
274
 
220
- let class = module.define_class("RbExpr", Default::default())?;
275
+ let class = module.define_class("RbExpr", ruby.class_object())?;
221
276
  class.define_method("+", method!(RbExpr::add, 1))?;
222
277
  class.define_method("-", method!(RbExpr::sub, 1))?;
223
278
  class.define_method("*", method!(RbExpr::mul, 1))?;
@@ -264,15 +319,16 @@ fn init() -> RbResult<()> {
264
319
  class.define_method("arg_sort", method!(RbExpr::arg_sort, 2))?;
265
320
  class.define_method("top_k", method!(RbExpr::top_k, 1))?;
266
321
  class.define_method("bottom_k", method!(RbExpr::bottom_k, 1))?;
322
+ class.define_method("peak_min", method!(RbExpr::peak_min, 0))?;
323
+ class.define_method("peak_max", method!(RbExpr::peak_max, 0))?;
267
324
  class.define_method("arg_max", method!(RbExpr::arg_max, 0))?;
268
325
  class.define_method("arg_min", method!(RbExpr::arg_min, 0))?;
269
326
  class.define_method("search_sorted", method!(RbExpr::search_sorted, 2))?;
270
- class.define_method("take", method!(RbExpr::take, 1))?;
327
+ class.define_method("gather", method!(RbExpr::gather, 1))?;
271
328
  class.define_method("sort_by", method!(RbExpr::sort_by, 2))?;
272
329
  class.define_method("backward_fill", method!(RbExpr::backward_fill, 1))?;
273
330
  class.define_method("forward_fill", method!(RbExpr::forward_fill, 1))?;
274
- class.define_method("shift", method!(RbExpr::shift, 1))?;
275
- class.define_method("shift_and_fill", method!(RbExpr::shift_and_fill, 2))?;
331
+ class.define_method("shift", method!(RbExpr::shift, 2))?;
276
332
  class.define_method("fill_null", method!(RbExpr::fill_null, 1))?;
277
333
  class.define_method(
278
334
  "fill_null_with_strategy",
@@ -286,10 +342,11 @@ fn init() -> RbResult<()> {
286
342
  class.define_method("std", method!(RbExpr::std, 1))?;
287
343
  class.define_method("var", method!(RbExpr::var, 1))?;
288
344
  class.define_method("is_unique", method!(RbExpr::is_unique, 0))?;
289
- class.define_method("approx_unique", method!(RbExpr::approx_unique, 0))?;
290
- class.define_method("is_first", method!(RbExpr::is_first, 0))?;
345
+ class.define_method("approx_n_unique", method!(RbExpr::approx_n_unique, 0))?;
346
+ class.define_method("is_first_distinct", method!(RbExpr::is_first_distinct, 0))?;
347
+ class.define_method("is_last_distinct", method!(RbExpr::is_last_distinct, 0))?;
291
348
  class.define_method("explode", method!(RbExpr::explode, 0))?;
292
- class.define_method("take_every", method!(RbExpr::take_every, 1))?;
349
+ class.define_method("gather_every", method!(RbExpr::gather_every, 1))?;
293
350
  class.define_method("tail", method!(RbExpr::tail, 1))?;
294
351
  class.define_method("head", method!(RbExpr::head, 1))?;
295
352
  class.define_method("slice", method!(RbExpr::slice, 2))?;
@@ -299,8 +356,6 @@ fn init() -> RbResult<()> {
299
356
  class.define_method("floor", method!(RbExpr::floor, 0))?;
300
357
  class.define_method("ceil", method!(RbExpr::ceil, 0))?;
301
358
  class.define_method("clip", method!(RbExpr::clip, 2))?;
302
- class.define_method("clip_min", method!(RbExpr::clip_min, 1))?;
303
- class.define_method("clip_max", method!(RbExpr::clip_max, 1))?;
304
359
  class.define_method("abs", method!(RbExpr::abs, 0))?;
305
360
  class.define_method("sin", method!(RbExpr::sin, 0))?;
306
361
  class.define_method("cos", method!(RbExpr::cos, 0))?;
@@ -323,29 +378,37 @@ fn init() -> RbResult<()> {
323
378
  class.define_method("is_in", method!(RbExpr::is_in, 1))?;
324
379
  class.define_method("repeat_by", method!(RbExpr::repeat_by, 1))?;
325
380
  class.define_method("pow", method!(RbExpr::pow, 1))?;
326
- class.define_method("cumsum", method!(RbExpr::cumsum, 1))?;
327
- class.define_method("cummax", method!(RbExpr::cummax, 1))?;
328
- class.define_method("cummin", method!(RbExpr::cummin, 1))?;
329
- class.define_method("cumprod", method!(RbExpr::cumprod, 1))?;
381
+ class.define_method("cum_sum", method!(RbExpr::cum_sum, 1))?;
382
+ class.define_method("cum_max", method!(RbExpr::cum_max, 1))?;
383
+ class.define_method("cum_min", method!(RbExpr::cum_min, 1))?;
384
+ class.define_method("cum_prod", method!(RbExpr::cum_prod, 1))?;
330
385
  class.define_method("product", method!(RbExpr::product, 0))?;
331
386
  class.define_method("shrink_dtype", method!(RbExpr::shrink_dtype, 0))?;
332
387
  class.define_method("str_to_date", method!(RbExpr::str_to_date, 4))?;
333
- class.define_method("str_to_datetime", method!(RbExpr::str_to_datetime, 6))?;
388
+ class.define_method("str_to_datetime", method!(RbExpr::str_to_datetime, 7))?;
334
389
  class.define_method("str_to_time", method!(RbExpr::str_to_time, 3))?;
335
- class.define_method("str_strip", method!(RbExpr::str_strip, 1))?;
336
- class.define_method("str_rstrip", method!(RbExpr::str_rstrip, 1))?;
337
- class.define_method("str_lstrip", method!(RbExpr::str_lstrip, 1))?;
390
+ class.define_method("str_strip_chars", method!(RbExpr::str_strip_chars, 1))?;
391
+ class.define_method(
392
+ "str_strip_chars_start",
393
+ method!(RbExpr::str_strip_chars_start, 1),
394
+ )?;
395
+ class.define_method(
396
+ "str_strip_chars_end",
397
+ method!(RbExpr::str_strip_chars_end, 1),
398
+ )?;
399
+ class.define_method("str_strip_prefix", method!(RbExpr::str_strip_prefix, 1))?;
400
+ class.define_method("str_strip_suffix", method!(RbExpr::str_strip_suffix, 1))?;
338
401
  class.define_method("str_slice", method!(RbExpr::str_slice, 2))?;
339
402
  class.define_method("str_explode", method!(RbExpr::str_explode, 0))?;
340
403
  class.define_method("str_to_uppercase", method!(RbExpr::str_to_uppercase, 0))?;
341
404
  class.define_method("str_to_lowercase", method!(RbExpr::str_to_lowercase, 0))?;
342
- class.define_method("str_lengths", method!(RbExpr::str_lengths, 0))?;
343
- class.define_method("str_n_chars", method!(RbExpr::str_n_chars, 0))?;
405
+ class.define_method("str_len_bytes", method!(RbExpr::str_len_bytes, 0))?;
406
+ class.define_method("str_len_chars", method!(RbExpr::str_len_chars, 0))?;
344
407
  class.define_method("str_replace_n", method!(RbExpr::str_replace_n, 4))?;
345
408
  class.define_method("str_replace_all", method!(RbExpr::str_replace_all, 3))?;
346
409
  class.define_method("str_zfill", method!(RbExpr::str_zfill, 1))?;
347
- class.define_method("str_ljust", method!(RbExpr::str_ljust, 2))?;
348
- class.define_method("str_rjust", method!(RbExpr::str_rjust, 2))?;
410
+ class.define_method("str_pad_start", method!(RbExpr::str_pad_start, 2))?;
411
+ class.define_method("str_pad_end", method!(RbExpr::str_pad_end, 2))?;
349
412
  class.define_method("str_contains", method!(RbExpr::str_contains, 3))?;
350
413
  class.define_method("str_ends_with", method!(RbExpr::str_ends_with, 1))?;
351
414
  class.define_method("str_starts_with", method!(RbExpr::str_starts_with, 1))?;
@@ -359,7 +422,7 @@ fn init() -> RbResult<()> {
359
422
  class.define_method("str_hex_decode", method!(RbExpr::str_hex_decode, 1))?;
360
423
  class.define_method("str_base64_encode", method!(RbExpr::str_base64_encode, 0))?;
361
424
  class.define_method("str_base64_decode", method!(RbExpr::str_base64_decode, 1))?;
362
- class.define_method("str_parse_int", method!(RbExpr::str_parse_int, 2))?;
425
+ class.define_method("str_to_integer", method!(RbExpr::str_to_integer, 2))?;
363
426
  class.define_method("str_json_extract", method!(RbExpr::str_json_extract, 2))?;
364
427
  class.define_method("binary_hex_encode", method!(RbExpr::bin_hex_encode, 0))?;
365
428
  class.define_method("binary_hex_decode", method!(RbExpr::bin_hex_decode, 1))?;
@@ -377,7 +440,7 @@ fn init() -> RbResult<()> {
377
440
  )?;
378
441
  class.define_method("str_extract", method!(RbExpr::str_extract, 2))?;
379
442
  class.define_method("str_extract_all", method!(RbExpr::str_extract_all, 1))?;
380
- class.define_method("count_match", method!(RbExpr::str_count_match, 1))?;
443
+ class.define_method("str_count_matches", method!(RbExpr::str_count_matches, 2))?;
381
444
  class.define_method("strftime", method!(RbExpr::dt_to_string, 1))?;
382
445
  class.define_method("str_split", method!(RbExpr::str_split, 1))?;
383
446
  class.define_method(
@@ -390,9 +453,9 @@ fn init() -> RbResult<()> {
390
453
  method!(RbExpr::str_split_exact_inclusive, 2),
391
454
  )?;
392
455
  class.define_method("str_splitn", method!(RbExpr::str_splitn, 2))?;
393
- class.define_method("list_lengths", method!(RbExpr::list_lengths, 0))?;
456
+ class.define_method("list_len", method!(RbExpr::list_len, 0))?;
394
457
  class.define_method("list_contains", method!(RbExpr::list_contains, 1))?;
395
- class.define_method("list_count_match", method!(RbExpr::list_count_match, 1))?;
458
+ class.define_method("list_count_matches", method!(RbExpr::list_count_matches, 1))?;
396
459
  class.define_method("year", method!(RbExpr::dt_year, 0))?;
397
460
  class.define_method("dt_is_leap_year", method!(RbExpr::dt_is_leap_year, 0))?;
398
461
  class.define_method("iso_year", method!(RbExpr::dt_iso_year, 0))?;
@@ -440,7 +503,6 @@ fn init() -> RbResult<()> {
440
503
  "dt_replace_time_zone",
441
504
  method!(RbExpr::dt_replace_time_zone, 2),
442
505
  )?;
443
- class.define_method("dt_tz_localize", method!(RbExpr::dt_tz_localize, 1))?;
444
506
  class.define_method("dt_truncate", method!(RbExpr::dt_truncate, 2))?;
445
507
  class.define_method("dt_month_start", method!(RbExpr::dt_month_start, 0))?;
446
508
  class.define_method("dt_month_end", method!(RbExpr::dt_month_end, 0))?;
@@ -450,10 +512,6 @@ fn init() -> RbResult<()> {
450
512
  class.define_method("dot", method!(RbExpr::dot, 1))?;
451
513
  class.define_method("reinterpret", method!(RbExpr::reinterpret, 1))?;
452
514
  class.define_method("mode", method!(RbExpr::mode, 0))?;
453
- class.define_method("keep_name", method!(RbExpr::keep_name, 0))?;
454
- class.define_method("prefix", method!(RbExpr::prefix, 1))?;
455
- class.define_method("suffix", method!(RbExpr::suffix, 1))?;
456
- class.define_method("map_alias", method!(RbExpr::map_alias, 1))?;
457
515
  class.define_method("exclude", method!(RbExpr::exclude, 1))?;
458
516
  class.define_method("interpolate", method!(RbExpr::interpolate, 1))?;
459
517
  class.define_method("rolling_sum", method!(RbExpr::rolling_sum, 6))?;
@@ -490,20 +548,20 @@ fn init() -> RbResult<()> {
490
548
  class.define_method("pct_change", method!(RbExpr::pct_change, 1))?;
491
549
  class.define_method("skew", method!(RbExpr::skew, 1))?;
492
550
  class.define_method("kurtosis", method!(RbExpr::kurtosis, 2))?;
493
- class.define_method("str_concat", method!(RbExpr::str_concat, 1))?;
551
+ class.define_method("str_concat", method!(RbExpr::str_concat, 2))?;
494
552
  class.define_method("cat_set_ordering", method!(RbExpr::cat_set_ordering, 1))?;
495
553
  class.define_method("reshape", method!(RbExpr::reshape, 1))?;
496
- class.define_method("cumcount", method!(RbExpr::cumcount, 1))?;
554
+ class.define_method("cum_count", method!(RbExpr::cum_count, 1))?;
497
555
  class.define_method("to_physical", method!(RbExpr::to_physical, 0))?;
498
- class.define_method("shuffle", method!(RbExpr::shuffle, 2))?;
499
- class.define_method("sample_n", method!(RbExpr::sample_n, 5))?;
500
- class.define_method("sample_frac", method!(RbExpr::sample_frac, 5))?;
556
+ class.define_method("shuffle", method!(RbExpr::shuffle, 1))?;
557
+ class.define_method("sample_n", method!(RbExpr::sample_n, 4))?;
558
+ class.define_method("sample_frac", method!(RbExpr::sample_frac, 4))?;
501
559
  class.define_method("ewm_mean", method!(RbExpr::ewm_mean, 4))?;
502
560
  class.define_method("ewm_std", method!(RbExpr::ewm_std, 5))?;
503
561
  class.define_method("ewm_var", method!(RbExpr::ewm_var, 5))?;
504
562
  class.define_method("extend_constant", method!(RbExpr::extend_constant, 2))?;
505
- class.define_method("any", method!(RbExpr::any, 0))?;
506
- class.define_method("all", method!(RbExpr::all, 0))?;
563
+ class.define_method("any", method!(RbExpr::any, 1))?;
564
+ class.define_method("all", method!(RbExpr::all, 1))?;
507
565
  class.define_method(
508
566
  "struct_field_by_name",
509
567
  method!(RbExpr::struct_field_by_name, 1),
@@ -537,6 +595,14 @@ fn init() -> RbResult<()> {
537
595
  method!(RbExpr::meta_is_regex_projection, 0),
538
596
  )?;
539
597
 
598
+ // name
599
+ class.define_method("name_keep", method!(RbExpr::name_keep, 0))?;
600
+ class.define_method("name_map", method!(RbExpr::name_map, 1))?;
601
+ class.define_method("name_prefix", method!(RbExpr::name_prefix, 1))?;
602
+ class.define_method("name_suffix", method!(RbExpr::name_suffix, 1))?;
603
+ class.define_method("name_to_lowercase", method!(RbExpr::name_to_lowercase, 0))?;
604
+ class.define_method("name_to_uppercase", method!(RbExpr::name_to_uppercase, 0))?;
605
+
540
606
  // maybe add to different class
541
607
  class.define_singleton_method("col", function!(crate::functions::lazy::col, 1))?;
542
608
  class.define_singleton_method("count", function!(crate::functions::lazy::count, 0))?;
@@ -546,7 +612,14 @@ fn init() -> RbResult<()> {
546
612
  class.define_singleton_method("fold", function!(crate::functions::lazy::fold, 3))?;
547
613
  class.define_singleton_method("cumfold", function!(crate::functions::lazy::cumfold, 4))?;
548
614
  class.define_singleton_method("lit", function!(crate::functions::lazy::lit, 2))?;
549
- class.define_singleton_method("arange", function!(crate::functions::lazy::arange, 3))?;
615
+ class.define_singleton_method(
616
+ "int_range",
617
+ function!(crate::functions::range::int_range, 4),
618
+ )?;
619
+ class.define_singleton_method(
620
+ "int_ranges",
621
+ function!(crate::functions::range::int_ranges, 4),
622
+ )?;
550
623
  class.define_singleton_method("repeat", function!(crate::functions::lazy::repeat, 3))?;
551
624
  class.define_singleton_method(
552
625
  "pearson_corr",
@@ -556,7 +629,7 @@ fn init() -> RbResult<()> {
556
629
  "spearman_rank_corr",
557
630
  function!(crate::functions::lazy::spearman_rank_corr, 4),
558
631
  )?;
559
- class.define_singleton_method("cov", function!(crate::functions::lazy::cov, 2))?;
632
+ class.define_singleton_method("cov", function!(crate::functions::lazy::cov, 3))?;
560
633
  class.define_singleton_method(
561
634
  "arg_sort_by",
562
635
  function!(crate::functions::lazy::arg_sort_by, 2),
@@ -571,7 +644,7 @@ fn init() -> RbResult<()> {
571
644
  function!(crate::functions::lazy::concat_lst, 1),
572
645
  )?;
573
646
 
574
- let class = module.define_class("RbLazyFrame", Default::default())?;
647
+ let class = module.define_class("RbLazyFrame", ruby.class_object())?;
575
648
  class.define_singleton_method("read_json", function!(RbLazyFrame::read_json, 1))?;
576
649
  class.define_singleton_method(
577
650
  "new_from_ndjson",
@@ -580,7 +653,7 @@ fn init() -> RbResult<()> {
580
653
  class.define_singleton_method("new_from_csv", function!(RbLazyFrame::new_from_csv, -1))?;
581
654
  class.define_singleton_method(
582
655
  "new_from_parquet",
583
- function!(RbLazyFrame::new_from_parquet, 8),
656
+ function!(RbLazyFrame::new_from_parquet, 9),
584
657
  )?;
585
658
  class.define_singleton_method("new_from_ipc", function!(RbLazyFrame::new_from_ipc, 6))?;
586
659
  class.define_method("write_json", method!(RbLazyFrame::write_json, 1))?;
@@ -591,7 +664,7 @@ fn init() -> RbResult<()> {
591
664
  )?;
592
665
  class.define_method(
593
666
  "optimization_toggle",
594
- method!(RbLazyFrame::optimization_toggle, 7),
667
+ method!(RbLazyFrame::optimization_toggle, 8),
595
668
  )?;
596
669
  class.define_method("sort", method!(RbLazyFrame::sort, 4))?;
597
670
  class.define_method("sort_by_exprs", method!(RbLazyFrame::sort_by_exprs, 4))?;
@@ -601,17 +674,22 @@ fn init() -> RbResult<()> {
601
674
  class.define_method("fetch", method!(RbLazyFrame::fetch, 1))?;
602
675
  class.define_method("filter", method!(RbLazyFrame::filter, 1))?;
603
676
  class.define_method("select", method!(RbLazyFrame::select, 1))?;
604
- class.define_method("groupby", method!(RbLazyFrame::groupby, 2))?;
605
- class.define_method("groupby_rolling", method!(RbLazyFrame::groupby_rolling, 6))?;
606
- class.define_method("groupby_dynamic", method!(RbLazyFrame::groupby_dynamic, 9))?;
677
+ class.define_method("group_by", method!(RbLazyFrame::group_by, 2))?;
678
+ class.define_method(
679
+ "group_by_rolling",
680
+ method!(RbLazyFrame::group_by_rolling, 6),
681
+ )?;
682
+ class.define_method(
683
+ "group_by_dynamic",
684
+ method!(RbLazyFrame::group_by_dynamic, 10),
685
+ )?;
607
686
  class.define_method("with_context", method!(RbLazyFrame::with_context, 1))?;
608
687
  class.define_method("join_asof", method!(RbLazyFrame::join_asof, 11))?;
609
688
  class.define_method("join", method!(RbLazyFrame::join, 7))?;
610
689
  class.define_method("with_columns", method!(RbLazyFrame::with_columns, 1))?;
611
690
  class.define_method("rename", method!(RbLazyFrame::rename, 2))?;
612
691
  class.define_method("reverse", method!(RbLazyFrame::reverse, 0))?;
613
- class.define_method("shift", method!(RbLazyFrame::shift, 1))?;
614
- class.define_method("shift_and_fill", method!(RbLazyFrame::shift_and_fill, 2))?;
692
+ class.define_method("shift", method!(RbLazyFrame::shift, 2))?;
615
693
  class.define_method("fill_nan", method!(RbLazyFrame::fill_nan, 1))?;
616
694
  class.define_method("min", method!(RbLazyFrame::min, 0))?;
617
695
  class.define_method("max", method!(RbLazyFrame::max, 0))?;
@@ -636,12 +714,12 @@ fn init() -> RbResult<()> {
636
714
  class.define_method("unnest", method!(RbLazyFrame::unnest, 1))?;
637
715
  class.define_method("width", method!(RbLazyFrame::width, 0))?;
638
716
 
639
- let class = module.define_class("RbLazyGroupBy", Default::default())?;
717
+ let class = module.define_class("RbLazyGroupBy", ruby.class_object())?;
640
718
  class.define_method("agg", method!(RbLazyGroupBy::agg, 1))?;
641
719
  class.define_method("head", method!(RbLazyGroupBy::head, 1))?;
642
720
  class.define_method("tail", method!(RbLazyGroupBy::tail, 1))?;
643
721
 
644
- let class = module.define_class("RbSeries", Default::default())?;
722
+ let class = module.define_class("RbSeries", ruby.class_object())?;
645
723
  class.define_singleton_method("new_opt_bool", function!(RbSeries::new_opt_bool, 3))?;
646
724
  class.define_singleton_method("new_opt_u8", function!(RbSeries::new_opt_u8, 3))?;
647
725
  class.define_singleton_method("new_opt_u16", function!(RbSeries::new_opt_u16, 3))?;
@@ -731,8 +809,6 @@ fn init() -> RbResult<()> {
731
809
  class.define_method("apply_lambda", method!(RbSeries::apply_lambda, 3))?;
732
810
  class.define_method("zip_with", method!(RbSeries::zip_with, 2))?;
733
811
  class.define_method("to_dummies", method!(RbSeries::to_dummies, 2))?;
734
- class.define_method("peak_max", method!(RbSeries::peak_max, 0))?;
735
- class.define_method("peak_min", method!(RbSeries::peak_min, 0))?;
736
812
  class.define_method("n_unique", method!(RbSeries::n_unique, 0))?;
737
813
  class.define_method("floor", method!(RbSeries::floor, 0))?;
738
814
  class.define_method("shrink_to_fit", method!(RbSeries::shrink_to_fit, 0))?;
@@ -902,11 +978,19 @@ fn init() -> RbResult<()> {
902
978
  // extra
903
979
  class.define_method("extend_constant", method!(RbSeries::extend_constant, 2))?;
904
980
 
905
- let class = module.define_class("RbWhen", Default::default())?;
981
+ let class = module.define_class("RbWhen", ruby.class_object())?;
906
982
  class.define_method("_then", method!(RbWhen::then, 1))?;
907
983
 
908
- let class = module.define_class("RbWhenThen", Default::default())?;
909
- class.define_method("otherwise", method!(RbWhenThen::overwise, 1))?;
984
+ let class = module.define_class("RbWhenThen", ruby.class_object())?;
985
+ class.define_method("otherwise", method!(RbThen::overwise, 1))?;
986
+
987
+ // sql
988
+ let class = module.define_class("RbSQLContext", ruby.class_object())?;
989
+ class.define_singleton_method("new", function!(RbSQLContext::new, 0))?;
990
+ class.define_method("execute", method!(RbSQLContext::execute, 1))?;
991
+ class.define_method("get_tables", method!(RbSQLContext::get_tables, 0))?;
992
+ class.define_method("register", method!(RbSQLContext::register, 2))?;
993
+ class.define_method("unregister", method!(RbSQLContext::unregister, 1))?;
910
994
 
911
995
  Ok(())
912
996
  }
@@ -1,4 +1,4 @@
1
- use magnus::{class, IntoValue, RArray, TryConvert, Value};
1
+ use magnus::{class, prelude::*, typed_data::Obj, IntoValue, RArray, TryConvert, Value};
2
2
  use polars::prelude::*;
3
3
  use polars_core::frame::row::{rows_to_schema_first_non_null, Row};
4
4
  use polars_core::series::SeriesIter;
@@ -34,20 +34,20 @@ pub fn apply_lambda_unknown<'a>(
34
34
  null_count += 1;
35
35
  continue;
36
36
  } else if out.is_kind_of(class::true_class()) || out.is_kind_of(class::false_class()) {
37
- let first_value = out.try_convert::<bool>().ok();
37
+ let first_value = bool::try_convert(out).ok();
38
38
  return Ok((
39
- RbSeries::new(
39
+ Obj::wrap(RbSeries::new(
40
40
  apply_lambda_with_bool_out_type(df, lambda, null_count, first_value)
41
41
  .into_series(),
42
- )
43
- .into(),
42
+ ))
43
+ .as_value(),
44
44
  false,
45
45
  ));
46
46
  } else if out.is_kind_of(class::float()) {
47
- let first_value = out.try_convert::<f64>().ok();
47
+ let first_value = f64::try_convert(out).ok();
48
48
 
49
49
  return Ok((
50
- RbSeries::new(
50
+ Obj::wrap(RbSeries::new(
51
51
  apply_lambda_with_primitive_out_type::<Float64Type>(
52
52
  df,
53
53
  lambda,
@@ -55,14 +55,14 @@ pub fn apply_lambda_unknown<'a>(
55
55
  first_value,
56
56
  )
57
57
  .into_series(),
58
- )
59
- .into(),
58
+ ))
59
+ .as_value(),
60
60
  false,
61
61
  ));
62
62
  } else if out.is_kind_of(class::integer()) {
63
- let first_value = out.try_convert::<i64>().ok();
63
+ let first_value = i64::try_convert(out).ok();
64
64
  return Ok((
65
- RbSeries::new(
65
+ Obj::wrap(RbSeries::new(
66
66
  apply_lambda_with_primitive_out_type::<Int64Type>(
67
67
  df,
68
68
  lambda,
@@ -70,12 +70,12 @@ pub fn apply_lambda_unknown<'a>(
70
70
  first_value,
71
71
  )
72
72
  .into_series(),
73
- )
74
- .into(),
73
+ ))
74
+ .as_value(),
75
75
  false,
76
76
  ));
77
77
  // } else if out.is_kind_of(class::string()) {
78
- // let first_value = out.try_convert::<String>().ok();
78
+ // let first_value = String::try_convert(out).ok();
79
79
  // return Ok((
80
80
  // RbSeries::new(
81
81
  // apply_lambda_with_utf8_out_type(df, lambda, null_count, first_value)
@@ -85,25 +85,21 @@ pub fn apply_lambda_unknown<'a>(
85
85
  // false,
86
86
  // ));
87
87
  } else if out.respond_to("_s", true)? {
88
- let rb_rbseries: Value = out.funcall("_s", ()).unwrap();
89
- let series = rb_rbseries
90
- .try_convert::<&RbSeries>()
91
- .unwrap()
92
- .series
93
- .borrow();
88
+ let rb_rbseries: Obj<RbSeries> = out.funcall("_s", ()).unwrap();
89
+ let series = rb_rbseries.series.borrow();
94
90
  let dt = series.dtype();
95
91
  return Ok((
96
- RbSeries::new(
92
+ Obj::wrap(RbSeries::new(
97
93
  apply_lambda_with_list_out_type(df, lambda, null_count, Some(&series), dt)?
98
94
  .into_series(),
99
- )
100
- .into(),
95
+ ))
96
+ .as_value(),
101
97
  false,
102
98
  ));
103
- } else if out.try_convert::<Wrap<Row<'a>>>().is_ok() {
104
- let first_value = out.try_convert::<Wrap<Row<'a>>>().unwrap().0;
99
+ } else if Wrap::<Row<'a>>::try_convert(out).is_ok() {
100
+ let first_value = Wrap::<Row<'a>>::try_convert(out).unwrap().0;
105
101
  return Ok((
106
- RbDataFrame::from(
102
+ Obj::wrap(RbDataFrame::from(
107
103
  apply_lambda_with_rows_output(
108
104
  df,
109
105
  lambda,
@@ -112,8 +108,8 @@ pub fn apply_lambda_unknown<'a>(
112
108
  inference_size,
113
109
  )
114
110
  .map_err(RbPolarsErr::from)?,
115
- )
116
- .into(),
111
+ ))
112
+ .as_value(),
117
113
  true,
118
114
  ));
119
115
  } else if out.is_kind_of(class::array()) {
@@ -143,7 +139,7 @@ where
143
139
  let iter = iters.iter_mut().map(|it| Wrap(it.next().unwrap()));
144
140
  let tpl = (RArray::from_iter(iter),);
145
141
  match lambda.funcall::<_, _, Value>("call", tpl) {
146
- Ok(val) => val.try_convert::<T>().ok(),
142
+ Ok(val) => T::try_convert(val).ok(),
147
143
  Err(e) => panic!("ruby function failed {}", e),
148
144
  }
149
145
  })
@@ -219,8 +215,7 @@ pub fn apply_lambda_with_list_out_type(
219
215
  let tpl = (RArray::from_iter(iter),);
220
216
  match lambda.funcall::<_, _, Value>("call", tpl) {
221
217
  Ok(val) => match val.funcall::<_, _, Value>("_s", ()) {
222
- Ok(val) => val
223
- .try_convert::<&RbSeries>()
218
+ Ok(val) => Obj::<RbSeries>::try_convert(val)
224
219
  .ok()
225
220
  .map(|ps| ps.series.borrow().clone()),
226
221
  Err(_) => {
@@ -257,11 +252,11 @@ pub fn apply_lambda_with_rows_output<'a>(
257
252
  let tpl = (RArray::from_iter(iter),);
258
253
  match lambda.funcall::<_, _, Value>("call", tpl) {
259
254
  Ok(val) => {
260
- match val.try_convert::<RArray>().ok() {
255
+ match RArray::try_convert(val).ok() {
261
256
  Some(tuple) => {
262
257
  row_buf.0.clear();
263
258
  for v in tuple.each() {
264
- let v = v.unwrap().try_convert::<Wrap<AnyValue>>().unwrap().0;
259
+ let v = Wrap::<AnyValue>::try_convert(v.unwrap()).unwrap().0;
265
260
  row_buf.0.push(v);
266
261
  }
267
262
  let ptr = &row_buf as *const Row;
@@ -2,7 +2,7 @@ pub mod dataframe;
2
2
  pub mod lazy;
3
3
  pub mod series;
4
4
 
5
- use magnus::{RHash, Value};
5
+ use magnus::{prelude::*, RHash, Value};
6
6
  use polars::chunked_array::builder::get_list_builder;
7
7
  use polars::prelude::*;
8
8
  use polars_core::export::rayon::prelude::*;
@@ -68,7 +68,7 @@ fn iterator_to_struct(
68
68
  }
69
69
  }
70
70
  Some(dict) => {
71
- let dict = dict.try_convert::<RHash>()?;
71
+ let dict = RHash::try_convert(dict)?;
72
72
  if dict.len() != struct_width {
73
73
  return Err(crate::error::ComputeError::new_err(
74
74
  format!("Cannot create struct type.\n> The struct dtype expects {} fields, but it got a dict with {} fields.", struct_width, dict.len())
@@ -78,7 +78,7 @@ fn iterator_to_struct(
78
78
  // the first item determines the output name
79
79
  todo!()
80
80
  // for ((_, val), field_items) in dict.iter().zip(&mut items) {
81
- // let item = val.try_convert::<Wrap<AnyValue>>()?;
81
+ // let item = Wrap::<AnyValue>::try_convert(val)?;
82
82
  // field_items.push(item.0)
83
83
  // }
84
84
  }