polars-df 0.21.1 → 0.23.0
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 +15 -0
- data/Cargo.lock +120 -90
- data/Cargo.toml +3 -0
- data/README.md +20 -7
- data/ext/polars/Cargo.toml +18 -12
- data/ext/polars/src/batched_csv.rs +4 -4
- data/ext/polars/src/catalog/unity.rs +96 -94
- data/ext/polars/src/conversion/any_value.rs +39 -37
- data/ext/polars/src/conversion/chunked_array.rs +36 -29
- data/ext/polars/src/conversion/datetime.rs +11 -0
- data/ext/polars/src/conversion/mod.rs +244 -51
- data/ext/polars/src/dataframe/construction.rs +5 -17
- data/ext/polars/src/dataframe/export.rs +17 -15
- data/ext/polars/src/dataframe/general.rs +15 -17
- data/ext/polars/src/dataframe/io.rs +1 -2
- data/ext/polars/src/dataframe/mod.rs +25 -1
- data/ext/polars/src/dataframe/serde.rs +23 -8
- data/ext/polars/src/exceptions.rs +8 -5
- data/ext/polars/src/expr/datatype.rs +4 -4
- data/ext/polars/src/expr/datetime.rs +22 -28
- data/ext/polars/src/expr/general.rs +3 -10
- data/ext/polars/src/expr/list.rs +8 -24
- data/ext/polars/src/expr/meta.rs +4 -6
- data/ext/polars/src/expr/mod.rs +2 -0
- data/ext/polars/src/expr/name.rs +11 -14
- data/ext/polars/src/expr/serde.rs +28 -0
- data/ext/polars/src/expr/string.rs +5 -10
- data/ext/polars/src/file.rs +20 -14
- data/ext/polars/src/functions/business.rs +0 -1
- data/ext/polars/src/functions/io.rs +7 -4
- data/ext/polars/src/functions/lazy.rs +7 -6
- data/ext/polars/src/functions/meta.rs +3 -3
- data/ext/polars/src/functions/string_cache.rs +3 -3
- data/ext/polars/src/interop/arrow/to_ruby.rs +3 -3
- data/ext/polars/src/interop/numo/numo_rs.rs +4 -3
- data/ext/polars/src/io/mod.rs +23 -3
- data/ext/polars/src/lazyframe/general.rs +35 -50
- data/ext/polars/src/lazyframe/mod.rs +16 -1
- data/ext/polars/src/lazyframe/optflags.rs +57 -0
- data/ext/polars/src/lazyframe/serde.rs +27 -3
- data/ext/polars/src/lib.rs +144 -19
- data/ext/polars/src/map/dataframe.rs +18 -15
- data/ext/polars/src/map/lazy.rs +6 -5
- data/ext/polars/src/map/series.rs +7 -6
- data/ext/polars/src/on_startup.rs +12 -5
- data/ext/polars/src/rb_modules.rs +2 -2
- data/ext/polars/src/series/aggregation.rs +49 -29
- data/ext/polars/src/series/construction.rs +2 -0
- data/ext/polars/src/series/export.rs +38 -33
- data/ext/polars/src/series/general.rs +69 -31
- data/ext/polars/src/series/mod.rs +29 -4
- data/lib/polars/array_expr.rb +1 -1
- data/lib/polars/data_frame.rb +119 -15
- data/lib/polars/data_types.rb +23 -6
- data/lib/polars/date_time_expr.rb +36 -15
- data/lib/polars/expr.rb +41 -32
- data/lib/polars/functions/business.rb +95 -0
- data/lib/polars/functions/lazy.rb +1 -1
- data/lib/polars/iceberg_dataset.rb +113 -0
- data/lib/polars/io/iceberg.rb +34 -0
- data/lib/polars/io/ipc.rb +28 -49
- data/lib/polars/io/parquet.rb +7 -4
- data/lib/polars/io/scan_options.rb +12 -3
- data/lib/polars/io/utils.rb +17 -0
- data/lib/polars/lazy_frame.rb +97 -10
- data/lib/polars/list_expr.rb +21 -13
- data/lib/polars/list_name_space.rb +33 -21
- data/lib/polars/meta_expr.rb +25 -0
- data/lib/polars/query_opt_flags.rb +50 -0
- data/lib/polars/scan_cast_options.rb +23 -1
- data/lib/polars/schema.rb +1 -1
- data/lib/polars/selectors.rb +8 -8
- data/lib/polars/series.rb +26 -2
- data/lib/polars/string_expr.rb +27 -28
- data/lib/polars/string_name_space.rb +18 -5
- data/lib/polars/utils/convert.rb +2 -2
- data/lib/polars/utils/serde.rb +17 -0
- data/lib/polars/utils/various.rb +4 -0
- data/lib/polars/version.rb +1 -1
- data/lib/polars.rb +6 -0
- metadata +10 -1
data/ext/polars/src/lib.rs
CHANGED
|
@@ -34,9 +34,9 @@ use expr::selector::RbSelector;
|
|
|
34
34
|
use functions::string_cache::RbStringCacheHolder;
|
|
35
35
|
use functions::whenthen::{RbChainedThen, RbChainedWhen, RbThen, RbWhen};
|
|
36
36
|
use interop::arrow::to_ruby::RbArrowArrayStream;
|
|
37
|
-
use lazyframe::RbLazyFrame;
|
|
37
|
+
use lazyframe::{RbLazyFrame, RbOptFlags};
|
|
38
38
|
use lazygroupby::RbLazyGroupBy;
|
|
39
|
-
use magnus::{Ruby,
|
|
39
|
+
use magnus::{Ruby, function, method, prelude::*};
|
|
40
40
|
use series::RbSeries;
|
|
41
41
|
use sql::RbSQLContext;
|
|
42
42
|
|
|
@@ -52,7 +52,7 @@ fn re_escape(pattern: String) -> String {
|
|
|
52
52
|
fn init(ruby: &Ruby) -> RbResult<()> {
|
|
53
53
|
crate::on_startup::register_startup_deps();
|
|
54
54
|
|
|
55
|
-
let module = define_module("Polars")?;
|
|
55
|
+
let module = ruby.define_module("Polars")?;
|
|
56
56
|
|
|
57
57
|
let class = module.define_class("RbBatchedCsv", ruby.class_object())?;
|
|
58
58
|
class.define_singleton_method("new", function!(RbBatchedCsv::new, -1))?;
|
|
@@ -156,9 +156,15 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
|
156
156
|
class.define_method("transpose", method!(RbDataFrame::transpose, 2))?;
|
|
157
157
|
class.define_method("upsample", method!(RbDataFrame::upsample, 4))?;
|
|
158
158
|
class.define_method("to_struct", method!(RbDataFrame::to_struct, 1))?;
|
|
159
|
-
class.define_method("unnest", method!(RbDataFrame::unnest, 1))?;
|
|
160
159
|
class.define_method("clear", method!(RbDataFrame::clear, 0))?;
|
|
161
|
-
class.define_method(
|
|
160
|
+
class.define_method(
|
|
161
|
+
"serialize_binary",
|
|
162
|
+
method!(RbDataFrame::serialize_binary, 1),
|
|
163
|
+
)?;
|
|
164
|
+
class.define_singleton_method(
|
|
165
|
+
"deserialize_binary",
|
|
166
|
+
function!(RbDataFrame::deserialize_binary, 1),
|
|
167
|
+
)?;
|
|
162
168
|
|
|
163
169
|
let class = module.define_class("RbExpr", ruby.class_object())?;
|
|
164
170
|
class.define_method("+", method!(RbExpr::add, 1))?;
|
|
@@ -291,7 +297,6 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
|
291
297
|
class.define_method("cum_min", method!(RbExpr::cum_min, 1))?;
|
|
292
298
|
class.define_method("cum_prod", method!(RbExpr::cum_prod, 1))?;
|
|
293
299
|
class.define_method("product", method!(RbExpr::product, 0))?;
|
|
294
|
-
class.define_method("shrink_dtype", method!(RbExpr::shrink_dtype, 0))?;
|
|
295
300
|
class.define_method("str_to_date", method!(RbExpr::str_to_date, 4))?;
|
|
296
301
|
class.define_method("str_to_datetime", method!(RbExpr::str_to_datetime, 7))?;
|
|
297
302
|
class.define_method("str_to_time", method!(RbExpr::str_to_time, 3))?;
|
|
@@ -359,7 +364,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
|
359
364
|
class.define_method("str_base64_encode", method!(RbExpr::str_base64_encode, 0))?;
|
|
360
365
|
class.define_method("str_base64_decode", method!(RbExpr::str_base64_decode, 1))?;
|
|
361
366
|
class.define_method("str_to_integer", method!(RbExpr::str_to_integer, 3))?;
|
|
362
|
-
class.define_method("str_json_decode", method!(RbExpr::str_json_decode,
|
|
367
|
+
class.define_method("str_json_decode", method!(RbExpr::str_json_decode, 1))?;
|
|
363
368
|
class.define_method("binary_hex_encode", method!(RbExpr::bin_hex_encode, 0))?;
|
|
364
369
|
class.define_method("binary_hex_decode", method!(RbExpr::bin_hex_decode, 1))?;
|
|
365
370
|
class.define_method(
|
|
@@ -426,26 +431,25 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
|
426
431
|
class.define_method("dt_millisecond", method!(RbExpr::dt_millisecond, 0))?;
|
|
427
432
|
class.define_method("dt_microsecond", method!(RbExpr::dt_microsecond, 0))?;
|
|
428
433
|
class.define_method("dt_nanosecond", method!(RbExpr::dt_nanosecond, 0))?;
|
|
429
|
-
class.define_method("dt_total_days", method!(RbExpr::dt_total_days,
|
|
430
|
-
class.define_method("dt_total_hours", method!(RbExpr::dt_total_hours,
|
|
431
|
-
class.define_method("dt_total_minutes", method!(RbExpr::dt_total_minutes,
|
|
432
|
-
class.define_method("dt_total_seconds", method!(RbExpr::dt_total_seconds,
|
|
434
|
+
class.define_method("dt_total_days", method!(RbExpr::dt_total_days, 1))?;
|
|
435
|
+
class.define_method("dt_total_hours", method!(RbExpr::dt_total_hours, 1))?;
|
|
436
|
+
class.define_method("dt_total_minutes", method!(RbExpr::dt_total_minutes, 1))?;
|
|
437
|
+
class.define_method("dt_total_seconds", method!(RbExpr::dt_total_seconds, 1))?;
|
|
433
438
|
class.define_method(
|
|
434
439
|
"dt_total_nanoseconds",
|
|
435
|
-
method!(RbExpr::dt_total_nanoseconds,
|
|
440
|
+
method!(RbExpr::dt_total_nanoseconds, 1),
|
|
436
441
|
)?;
|
|
437
442
|
class.define_method(
|
|
438
443
|
"dt_total_microseconds",
|
|
439
|
-
method!(RbExpr::dt_total_microseconds,
|
|
444
|
+
method!(RbExpr::dt_total_microseconds, 1),
|
|
440
445
|
)?;
|
|
441
446
|
class.define_method(
|
|
442
447
|
"dt_total_milliseconds",
|
|
443
|
-
method!(RbExpr::dt_total_milliseconds,
|
|
448
|
+
method!(RbExpr::dt_total_milliseconds, 1),
|
|
444
449
|
)?;
|
|
445
450
|
class.define_method("dt_timestamp", method!(RbExpr::dt_timestamp, 1))?;
|
|
446
451
|
class.define_method("dt_to_string", method!(RbExpr::dt_to_string, 1))?;
|
|
447
452
|
class.define_method("dt_offset_by", method!(RbExpr::dt_offset_by, 1))?;
|
|
448
|
-
class.define_method("dt_epoch_seconds", method!(RbExpr::dt_epoch_seconds, 0))?;
|
|
449
453
|
class.define_method("dt_with_time_unit", method!(RbExpr::dt_with_time_unit, 1))?;
|
|
450
454
|
class.define_method(
|
|
451
455
|
"dt_convert_time_zone",
|
|
@@ -527,7 +531,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
|
527
531
|
class.define_method("list_eval", method!(RbExpr::list_eval, 1))?;
|
|
528
532
|
class.define_method("list_filter", method!(RbExpr::list_filter, 1))?;
|
|
529
533
|
class.define_method("cumulative_eval", method!(RbExpr::cumulative_eval, 2))?;
|
|
530
|
-
class.define_method("list_to_struct", method!(RbExpr::list_to_struct,
|
|
534
|
+
class.define_method("list_to_struct", method!(RbExpr::list_to_struct, 1))?;
|
|
531
535
|
class.define_method("rank", method!(RbExpr::rank, 3))?;
|
|
532
536
|
class.define_method("diff", method!(RbExpr::diff, 2))?;
|
|
533
537
|
class.define_method("pct_change", method!(RbExpr::pct_change, 1))?;
|
|
@@ -578,6 +582,13 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
|
578
582
|
class.define_method("hist", method!(RbExpr::hist, 4))?;
|
|
579
583
|
class.define_method("into_selector", method!(RbExpr::into_selector, 0))?;
|
|
580
584
|
class.define_singleton_method("new_selector", function!(RbExpr::new_selector, 1))?;
|
|
585
|
+
#[cfg(feature = "serialize_binary")]
|
|
586
|
+
class.define_method("serialize_binary", method!(RbExpr::serialize_binary, 1))?;
|
|
587
|
+
#[cfg(feature = "serialize_binary")]
|
|
588
|
+
class.define_singleton_method(
|
|
589
|
+
"deserialize_binary",
|
|
590
|
+
function!(RbExpr::deserialize_binary, 1),
|
|
591
|
+
)?;
|
|
581
592
|
|
|
582
593
|
// bitwise
|
|
583
594
|
class.define_method("bitwise_count_ones", method!(RbExpr::bitwise_count_ones, 0))?;
|
|
@@ -810,7 +821,20 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
|
810
821
|
class.define_singleton_method("re_escape", function!(re_escape, 1))?;
|
|
811
822
|
|
|
812
823
|
let class = module.define_class("RbLazyFrame", ruby.class_object())?;
|
|
813
|
-
|
|
824
|
+
#[cfg(feature = "serialize_binary")]
|
|
825
|
+
class.define_method(
|
|
826
|
+
"serialize_binary",
|
|
827
|
+
method!(RbLazyFrame::serialize_binary, 1),
|
|
828
|
+
)?;
|
|
829
|
+
#[cfg(feature = "serialize_binary")]
|
|
830
|
+
class.define_singleton_method(
|
|
831
|
+
"deserialize_binary",
|
|
832
|
+
function!(RbLazyFrame::deserialize_binary, 1),
|
|
833
|
+
)?;
|
|
834
|
+
class.define_singleton_method(
|
|
835
|
+
"deserialize_json",
|
|
836
|
+
function!(RbLazyFrame::deserialize_json, 1),
|
|
837
|
+
)?;
|
|
814
838
|
class.define_singleton_method(
|
|
815
839
|
"new_from_ndjson",
|
|
816
840
|
function!(RbLazyFrame::new_from_ndjson, 8),
|
|
@@ -820,7 +844,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
|
820
844
|
"new_from_parquet",
|
|
821
845
|
function!(RbLazyFrame::new_from_parquet, 6),
|
|
822
846
|
)?;
|
|
823
|
-
class.define_singleton_method("new_from_ipc", function!(RbLazyFrame::new_from_ipc,
|
|
847
|
+
class.define_singleton_method("new_from_ipc", function!(RbLazyFrame::new_from_ipc, 3))?;
|
|
824
848
|
class.define_method("write_json", method!(RbLazyFrame::write_json, 1))?;
|
|
825
849
|
class.define_method("describe_plan", method!(RbLazyFrame::describe_plan, 0))?;
|
|
826
850
|
class.define_method(
|
|
@@ -887,7 +911,7 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
|
887
911
|
class.define_method("cast_all", method!(RbLazyFrame::cast_all, 2))?;
|
|
888
912
|
class.define_method("_clone", method!(RbLazyFrame::clone, 0))?;
|
|
889
913
|
class.define_method("collect_schema", method!(RbLazyFrame::collect_schema, 0))?;
|
|
890
|
-
class.define_method("unnest", method!(RbLazyFrame::unnest,
|
|
914
|
+
class.define_method("unnest", method!(RbLazyFrame::unnest, 2))?;
|
|
891
915
|
class.define_method("count", method!(RbLazyFrame::count, 0))?;
|
|
892
916
|
class.define_method("merge_sorted", method!(RbLazyFrame::merge_sorted, 2))?;
|
|
893
917
|
|
|
@@ -902,10 +926,12 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
|
902
926
|
class.define_singleton_method("new_opt_u16", function!(RbSeries::new_opt_u16, 3))?;
|
|
903
927
|
class.define_singleton_method("new_opt_u32", function!(RbSeries::new_opt_u32, 3))?;
|
|
904
928
|
class.define_singleton_method("new_opt_u64", function!(RbSeries::new_opt_u64, 3))?;
|
|
929
|
+
class.define_singleton_method("new_opt_u128", function!(RbSeries::new_opt_u128, 3))?;
|
|
905
930
|
class.define_singleton_method("new_opt_i8", function!(RbSeries::new_opt_i8, 3))?;
|
|
906
931
|
class.define_singleton_method("new_opt_i16", function!(RbSeries::new_opt_i16, 3))?;
|
|
907
932
|
class.define_singleton_method("new_opt_i32", function!(RbSeries::new_opt_i32, 3))?;
|
|
908
933
|
class.define_singleton_method("new_opt_i64", function!(RbSeries::new_opt_i64, 3))?;
|
|
934
|
+
class.define_singleton_method("new_opt_i128", function!(RbSeries::new_opt_i128, 3))?;
|
|
909
935
|
class.define_singleton_method("new_opt_f32", function!(RbSeries::new_opt_f32, 3))?;
|
|
910
936
|
class.define_singleton_method("new_opt_f64", function!(RbSeries::new_opt_f64, 3))?;
|
|
911
937
|
class.define_singleton_method(
|
|
@@ -1002,6 +1028,12 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
|
1002
1028
|
class.define_method("lt", method!(RbSeries::lt, 1))?;
|
|
1003
1029
|
class.define_method("lt_eq", method!(RbSeries::lt_eq, 1))?;
|
|
1004
1030
|
class.define_method("not_", method!(RbSeries::not_, 0))?;
|
|
1031
|
+
class.define_method("shrink_dtype", method!(RbSeries::shrink_dtype, 0))?;
|
|
1032
|
+
class.define_method(
|
|
1033
|
+
"str_to_decimal_infer",
|
|
1034
|
+
method!(RbSeries::str_to_decimal_infer, 1),
|
|
1035
|
+
)?;
|
|
1036
|
+
class.define_method("str_json_decode", method!(RbSeries::str_json_decode, 1))?;
|
|
1005
1037
|
class.define_method("to_s", method!(RbSeries::to_s, 0))?;
|
|
1006
1038
|
class.define_method("len", method!(RbSeries::len, 0))?;
|
|
1007
1039
|
class.define_method("to_a", method!(RbSeries::to_a, 0))?;
|
|
@@ -1298,5 +1330,98 @@ fn init(ruby: &Ruby) -> RbResult<()> {
|
|
|
1298
1330
|
class.define_singleton_method("all", function!(RbSelector::all, 0))?;
|
|
1299
1331
|
class.define_method("_hash", method!(RbSelector::hash, 0))?;
|
|
1300
1332
|
|
|
1333
|
+
// opt flags
|
|
1334
|
+
let class = module.define_class("RbOptFlags", ruby.class_object())?;
|
|
1335
|
+
class.define_singleton_method("empty", function!(RbOptFlags::empty, 0))?;
|
|
1336
|
+
class.define_singleton_method("default", function!(RbOptFlags::default, 0))?;
|
|
1337
|
+
class.define_method("no_optimizations", method!(RbOptFlags::no_optimizations, 0))?;
|
|
1338
|
+
class.define_method("copy", method!(RbOptFlags::copy, 0))?;
|
|
1339
|
+
class.define_method(
|
|
1340
|
+
"get_type_coercion",
|
|
1341
|
+
method!(RbOptFlags::get_type_coercion, 0),
|
|
1342
|
+
)?;
|
|
1343
|
+
class.define_method(
|
|
1344
|
+
"set_type_coercion",
|
|
1345
|
+
method!(RbOptFlags::set_type_coercion, 1),
|
|
1346
|
+
)?;
|
|
1347
|
+
class.define_method("get_type_check", method!(RbOptFlags::get_type_check, 0))?;
|
|
1348
|
+
class.define_method("set_type_check", method!(RbOptFlags::set_type_check, 1))?;
|
|
1349
|
+
class.define_method(
|
|
1350
|
+
"get_projection_pushdown",
|
|
1351
|
+
method!(RbOptFlags::get_projection_pushdown, 0),
|
|
1352
|
+
)?;
|
|
1353
|
+
class.define_method(
|
|
1354
|
+
"set_projection_pushdown",
|
|
1355
|
+
method!(RbOptFlags::set_projection_pushdown, 1),
|
|
1356
|
+
)?;
|
|
1357
|
+
class.define_method(
|
|
1358
|
+
"get_predicate_pushdown",
|
|
1359
|
+
method!(RbOptFlags::get_predicate_pushdown, 0),
|
|
1360
|
+
)?;
|
|
1361
|
+
class.define_method(
|
|
1362
|
+
"set_predicate_pushdown",
|
|
1363
|
+
method!(RbOptFlags::set_predicate_pushdown, 1),
|
|
1364
|
+
)?;
|
|
1365
|
+
class.define_method(
|
|
1366
|
+
"get_cluster_with_columns",
|
|
1367
|
+
method!(RbOptFlags::get_cluster_with_columns, 0),
|
|
1368
|
+
)?;
|
|
1369
|
+
class.define_method(
|
|
1370
|
+
"set_cluster_with_columns",
|
|
1371
|
+
method!(RbOptFlags::set_cluster_with_columns, 1),
|
|
1372
|
+
)?;
|
|
1373
|
+
class.define_method(
|
|
1374
|
+
"get_simplify_expression",
|
|
1375
|
+
method!(RbOptFlags::get_simplify_expression, 0),
|
|
1376
|
+
)?;
|
|
1377
|
+
class.define_method(
|
|
1378
|
+
"set_simplify_expression",
|
|
1379
|
+
method!(RbOptFlags::set_simplify_expression, 1),
|
|
1380
|
+
)?;
|
|
1381
|
+
class.define_method(
|
|
1382
|
+
"get_slice_pushdown",
|
|
1383
|
+
method!(RbOptFlags::get_slice_pushdown, 0),
|
|
1384
|
+
)?;
|
|
1385
|
+
class.define_method(
|
|
1386
|
+
"set_slice_pushdown",
|
|
1387
|
+
method!(RbOptFlags::set_slice_pushdown, 1),
|
|
1388
|
+
)?;
|
|
1389
|
+
class.define_method(
|
|
1390
|
+
"get_comm_subplan_elim",
|
|
1391
|
+
method!(RbOptFlags::get_comm_subplan_elim, 0),
|
|
1392
|
+
)?;
|
|
1393
|
+
class.define_method(
|
|
1394
|
+
"set_comm_subplan_elim",
|
|
1395
|
+
method!(RbOptFlags::set_comm_subplan_elim, 1),
|
|
1396
|
+
)?;
|
|
1397
|
+
class.define_method(
|
|
1398
|
+
"get_comm_subexpr_elim",
|
|
1399
|
+
method!(RbOptFlags::get_comm_subexpr_elim, 0),
|
|
1400
|
+
)?;
|
|
1401
|
+
class.define_method(
|
|
1402
|
+
"set_comm_subexpr_elim",
|
|
1403
|
+
method!(RbOptFlags::set_comm_subexpr_elim, 1),
|
|
1404
|
+
)?;
|
|
1405
|
+
class.define_method(
|
|
1406
|
+
"get_check_order_observe",
|
|
1407
|
+
method!(RbOptFlags::get_check_order_observe, 0),
|
|
1408
|
+
)?;
|
|
1409
|
+
class.define_method(
|
|
1410
|
+
"set_check_order_observe",
|
|
1411
|
+
method!(RbOptFlags::set_check_order_observe, 1),
|
|
1412
|
+
)?;
|
|
1413
|
+
class.define_method(
|
|
1414
|
+
"get_fast_projection",
|
|
1415
|
+
method!(RbOptFlags::get_fast_projection, 0),
|
|
1416
|
+
)?;
|
|
1417
|
+
class.define_method(
|
|
1418
|
+
"set_fast_projection",
|
|
1419
|
+
method!(RbOptFlags::set_fast_projection, 1),
|
|
1420
|
+
)?;
|
|
1421
|
+
class.define_method("get_eager", method!(RbOptFlags::get_eager, 0))?;
|
|
1422
|
+
class.define_method("set_eager", method!(RbOptFlags::set_eager, 1))?;
|
|
1423
|
+
class.define_method("get_streaming", method!(RbOptFlags::get_streaming, 0))?;
|
|
1424
|
+
class.define_method("set_streaming", method!(RbOptFlags::set_streaming, 1))?;
|
|
1425
|
+
|
|
1301
1426
|
Ok(())
|
|
1302
1427
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use magnus::{IntoValue, RArray, TryConvert, Value,
|
|
1
|
+
use magnus::{IntoValue, RArray, Ruby, TryConvert, Value, prelude::*, typed_data::Obj};
|
|
2
2
|
use polars::prelude::*;
|
|
3
3
|
use polars_core::frame::row::{Row, rows_to_schema_first_non_null};
|
|
4
4
|
use polars_core::series::SeriesIter;
|
|
@@ -25,32 +25,35 @@ pub fn apply_lambda_unknown<'a>(
|
|
|
25
25
|
lambda: Value,
|
|
26
26
|
inference_size: usize,
|
|
27
27
|
) -> RbResult<(Value, bool)> {
|
|
28
|
+
let ruby = Ruby::get_with(lambda);
|
|
28
29
|
let mut null_count = 0;
|
|
29
30
|
let mut iters = get_iters(df);
|
|
30
31
|
|
|
31
32
|
for _ in 0..df.height() {
|
|
32
33
|
let iter = iters.iter_mut().map(|it| Wrap(it.next().unwrap()));
|
|
33
|
-
let arg = (
|
|
34
|
+
let arg = (ruby.ary_from_iter(iter),);
|
|
34
35
|
let out: Value = lambda.funcall("call", arg)?;
|
|
35
36
|
|
|
36
37
|
if out.is_nil() {
|
|
37
38
|
null_count += 1;
|
|
38
39
|
continue;
|
|
39
|
-
} else if out.is_kind_of(
|
|
40
|
+
} else if out.is_kind_of(ruby.class_true_class())
|
|
41
|
+
|| out.is_kind_of(ruby.class_false_class())
|
|
42
|
+
{
|
|
40
43
|
let first_value = bool::try_convert(out).ok();
|
|
41
44
|
return Ok((
|
|
42
|
-
|
|
45
|
+
ruby.obj_wrap(RbSeries::new(
|
|
43
46
|
apply_lambda_with_bool_out_type(df, lambda, null_count, first_value)
|
|
44
47
|
.into_series(),
|
|
45
48
|
))
|
|
46
49
|
.as_value(),
|
|
47
50
|
false,
|
|
48
51
|
));
|
|
49
|
-
} else if out.is_kind_of(
|
|
52
|
+
} else if out.is_kind_of(ruby.class_float()) {
|
|
50
53
|
let first_value = f64::try_convert(out).ok();
|
|
51
54
|
|
|
52
55
|
return Ok((
|
|
53
|
-
|
|
56
|
+
ruby.obj_wrap(RbSeries::new(
|
|
54
57
|
apply_lambda_with_primitive_out_type::<Float64Type>(
|
|
55
58
|
df,
|
|
56
59
|
lambda,
|
|
@@ -62,10 +65,10 @@ pub fn apply_lambda_unknown<'a>(
|
|
|
62
65
|
.as_value(),
|
|
63
66
|
false,
|
|
64
67
|
));
|
|
65
|
-
} else if out.is_kind_of(
|
|
68
|
+
} else if out.is_kind_of(ruby.class_integer()) {
|
|
66
69
|
let first_value = i64::try_convert(out).ok();
|
|
67
70
|
return Ok((
|
|
68
|
-
|
|
71
|
+
ruby.obj_wrap(RbSeries::new(
|
|
69
72
|
apply_lambda_with_primitive_out_type::<Int64Type>(
|
|
70
73
|
df,
|
|
71
74
|
lambda,
|
|
@@ -77,7 +80,7 @@ pub fn apply_lambda_unknown<'a>(
|
|
|
77
80
|
.as_value(),
|
|
78
81
|
false,
|
|
79
82
|
));
|
|
80
|
-
// } else if out.is_kind_of(
|
|
83
|
+
// } else if out.is_kind_of(ruby.class_string()) {
|
|
81
84
|
// let first_value = String::try_convert(out).ok();
|
|
82
85
|
// return Ok((
|
|
83
86
|
// RbSeries::new(
|
|
@@ -92,7 +95,7 @@ pub fn apply_lambda_unknown<'a>(
|
|
|
92
95
|
let series = rb_rbseries.series.borrow();
|
|
93
96
|
let dt = series.dtype();
|
|
94
97
|
return Ok((
|
|
95
|
-
|
|
98
|
+
ruby.obj_wrap(RbSeries::new(
|
|
96
99
|
apply_lambda_with_list_out_type(df, lambda, null_count, Some(&series), dt)?
|
|
97
100
|
.into_series(),
|
|
98
101
|
))
|
|
@@ -102,7 +105,7 @@ pub fn apply_lambda_unknown<'a>(
|
|
|
102
105
|
} else if Wrap::<Row<'a>>::try_convert(out).is_ok() {
|
|
103
106
|
let first_value = Wrap::<Row<'a>>::try_convert(out).unwrap().0;
|
|
104
107
|
return Ok((
|
|
105
|
-
|
|
108
|
+
ruby.obj_wrap(RbDataFrame::from(
|
|
106
109
|
apply_lambda_with_rows_output(
|
|
107
110
|
df,
|
|
108
111
|
lambda,
|
|
@@ -115,7 +118,7 @@ pub fn apply_lambda_unknown<'a>(
|
|
|
115
118
|
.as_value(),
|
|
116
119
|
true,
|
|
117
120
|
));
|
|
118
|
-
} else if out.is_kind_of(
|
|
121
|
+
} else if out.is_kind_of(ruby.class_array()) {
|
|
119
122
|
return Err(RbPolarsErr::Other(
|
|
120
123
|
"A list output type is invalid. Do you mean to create polars List Series?\
|
|
121
124
|
Then return a Series object."
|
|
@@ -141,7 +144,7 @@ where
|
|
|
141
144
|
let mut iters = get_iters_skip(df, init_null_count + skip);
|
|
142
145
|
((init_null_count + skip)..df.height()).map(move |_| {
|
|
143
146
|
let iter = iters.iter_mut().map(|it| Wrap(it.next().unwrap()));
|
|
144
|
-
let tpl = (
|
|
147
|
+
let tpl = (Ruby::get_with(lambda).ary_from_iter(iter),);
|
|
145
148
|
match lambda.funcall::<_, _, Value>("call", tpl) {
|
|
146
149
|
Ok(val) => T::try_convert(val).ok(),
|
|
147
150
|
Err(e) => panic!("ruby function failed {e}"),
|
|
@@ -237,7 +240,7 @@ pub fn apply_lambda_with_list_out_type(
|
|
|
237
240
|
let mut iters = get_iters_skip(df, init_null_count + skip);
|
|
238
241
|
let iter = ((init_null_count + skip)..df.height()).map(|_| {
|
|
239
242
|
let iter = iters.iter_mut().map(|it| Wrap(it.next().unwrap()));
|
|
240
|
-
let tpl = (
|
|
243
|
+
let tpl = (Ruby::get_with(lambda).ary_from_iter(iter),);
|
|
241
244
|
match lambda.funcall::<_, _, Value>("call", tpl) {
|
|
242
245
|
Ok(val) => match val.funcall::<_, _, Value>("_s", ()) {
|
|
243
246
|
Ok(val) => Obj::<RbSeries>::try_convert(val)
|
|
@@ -281,7 +284,7 @@ pub fn apply_lambda_with_rows_output<'a>(
|
|
|
281
284
|
let mut iters = get_iters_skip(df, init_null_count + skip);
|
|
282
285
|
let mut row_iter = ((init_null_count + skip)..df.height()).map(|_| {
|
|
283
286
|
let iter = iters.iter_mut().map(|it| Wrap(it.next().unwrap()));
|
|
284
|
-
let tpl = (
|
|
287
|
+
let tpl = (Ruby::get_with(lambda).ary_from_iter(iter),);
|
|
285
288
|
match lambda.funcall::<_, _, Value>("call", tpl) {
|
|
286
289
|
Ok(val) => {
|
|
287
290
|
match RArray::try_convert(val).ok() {
|
data/ext/polars/src/map/lazy.rs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
use magnus::{
|
|
1
|
+
use magnus::{Ruby, Value, prelude::*};
|
|
2
2
|
use polars::prelude::*;
|
|
3
3
|
|
|
4
4
|
use crate::rb_modules::*;
|
|
5
5
|
use crate::{RbExpr, RbSeries, Wrap};
|
|
6
6
|
|
|
7
7
|
fn to_series(v: Value, name: &str) -> PolarsResult<Series> {
|
|
8
|
+
let ruby = Ruby::get_with(v);
|
|
8
9
|
let rb_rbseries = match v.funcall("_s", ()) {
|
|
9
10
|
Ok(s) => s,
|
|
10
11
|
// the lambda did not return a series, we try to create a new Ruby Series
|
|
11
12
|
_ => {
|
|
12
|
-
let data =
|
|
13
|
+
let data = ruby.ary_new();
|
|
13
14
|
data.push(v).unwrap();
|
|
14
|
-
let res =
|
|
15
|
+
let res = pl_series().funcall::<_, _, Value>("new", (name.to_string(), data));
|
|
15
16
|
|
|
16
17
|
match res {
|
|
17
18
|
Ok(ruby_s) => ruby_s.funcall::<_, _, &RbSeries>("_s", ()).unwrap(),
|
|
@@ -34,8 +35,8 @@ pub fn binary_lambda(lambda: Value, a: Series, b: Series) -> PolarsResult<Option
|
|
|
34
35
|
let rbseries_b = RbSeries::new(b);
|
|
35
36
|
|
|
36
37
|
// Wrap this RbSeries object in the Ruby side Series wrapper
|
|
37
|
-
let ruby_series_wrapper_a: Value =
|
|
38
|
-
let ruby_series_wrapper_b: Value =
|
|
38
|
+
let ruby_series_wrapper_a: Value = pl_utils().funcall("wrap_s", (rbseries_a,)).unwrap();
|
|
39
|
+
let ruby_series_wrapper_b: Value = pl_utils().funcall("wrap_s", (rbseries_b,)).unwrap();
|
|
39
40
|
|
|
40
41
|
// call the lambda and get a Ruby side Series wrapper
|
|
41
42
|
let result_series_wrapper: Value =
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use magnus::{IntoValue, TryConvert, Value,
|
|
1
|
+
use magnus::{IntoValue, Ruby, TryConvert, Value, prelude::*, typed_data::Obj};
|
|
2
2
|
use polars::prelude::*;
|
|
3
3
|
|
|
4
4
|
use super::*;
|
|
@@ -12,12 +12,13 @@ fn infer_and_finish<'a, A: ApplyLambda<'a>>(
|
|
|
12
12
|
out: Value,
|
|
13
13
|
null_count: usize,
|
|
14
14
|
) -> RbResult<RbSeries> {
|
|
15
|
-
|
|
15
|
+
let ruby = Ruby::get_with(lambda);
|
|
16
|
+
if out.is_kind_of(ruby.class_true_class()) || out.is_kind_of(ruby.class_false_class()) {
|
|
16
17
|
let first_value = bool::try_convert(out).unwrap();
|
|
17
18
|
applyer
|
|
18
19
|
.apply_lambda_with_bool_out_type(lambda, null_count, Some(first_value))
|
|
19
20
|
.map(|ca| ca.into_series().into())
|
|
20
|
-
} else if out.is_kind_of(
|
|
21
|
+
} else if out.is_kind_of(ruby.class_float()) {
|
|
21
22
|
let first_value = f64::try_convert(out).unwrap();
|
|
22
23
|
applyer
|
|
23
24
|
.apply_lambda_with_primitive_out_type::<Float64Type>(
|
|
@@ -26,7 +27,7 @@ fn infer_and_finish<'a, A: ApplyLambda<'a>>(
|
|
|
26
27
|
Some(first_value),
|
|
27
28
|
)
|
|
28
29
|
.map(|ca| ca.into_series().into())
|
|
29
|
-
} else if out.is_kind_of(
|
|
30
|
+
} else if out.is_kind_of(ruby.class_string()) {
|
|
30
31
|
let first_value = String::try_convert(out).unwrap();
|
|
31
32
|
applyer
|
|
32
33
|
.apply_lambda_with_utf8_out_type(lambda, null_count, Some(first_value.as_str()))
|
|
@@ -38,9 +39,9 @@ fn infer_and_finish<'a, A: ApplyLambda<'a>>(
|
|
|
38
39
|
applyer
|
|
39
40
|
.apply_lambda_with_list_out_type(lambda, null_count, &series, dt)
|
|
40
41
|
.map(|ca| ca.into_series().into())
|
|
41
|
-
} else if out.is_kind_of(
|
|
42
|
+
} else if out.is_kind_of(ruby.class_array()) {
|
|
42
43
|
todo!()
|
|
43
|
-
} else if out.is_kind_of(
|
|
44
|
+
} else if out.is_kind_of(ruby.class_hash()) {
|
|
44
45
|
let first = Wrap::<AnyValue<'_>>::try_convert(out)?;
|
|
45
46
|
applyer.apply_into_struct(lambda, null_count, first.0)
|
|
46
47
|
}
|
|
@@ -2,15 +2,23 @@ use std::any::Any;
|
|
|
2
2
|
use std::sync::Arc;
|
|
3
3
|
use std::sync::OnceLock;
|
|
4
4
|
|
|
5
|
-
use magnus::IntoValue;
|
|
5
|
+
use magnus::{IntoValue, Ruby, Value, prelude::*};
|
|
6
6
|
use polars::prelude::*;
|
|
7
7
|
use polars_core::chunked_array::object::builder::ObjectChunkedBuilder;
|
|
8
8
|
use polars_core::chunked_array::object::registry;
|
|
9
9
|
use polars_core::chunked_array::object::registry::AnonymousObjectBuilder;
|
|
10
10
|
use polars_core::prelude::AnyValue;
|
|
11
|
+
use polars_error::PolarsWarning;
|
|
11
12
|
|
|
12
13
|
use crate::Wrap;
|
|
13
14
|
use crate::prelude::ObjectValue;
|
|
15
|
+
use crate::rb_modules::pl_utils;
|
|
16
|
+
|
|
17
|
+
fn warning_function(msg: &str, _warning: PolarsWarning) {
|
|
18
|
+
if let Err(e) = pl_utils().funcall::<_, _, Value>("_polars_warn", (msg.to_string(),)) {
|
|
19
|
+
eprintln!("{e}")
|
|
20
|
+
}
|
|
21
|
+
}
|
|
14
22
|
|
|
15
23
|
static POLARS_REGISTRY_INIT_LOCK: OnceLock<()> = OnceLock::new();
|
|
16
24
|
|
|
@@ -23,12 +31,12 @@ pub(crate) fn register_startup_deps() {
|
|
|
23
31
|
|
|
24
32
|
let object_converter = Arc::new(|av: AnyValue| {
|
|
25
33
|
let object = ObjectValue {
|
|
26
|
-
inner: Wrap(av).
|
|
34
|
+
inner: Wrap(av).into_value_with(&Ruby::get().unwrap()).into(),
|
|
27
35
|
};
|
|
28
36
|
Box::new(object) as Box<dyn Any>
|
|
29
37
|
});
|
|
30
38
|
let rbobject_converter = Arc::new(|av: AnyValue| {
|
|
31
|
-
let object = Wrap(av).
|
|
39
|
+
let object = Wrap(av).into_value_with(&Ruby::get().unwrap());
|
|
32
40
|
Box::new(object) as Box<dyn Any>
|
|
33
41
|
});
|
|
34
42
|
|
|
@@ -40,8 +48,7 @@ pub(crate) fn register_startup_deps() {
|
|
|
40
48
|
rbobject_converter,
|
|
41
49
|
physical_dtype,
|
|
42
50
|
);
|
|
43
|
-
// TODO
|
|
44
51
|
// Register warning function for `polars_warn!`.
|
|
45
|
-
|
|
52
|
+
polars_error::set_warning_function(warning_function);
|
|
46
53
|
});
|
|
47
54
|
}
|
|
@@ -9,13 +9,13 @@ pub(crate) fn polars() -> RModule {
|
|
|
9
9
|
static SERIES: Lazy<RClass> =
|
|
10
10
|
Lazy::new(|ruby| ruby.get_inner(&POLARS).const_get("Series").unwrap());
|
|
11
11
|
|
|
12
|
-
pub(crate) fn
|
|
12
|
+
pub(crate) fn pl_series() -> RClass {
|
|
13
13
|
Ruby::get().unwrap().get_inner(&SERIES)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
static UTILS: Lazy<RModule> = Lazy::new(|ruby| ruby.get_inner(&POLARS).const_get("Utils").unwrap());
|
|
17
17
|
|
|
18
|
-
pub(crate) fn
|
|
18
|
+
pub(crate) fn pl_utils() -> RModule {
|
|
19
19
|
Ruby::get().unwrap().get_inner(&UTILS)
|
|
20
20
|
}
|
|
21
21
|
|