polars-df 0.23.0 → 0.24.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 +127 -1
- data/Cargo.lock +72 -58
- data/README.md +31 -27
- data/ext/polars/Cargo.toml +15 -6
- data/ext/polars/src/batched_csv.rs +35 -39
- data/ext/polars/src/c_api/allocator.rs +7 -0
- data/ext/polars/src/c_api/mod.rs +1 -0
- data/ext/polars/src/catalog/unity.rs +123 -101
- data/ext/polars/src/conversion/any_value.rs +13 -17
- data/ext/polars/src/conversion/chunked_array.rs +5 -5
- data/ext/polars/src/conversion/datetime.rs +3 -2
- data/ext/polars/src/conversion/mod.rs +50 -45
- data/ext/polars/src/dataframe/export.rs +13 -13
- data/ext/polars/src/dataframe/general.rs +223 -223
- data/ext/polars/src/dataframe/io.rs +27 -141
- data/ext/polars/src/dataframe/mod.rs +13 -5
- data/ext/polars/src/dataframe/serde.rs +1 -1
- data/ext/polars/src/error.rs +44 -7
- data/ext/polars/src/exceptions.rs +45 -12
- data/ext/polars/src/expr/array.rs +12 -0
- data/ext/polars/src/expr/datatype.rs +2 -2
- data/ext/polars/src/expr/datetime.rs +4 -5
- data/ext/polars/src/expr/general.rs +49 -13
- data/ext/polars/src/expr/list.rs +4 -0
- data/ext/polars/src/expr/meta.rs +8 -3
- data/ext/polars/src/expr/mod.rs +22 -6
- data/ext/polars/src/expr/name.rs +19 -8
- data/ext/polars/src/expr/rolling.rs +50 -1
- data/ext/polars/src/expr/string.rs +0 -1
- data/ext/polars/src/expr/struct.rs +7 -2
- data/ext/polars/src/file.rs +136 -103
- data/ext/polars/src/functions/aggregation.rs +9 -8
- data/ext/polars/src/functions/io.rs +81 -10
- data/ext/polars/src/functions/lazy.rs +95 -21
- data/ext/polars/src/functions/mod.rs +2 -0
- data/ext/polars/src/functions/range.rs +19 -3
- data/ext/polars/src/functions/strings.rs +6 -0
- data/ext/polars/src/functions/utils.rs +6 -0
- data/ext/polars/src/interop/arrow/mod.rs +50 -1
- data/ext/polars/src/interop/arrow/{to_ruby.rs → to_rb.rs} +30 -0
- data/ext/polars/src/interop/arrow/to_rust.rs +43 -0
- data/ext/polars/src/interop/numo/to_numo_df.rs +1 -1
- data/ext/polars/src/interop/numo/to_numo_series.rs +1 -1
- data/ext/polars/src/lazyframe/exitable.rs +39 -0
- data/ext/polars/src/lazyframe/general.rs +340 -236
- data/ext/polars/src/lazyframe/mod.rs +46 -10
- data/ext/polars/src/lazyframe/optflags.rs +5 -4
- data/ext/polars/src/lazyframe/serde.rs +11 -3
- data/ext/polars/src/lazyframe/sink.rs +10 -5
- data/ext/polars/src/lazygroupby.rs +6 -7
- data/ext/polars/src/lib.rs +141 -76
- data/ext/polars/src/map/dataframe.rs +12 -12
- data/ext/polars/src/map/lazy.rs +7 -5
- data/ext/polars/src/map/mod.rs +15 -8
- data/ext/polars/src/map/series.rs +3 -3
- data/ext/polars/src/on_startup.rs +16 -8
- data/ext/polars/src/prelude.rs +1 -0
- data/ext/polars/src/rb_modules.rs +19 -49
- data/ext/polars/src/series/aggregation.rs +79 -140
- data/ext/polars/src/series/arithmetic.rs +16 -22
- data/ext/polars/src/series/comparison.rs +101 -222
- data/ext/polars/src/series/construction.rs +17 -18
- data/ext/polars/src/series/export.rs +1 -1
- data/ext/polars/src/series/general.rs +254 -289
- data/ext/polars/src/series/import.rs +17 -0
- data/ext/polars/src/series/map.rs +178 -160
- data/ext/polars/src/series/mod.rs +28 -12
- data/ext/polars/src/series/scatter.rs +12 -9
- data/ext/polars/src/sql.rs +16 -9
- data/ext/polars/src/testing/frame.rs +31 -0
- data/ext/polars/src/testing/mod.rs +5 -0
- data/ext/polars/src/testing/series.rs +31 -0
- data/ext/polars/src/timeout.rs +105 -0
- data/ext/polars/src/utils.rs +159 -1
- data/lib/polars/array_expr.rb +81 -12
- data/lib/polars/array_name_space.rb +74 -7
- data/lib/polars/batched_csv_reader.rb +21 -21
- data/lib/polars/binary_name_space.rb +1 -1
- data/lib/polars/cat_expr.rb +7 -7
- data/lib/polars/config.rb +1 -1
- data/lib/polars/convert.rb +189 -34
- data/lib/polars/data_frame.rb +1066 -831
- data/lib/polars/data_frame_plot.rb +173 -0
- data/lib/polars/data_type_group.rb +1 -0
- data/lib/polars/data_types.rb +31 -12
- data/lib/polars/date_time_expr.rb +51 -69
- data/lib/polars/date_time_name_space.rb +80 -112
- data/lib/polars/dynamic_group_by.rb +7 -7
- data/lib/polars/exceptions.rb +50 -10
- data/lib/polars/expr.rb +470 -517
- data/lib/polars/functions/aggregation/horizontal.rb +0 -1
- data/lib/polars/functions/aggregation/vertical.rb +2 -3
- data/lib/polars/functions/as_datatype.rb +290 -8
- data/lib/polars/functions/eager.rb +204 -10
- data/lib/polars/functions/escape_regex.rb +21 -0
- data/lib/polars/functions/lazy.rb +409 -169
- data/lib/polars/functions/lit.rb +17 -1
- data/lib/polars/functions/range/int_range.rb +74 -2
- data/lib/polars/functions/range/linear_space.rb +77 -0
- data/lib/polars/functions/range/time_range.rb +1 -1
- data/lib/polars/functions/repeat.rb +3 -12
- data/lib/polars/functions/whenthen.rb +2 -2
- data/lib/polars/group_by.rb +72 -20
- data/lib/polars/iceberg_dataset.rb +1 -6
- data/lib/polars/in_process_query.rb +37 -0
- data/lib/polars/io/cloud.rb +18 -0
- data/lib/polars/io/csv.rb +265 -126
- data/lib/polars/io/database.rb +0 -1
- data/lib/polars/io/delta.rb +15 -7
- data/lib/polars/io/ipc.rb +24 -17
- data/lib/polars/io/ndjson.rb +161 -24
- data/lib/polars/io/parquet.rb +101 -38
- data/lib/polars/lazy_frame.rb +849 -558
- data/lib/polars/lazy_group_by.rb +327 -2
- data/lib/polars/list_expr.rb +94 -16
- data/lib/polars/list_name_space.rb +88 -24
- data/lib/polars/meta_expr.rb +42 -1
- data/lib/polars/name_expr.rb +41 -4
- data/lib/polars/query_opt_flags.rb +198 -2
- data/lib/polars/rolling_group_by.rb +3 -3
- data/lib/polars/schema.rb +21 -3
- data/lib/polars/selector.rb +37 -2
- data/lib/polars/selectors.rb +45 -9
- data/lib/polars/series.rb +1156 -728
- data/lib/polars/series_plot.rb +72 -0
- data/lib/polars/slice.rb +1 -1
- data/lib/polars/sql_context.rb +11 -4
- data/lib/polars/string_expr.rb +59 -68
- data/lib/polars/string_name_space.rb +51 -87
- data/lib/polars/struct_expr.rb +36 -18
- data/lib/polars/testing.rb +24 -273
- data/lib/polars/utils/constants.rb +2 -0
- data/lib/polars/utils/construction/data_frame.rb +410 -0
- data/lib/polars/utils/construction/series.rb +364 -0
- data/lib/polars/utils/construction/utils.rb +9 -0
- data/lib/polars/utils/deprecation.rb +11 -0
- data/lib/polars/utils/serde.rb +8 -3
- data/lib/polars/utils/unstable.rb +19 -0
- data/lib/polars/utils/various.rb +59 -0
- data/lib/polars/utils.rb +46 -47
- data/lib/polars/version.rb +1 -1
- data/lib/polars.rb +47 -1
- metadata +25 -6
- data/ext/polars/src/allocator.rs +0 -13
- data/lib/polars/plot.rb +0 -109
data/ext/polars/src/map/lazy.rs
CHANGED
|
@@ -12,7 +12,7 @@ fn to_series(v: Value, name: &str) -> PolarsResult<Series> {
|
|
|
12
12
|
_ => {
|
|
13
13
|
let data = ruby.ary_new();
|
|
14
14
|
data.push(v).unwrap();
|
|
15
|
-
let res = pl_series().funcall::<_, _, Value>("new", (name.to_string(), data));
|
|
15
|
+
let res = pl_series(&ruby).funcall::<_, _, Value>("new", (name.to_string(), data));
|
|
16
16
|
|
|
17
17
|
match res {
|
|
18
18
|
Ok(ruby_s) => ruby_s.funcall::<_, _, &RbSeries>("_s", ()).unwrap(),
|
|
@@ -26,17 +26,19 @@ fn to_series(v: Value, name: &str) -> PolarsResult<Series> {
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
// Finally get the actual Series
|
|
29
|
-
Ok(rb_rbseries.series.
|
|
29
|
+
Ok(rb_rbseries.series.read().clone())
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
pub fn binary_lambda(lambda: Value, a: Series, b: Series) -> PolarsResult<Option<Series>> {
|
|
33
|
+
let ruby = Ruby::get_with(lambda);
|
|
34
|
+
|
|
33
35
|
// create a RbSeries struct/object for Ruby
|
|
34
36
|
let rbseries_a = RbSeries::new(a);
|
|
35
37
|
let rbseries_b = RbSeries::new(b);
|
|
36
38
|
|
|
37
39
|
// Wrap this RbSeries object in the Ruby side Series wrapper
|
|
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();
|
|
40
|
+
let ruby_series_wrapper_a: Value = pl_utils(&ruby).funcall("wrap_s", (rbseries_a,)).unwrap();
|
|
41
|
+
let ruby_series_wrapper_b: Value = pl_utils(&ruby).funcall("wrap_s", (rbseries_b,)).unwrap();
|
|
40
42
|
|
|
41
43
|
// call the lambda and get a Ruby side Series wrapper
|
|
42
44
|
let result_series_wrapper: Value =
|
|
@@ -64,7 +66,7 @@ pub fn binary_lambda(lambda: Value, a: Series, b: Series) -> PolarsResult<Option
|
|
|
64
66
|
};
|
|
65
67
|
|
|
66
68
|
// Finally get the actual Series
|
|
67
|
-
let binding = rbseries.series.
|
|
69
|
+
let binding = rbseries.series.read();
|
|
68
70
|
Ok(Some(binding.clone()))
|
|
69
71
|
}
|
|
70
72
|
|
data/ext/polars/src/map/mod.rs
CHANGED
|
@@ -2,13 +2,14 @@ pub mod dataframe;
|
|
|
2
2
|
pub mod lazy;
|
|
3
3
|
pub mod series;
|
|
4
4
|
|
|
5
|
-
use magnus::{RHash, Value, prelude::*};
|
|
5
|
+
use magnus::{RHash, Ruby, Value, prelude::*};
|
|
6
6
|
use polars::chunked_array::builder::get_list_builder;
|
|
7
7
|
use polars::prelude::*;
|
|
8
8
|
use polars_core::POOL;
|
|
9
9
|
use polars_core::utils::CustomIterTools;
|
|
10
10
|
use rayon::prelude::*;
|
|
11
11
|
|
|
12
|
+
use crate::utils::EnterPolarsExt;
|
|
12
13
|
use crate::{ObjectValue, RbPolarsErr, RbResult, RbSeries, RbValueError, Wrap};
|
|
13
14
|
|
|
14
15
|
pub trait RbPolarsNumericType: PolarsNumericType {}
|
|
@@ -17,10 +18,12 @@ impl RbPolarsNumericType for UInt8Type {}
|
|
|
17
18
|
impl RbPolarsNumericType for UInt16Type {}
|
|
18
19
|
impl RbPolarsNumericType for UInt32Type {}
|
|
19
20
|
impl RbPolarsNumericType for UInt64Type {}
|
|
21
|
+
impl RbPolarsNumericType for UInt128Type {}
|
|
20
22
|
impl RbPolarsNumericType for Int8Type {}
|
|
21
23
|
impl RbPolarsNumericType for Int16Type {}
|
|
22
24
|
impl RbPolarsNumericType for Int32Type {}
|
|
23
25
|
impl RbPolarsNumericType for Int64Type {}
|
|
26
|
+
impl RbPolarsNumericType for Int128Type {}
|
|
24
27
|
impl RbPolarsNumericType for Float32Type {}
|
|
25
28
|
impl RbPolarsNumericType for Float64Type {}
|
|
26
29
|
|
|
@@ -41,6 +44,8 @@ fn iterator_to_struct(
|
|
|
41
44
|
name: PlSmallStr,
|
|
42
45
|
capacity: usize,
|
|
43
46
|
) -> RbResult<RbSeries> {
|
|
47
|
+
let rb = Ruby::get().unwrap();
|
|
48
|
+
|
|
44
49
|
let (vals, flds) = match &first_value {
|
|
45
50
|
av @ AnyValue::Struct(_, _, flds) => (av._iter_struct_av().collect::<Vec<_>>(), &**flds),
|
|
46
51
|
AnyValue::StructOwned(payload) => (payload.0.clone(), &*payload.1),
|
|
@@ -97,13 +102,15 @@ fn iterator_to_struct(
|
|
|
97
102
|
}
|
|
98
103
|
}
|
|
99
104
|
|
|
100
|
-
let fields =
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
let fields = rb.enter_polars_ok(|| {
|
|
106
|
+
POOL.install(|| {
|
|
107
|
+
items
|
|
108
|
+
.par_iter()
|
|
109
|
+
.zip(flds)
|
|
110
|
+
.map(|(av, fld)| Series::new(fld.name().clone(), av))
|
|
111
|
+
.collect::<Vec<_>>()
|
|
112
|
+
})
|
|
113
|
+
})?;
|
|
107
114
|
|
|
108
115
|
Ok(
|
|
109
116
|
StructChunked::from_series(name, fields[0].len(), fields.iter())
|
|
@@ -34,7 +34,7 @@ fn infer_and_finish<'a, A: ApplyLambda<'a>>(
|
|
|
34
34
|
.map(|ca| ca.into_series().into())
|
|
35
35
|
} else if out.respond_to("_s", true)? {
|
|
36
36
|
let rb_rbseries: &RbSeries = out.funcall("_s", ()).unwrap();
|
|
37
|
-
let series = rb_rbseries.series.
|
|
37
|
+
let series = rb_rbseries.series.read();
|
|
38
38
|
let dt = series.dtype();
|
|
39
39
|
applyer
|
|
40
40
|
.apply_lambda_with_list_out_type(lambda, null_count, &series, dt)
|
|
@@ -153,8 +153,8 @@ where
|
|
|
153
153
|
T: IntoValue,
|
|
154
154
|
{
|
|
155
155
|
let out: Value = lambda.funcall("call", (in_val,))?;
|
|
156
|
-
let
|
|
157
|
-
let tmp =
|
|
156
|
+
let rb_series: Obj<RbSeries> = out.funcall("_s", ())?;
|
|
157
|
+
let tmp = rb_series.series.read();
|
|
158
158
|
Ok(tmp.clone())
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -9,20 +9,24 @@ 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
11
|
use polars_error::PolarsWarning;
|
|
12
|
+
use polars_error::signals::register_polars_keyboard_interrupt_hook;
|
|
12
13
|
|
|
13
14
|
use crate::Wrap;
|
|
14
15
|
use crate::prelude::ObjectValue;
|
|
15
16
|
use crate::rb_modules::pl_utils;
|
|
17
|
+
use crate::utils::RubyAttach;
|
|
16
18
|
|
|
17
19
|
fn warning_function(msg: &str, _warning: PolarsWarning) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
Ruby::attach(|rb| {
|
|
21
|
+
if let Err(e) = pl_utils(rb).funcall::<_, _, Value>("_polars_warn", (msg.to_string(),)) {
|
|
22
|
+
eprintln!("{e}")
|
|
23
|
+
}
|
|
24
|
+
})
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
static POLARS_REGISTRY_INIT_LOCK: OnceLock<()> = OnceLock::new();
|
|
24
28
|
|
|
25
|
-
pub(crate) fn register_startup_deps() {
|
|
29
|
+
pub(crate) fn register_startup_deps(catch_keyboard_interrupt: bool) {
|
|
26
30
|
POLARS_REGISTRY_INIT_LOCK.get_or_init(|| {
|
|
27
31
|
let object_builder = Box::new(|name: PlSmallStr, capacity: usize| {
|
|
28
32
|
Box::new(ObjectChunkedBuilder::<ObjectValue>::new(name, capacity))
|
|
@@ -30,13 +34,13 @@ pub(crate) fn register_startup_deps() {
|
|
|
30
34
|
});
|
|
31
35
|
|
|
32
36
|
let object_converter = Arc::new(|av: AnyValue| {
|
|
33
|
-
let object = ObjectValue {
|
|
34
|
-
inner: Wrap(av).into_value_with(
|
|
35
|
-
};
|
|
37
|
+
let object = Ruby::attach(|rb| ObjectValue {
|
|
38
|
+
inner: Wrap(av).into_value_with(rb).into(),
|
|
39
|
+
});
|
|
36
40
|
Box::new(object) as Box<dyn Any>
|
|
37
41
|
});
|
|
38
42
|
let rbobject_converter = Arc::new(|av: AnyValue| {
|
|
39
|
-
let object = Wrap(av).into_value_with(
|
|
43
|
+
let object = Ruby::attach(|rb| Wrap(av).into_value_with(rb));
|
|
40
44
|
Box::new(object) as Box<dyn Any>
|
|
41
45
|
});
|
|
42
46
|
|
|
@@ -50,5 +54,9 @@ pub(crate) fn register_startup_deps() {
|
|
|
50
54
|
);
|
|
51
55
|
// Register warning function for `polars_warn!`.
|
|
52
56
|
polars_error::set_warning_function(warning_function);
|
|
57
|
+
|
|
58
|
+
if catch_keyboard_interrupt {
|
|
59
|
+
register_polars_keyboard_interrupt_hook();
|
|
60
|
+
}
|
|
53
61
|
});
|
|
54
62
|
}
|
data/ext/polars/src/prelude.rs
CHANGED
|
@@ -1,64 +1,34 @@
|
|
|
1
|
-
use magnus::{
|
|
1
|
+
use magnus::{Module, RClass, RModule, Ruby, value::Lazy};
|
|
2
2
|
|
|
3
|
-
static POLARS: Lazy<RModule> = Lazy::new(|
|
|
3
|
+
static POLARS: Lazy<RModule> = Lazy::new(|rb| rb.class_object().const_get("Polars").unwrap());
|
|
4
|
+
static UTILS: Lazy<RModule> = Lazy::new(|rb| rb.get_inner(&POLARS).const_get("Utils").unwrap());
|
|
5
|
+
static SERIES: Lazy<RClass> = Lazy::new(|rb| rb.get_inner(&POLARS).const_get("Series").unwrap());
|
|
4
6
|
|
|
5
|
-
pub(crate) fn polars() -> RModule {
|
|
6
|
-
|
|
7
|
+
pub(crate) fn polars(rb: &Ruby) -> RModule {
|
|
8
|
+
rb.get_inner(&POLARS)
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
pub(crate) fn pl_series() -> RClass {
|
|
13
|
-
Ruby::get().unwrap().get_inner(&SERIES)
|
|
11
|
+
pub(crate) fn pl_utils(rb: &Ruby) -> RModule {
|
|
12
|
+
rb.get_inner(&UTILS)
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
pub(crate) fn pl_utils() -> RModule {
|
|
19
|
-
Ruby::get().unwrap().get_inner(&UTILS)
|
|
15
|
+
pub(crate) fn pl_series(rb: &Ruby) -> RClass {
|
|
16
|
+
rb.get_inner(&SERIES)
|
|
20
17
|
}
|
|
21
18
|
|
|
22
19
|
static BIGDECIMAL: Lazy<RClass> =
|
|
23
|
-
Lazy::new(|
|
|
20
|
+
Lazy::new(|rb| rb.class_object().const_get("BigDecimal").unwrap());
|
|
21
|
+
static DATE: Lazy<RClass> = Lazy::new(|rb| rb.class_object().const_get("Date").unwrap());
|
|
22
|
+
static DATETIME: Lazy<RClass> = Lazy::new(|rb| rb.class_object().const_get("DateTime").unwrap());
|
|
24
23
|
|
|
25
|
-
pub(crate) fn bigdecimal() -> RClass {
|
|
26
|
-
|
|
24
|
+
pub(crate) fn bigdecimal(rb: &Ruby) -> RClass {
|
|
25
|
+
rb.get_inner(&BIGDECIMAL)
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
pub(crate) fn date() -> RClass {
|
|
32
|
-
Ruby::get().unwrap().get_inner(&DATE)
|
|
28
|
+
pub(crate) fn date(rb: &Ruby) -> RClass {
|
|
29
|
+
rb.get_inner(&DATE)
|
|
33
30
|
}
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
pub(crate) fn datetime() -> RClass {
|
|
39
|
-
Ruby::get().unwrap().get_inner(&DATETIME)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
static ERROR: Lazy<ExceptionClass> =
|
|
43
|
-
Lazy::new(|ruby| ruby.get_inner(&POLARS).const_get("Error").unwrap());
|
|
44
|
-
|
|
45
|
-
pub(crate) fn error() -> ExceptionClass {
|
|
46
|
-
Ruby::get().unwrap().get_inner(&ERROR)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
static COMPUTE_ERROR: Lazy<ExceptionClass> =
|
|
50
|
-
Lazy::new(|ruby| ruby.get_inner(&POLARS).const_get("ComputeError").unwrap());
|
|
51
|
-
|
|
52
|
-
pub(crate) fn compute_error() -> ExceptionClass {
|
|
53
|
-
Ruby::get().unwrap().get_inner(&COMPUTE_ERROR)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
static INVALID_OPERATION_ERROR: Lazy<ExceptionClass> = Lazy::new(|ruby| {
|
|
57
|
-
ruby.get_inner(&POLARS)
|
|
58
|
-
.const_get("InvalidOperationError")
|
|
59
|
-
.unwrap()
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
pub(crate) fn invalid_operation_error() -> ExceptionClass {
|
|
63
|
-
Ruby::get().unwrap().get_inner(&INVALID_OPERATION_ERROR)
|
|
32
|
+
pub(crate) fn datetime(rb: &Ruby) -> RClass {
|
|
33
|
+
rb.get_inner(&DATETIME)
|
|
64
34
|
}
|
|
@@ -1,185 +1,124 @@
|
|
|
1
|
-
use
|
|
1
|
+
use DataType::*;
|
|
2
|
+
use magnus::{IntoValue, Ruby, Value};
|
|
3
|
+
use polars::prelude::*;
|
|
4
|
+
|
|
2
5
|
use crate::prelude::*;
|
|
3
|
-
use crate::utils::
|
|
6
|
+
use crate::utils::EnterPolarsExt;
|
|
4
7
|
use crate::{RbResult, RbSeries};
|
|
5
|
-
use magnus::{IntoValue, Ruby, Value};
|
|
6
8
|
|
|
7
|
-
fn scalar_to_rb(scalar: RbResult<Scalar
|
|
8
|
-
|
|
9
|
-
Ok(Wrap(scalar?.as_any_value()).into_value_with(&ruby))
|
|
9
|
+
fn scalar_to_rb(scalar: RbResult<Scalar>, rb: &Ruby) -> RbResult<Value> {
|
|
10
|
+
Ok(Wrap(scalar?.as_any_value()).into_value_with(rb))
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
impl RbSeries {
|
|
13
|
-
pub fn any(&
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
pub fn any(rb: &Ruby, self_: &Self, ignore_nulls: bool) -> RbResult<Option<bool>> {
|
|
15
|
+
rb.enter_polars(|| {
|
|
16
|
+
let s = self_.series.read();
|
|
17
|
+
let s = s.bool()?;
|
|
18
|
+
PolarsResult::Ok(if ignore_nulls {
|
|
19
|
+
Some(s.any())
|
|
20
|
+
} else {
|
|
21
|
+
s.any_kleene()
|
|
22
|
+
})
|
|
20
23
|
})
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
pub fn all(&
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
pub fn all(rb: &Ruby, self_: &Self, ignore_nulls: bool) -> RbResult<Option<bool>> {
|
|
27
|
+
rb.enter_polars(|| {
|
|
28
|
+
let s = self_.series.read();
|
|
29
|
+
let s = s.bool()?;
|
|
30
|
+
PolarsResult::Ok(if ignore_nulls {
|
|
31
|
+
Some(s.all())
|
|
32
|
+
} else {
|
|
33
|
+
s.all_kleene()
|
|
34
|
+
})
|
|
30
35
|
})
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
pub fn arg_max(&
|
|
34
|
-
|
|
38
|
+
pub fn arg_max(rb: &Ruby, self_: &Self) -> RbResult<Option<usize>> {
|
|
39
|
+
rb.enter_polars_ok(|| self_.series.read().arg_max())
|
|
35
40
|
}
|
|
36
41
|
|
|
37
|
-
pub fn arg_min(&
|
|
38
|
-
|
|
42
|
+
pub fn arg_min(rb: &Ruby, self_: &Self) -> RbResult<Option<usize>> {
|
|
43
|
+
rb.enter_polars_ok(|| self_.series.read().arg_min())
|
|
39
44
|
}
|
|
40
45
|
|
|
41
|
-
pub fn
|
|
42
|
-
|
|
43
|
-
rb_self
|
|
44
|
-
.series
|
|
45
|
-
.borrow()
|
|
46
|
-
.max_reduce()
|
|
47
|
-
.map_err(RbPolarsErr::from)?
|
|
48
|
-
.as_any_value(),
|
|
49
|
-
)
|
|
50
|
-
.into_value_with(ruby))
|
|
46
|
+
pub fn min(rb: &Ruby, self_: &Self) -> RbResult<Value> {
|
|
47
|
+
scalar_to_rb(rb.enter_polars(|| self_.series.read().min_reduce()), rb)
|
|
51
48
|
}
|
|
52
49
|
|
|
53
|
-
pub fn
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
)
|
|
65
|
-
.into_value_with(ruby)),
|
|
50
|
+
pub fn max(rb: &Ruby, self_: &Self) -> RbResult<Value> {
|
|
51
|
+
scalar_to_rb(rb.enter_polars(|| self_.series.read().max_reduce()), rb)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
pub fn mean(rb: &Ruby, self_: &Self) -> RbResult<Value> {
|
|
55
|
+
let s = self_.series.read();
|
|
56
|
+
match s.dtype() {
|
|
57
|
+
Boolean => scalar_to_rb(
|
|
58
|
+
rb.enter_polars(|| s.cast(&DataType::UInt8).unwrap().mean_reduce()),
|
|
59
|
+
rb,
|
|
60
|
+
),
|
|
66
61
|
// For non-numeric output types we require mean_reduce.
|
|
67
|
-
dt if dt.is_temporal() =>
|
|
68
|
-
|
|
69
|
-
.series
|
|
70
|
-
.borrow()
|
|
71
|
-
.mean_reduce()
|
|
72
|
-
.map_err(to_rb_err)?
|
|
73
|
-
.as_any_value(),
|
|
74
|
-
)
|
|
75
|
-
.into_value_with(ruby)),
|
|
76
|
-
_ => Ok(rb_self.series.borrow().mean().into_value_with(ruby)),
|
|
62
|
+
dt if dt.is_temporal() => scalar_to_rb(rb.enter_polars(|| s.mean_reduce()), rb),
|
|
63
|
+
_ => Ok(s.mean().into_value_with(rb)),
|
|
77
64
|
}
|
|
78
65
|
}
|
|
79
66
|
|
|
80
|
-
pub fn median(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
.unwrap()
|
|
88
|
-
.median_reduce()
|
|
89
|
-
.map_err(RbPolarsErr::from)?
|
|
90
|
-
.as_any_value(),
|
|
91
|
-
)
|
|
92
|
-
.into_value_with(ruby)),
|
|
67
|
+
pub fn median(rb: &Ruby, self_: &Self) -> RbResult<Value> {
|
|
68
|
+
let s = self_.series.read();
|
|
69
|
+
match s.dtype() {
|
|
70
|
+
Boolean => scalar_to_rb(
|
|
71
|
+
rb.enter_polars(|| s.cast(&DataType::UInt8).unwrap().median_reduce()),
|
|
72
|
+
rb,
|
|
73
|
+
),
|
|
93
74
|
// For non-numeric output types we require median_reduce.
|
|
94
|
-
dt if dt.is_temporal() =>
|
|
95
|
-
|
|
96
|
-
.series
|
|
97
|
-
.borrow()
|
|
98
|
-
.median_reduce()
|
|
99
|
-
.map_err(RbPolarsErr::from)?
|
|
100
|
-
.as_any_value(),
|
|
101
|
-
)
|
|
102
|
-
.into_value_with(ruby)),
|
|
103
|
-
_ => Ok(rb_self.series.borrow().median().into_value_with(ruby)),
|
|
75
|
+
dt if dt.is_temporal() => scalar_to_rb(rb.enter_polars(|| s.median_reduce()), rb),
|
|
76
|
+
_ => Ok(s.median().into_value_with(rb)),
|
|
104
77
|
}
|
|
105
78
|
}
|
|
106
79
|
|
|
107
|
-
pub fn min(ruby: &Ruby, rb_self: &Self) -> RbResult<Value> {
|
|
108
|
-
Ok(Wrap(
|
|
109
|
-
rb_self
|
|
110
|
-
.series
|
|
111
|
-
.borrow()
|
|
112
|
-
.min_reduce()
|
|
113
|
-
.map_err(RbPolarsErr::from)?
|
|
114
|
-
.as_any_value(),
|
|
115
|
-
)
|
|
116
|
-
.into_value_with(ruby))
|
|
117
|
-
}
|
|
118
|
-
|
|
119
80
|
pub fn quantile(
|
|
120
|
-
|
|
121
|
-
|
|
81
|
+
rb: &Ruby,
|
|
82
|
+
self_: &Self,
|
|
122
83
|
quantile: f64,
|
|
123
84
|
interpolation: Wrap<QuantileMethod>,
|
|
124
85
|
) -> RbResult<Value> {
|
|
125
|
-
|
|
126
|
-
.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
pub fn sum(ruby: &Ruby, rb_self: &Self) -> RbResult<Value> {
|
|
135
|
-
Ok(Wrap(
|
|
136
|
-
rb_self
|
|
137
|
-
.series
|
|
138
|
-
.borrow()
|
|
139
|
-
.sum_reduce()
|
|
140
|
-
.map_err(RbPolarsErr::from)?
|
|
141
|
-
.as_any_value(),
|
|
86
|
+
scalar_to_rb(
|
|
87
|
+
rb.enter_polars(|| {
|
|
88
|
+
self_
|
|
89
|
+
.series
|
|
90
|
+
.read()
|
|
91
|
+
.quantile_reduce(quantile, interpolation.0)
|
|
92
|
+
}),
|
|
93
|
+
rb,
|
|
142
94
|
)
|
|
143
|
-
.into_value_with(ruby))
|
|
144
95
|
}
|
|
145
96
|
|
|
146
|
-
pub fn
|
|
147
|
-
scalar_to_rb(
|
|
97
|
+
pub fn sum(rb: &Ruby, self_: &Self) -> RbResult<Value> {
|
|
98
|
+
scalar_to_rb(rb.enter_polars(|| self_.series.read().sum_reduce()), rb)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
pub fn first(rb: &Ruby, self_: &Self) -> RbResult<Value> {
|
|
102
|
+
scalar_to_rb(rb.enter_polars_ok(|| self_.series.read().first()), rb)
|
|
148
103
|
}
|
|
149
104
|
|
|
150
|
-
pub fn last(&
|
|
151
|
-
scalar_to_rb(
|
|
105
|
+
pub fn last(rb: &Ruby, self_: &Self) -> RbResult<Value> {
|
|
106
|
+
scalar_to_rb(rb.enter_polars_ok(|| self_.series.read().last()), rb)
|
|
152
107
|
}
|
|
153
108
|
|
|
154
|
-
pub fn approx_n_unique(&
|
|
155
|
-
|
|
156
|
-
.series
|
|
157
|
-
.borrow()
|
|
158
|
-
.approx_n_unique()
|
|
159
|
-
.map_err(RbPolarsErr::from)?)
|
|
109
|
+
pub fn approx_n_unique(rb: &Ruby, self_: &Self) -> RbResult<IdxSize> {
|
|
110
|
+
rb.enter_polars(|| self_.series.read().approx_n_unique())
|
|
160
111
|
}
|
|
161
112
|
|
|
162
|
-
pub fn bitwise_and(&
|
|
163
|
-
scalar_to_rb(
|
|
164
|
-
.series
|
|
165
|
-
.borrow()
|
|
166
|
-
.and_reduce()
|
|
167
|
-
.map_err(RbPolarsErr::from)?))
|
|
113
|
+
pub fn bitwise_and(rb: &Ruby, self_: &Self) -> RbResult<Value> {
|
|
114
|
+
scalar_to_rb(rb.enter_polars(|| self_.series.read().and_reduce()), rb)
|
|
168
115
|
}
|
|
169
116
|
|
|
170
|
-
pub fn bitwise_or(&
|
|
171
|
-
scalar_to_rb(
|
|
172
|
-
.series
|
|
173
|
-
.borrow()
|
|
174
|
-
.or_reduce()
|
|
175
|
-
.map_err(RbPolarsErr::from)?))
|
|
117
|
+
pub fn bitwise_or(rb: &Ruby, self_: &Self) -> RbResult<Value> {
|
|
118
|
+
scalar_to_rb(rb.enter_polars(|| self_.series.read().or_reduce()), rb)
|
|
176
119
|
}
|
|
177
120
|
|
|
178
|
-
pub fn bitwise_xor(&
|
|
179
|
-
scalar_to_rb(
|
|
180
|
-
.series
|
|
181
|
-
.borrow()
|
|
182
|
-
.xor_reduce()
|
|
183
|
-
.map_err(RbPolarsErr::from)?))
|
|
121
|
+
pub fn bitwise_xor(rb: &Ruby, self_: &Self) -> RbResult<Value> {
|
|
122
|
+
scalar_to_rb(rb.enter_polars(|| self_.series.read().xor_reduce()), rb)
|
|
184
123
|
}
|
|
185
124
|
}
|
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
use
|
|
1
|
+
use magnus::Ruby;
|
|
2
|
+
|
|
3
|
+
use super::RbSeries;
|
|
4
|
+
use crate::RbResult;
|
|
5
|
+
use crate::utils::EnterPolarsExt;
|
|
2
6
|
|
|
3
7
|
impl RbSeries {
|
|
4
|
-
pub fn add(&
|
|
5
|
-
|
|
6
|
-
.map(Into::into)
|
|
7
|
-
.map_err(RbPolarsErr::from)?)
|
|
8
|
+
pub fn add(rb: &Ruby, self_: &Self, other: &RbSeries) -> RbResult<Self> {
|
|
9
|
+
rb.enter_polars_series(|| &*self_.series.read() + &*other.series.read())
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
pub fn sub(&
|
|
11
|
-
|
|
12
|
-
.map(Into::into)
|
|
13
|
-
.map_err(RbPolarsErr::from)?)
|
|
12
|
+
pub fn sub(rb: &Ruby, self_: &Self, other: &RbSeries) -> RbResult<Self> {
|
|
13
|
+
rb.enter_polars_series(|| &*self_.series.read() - &*other.series.read())
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
pub fn mul(&
|
|
17
|
-
|
|
18
|
-
.map(Into::into)
|
|
19
|
-
.map_err(RbPolarsErr::from)?)
|
|
16
|
+
pub fn mul(rb: &Ruby, self_: &Self, other: &RbSeries) -> RbResult<Self> {
|
|
17
|
+
rb.enter_polars_series(|| &*self_.series.read() * &*other.series.read())
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
pub fn div(&
|
|
23
|
-
|
|
24
|
-
.map(Into::into)
|
|
25
|
-
.map_err(RbPolarsErr::from)?)
|
|
20
|
+
pub fn div(rb: &Ruby, self_: &Self, other: &RbSeries) -> RbResult<Self> {
|
|
21
|
+
rb.enter_polars_series(|| &*self_.series.read() / &*other.series.read())
|
|
26
22
|
}
|
|
27
23
|
|
|
28
|
-
pub fn rem(&
|
|
29
|
-
|
|
30
|
-
.map(Into::into)
|
|
31
|
-
.map_err(RbPolarsErr::from)?)
|
|
24
|
+
pub fn rem(rb: &Ruby, self_: &Self, other: &RbSeries) -> RbResult<Self> {
|
|
25
|
+
rb.enter_polars_series(|| &*self_.series.read() % &*other.series.read())
|
|
32
26
|
}
|
|
33
27
|
}
|
|
34
28
|
|
|
@@ -36,7 +30,7 @@ macro_rules! impl_arithmetic {
|
|
|
36
30
|
($name:ident, $type:ty, $operand:tt) => {
|
|
37
31
|
impl RbSeries {
|
|
38
32
|
pub fn $name(&self, other: $type) -> RbResult<Self> {
|
|
39
|
-
Ok(RbSeries::new(&*self.series.
|
|
33
|
+
Ok(RbSeries::new(&*self.series.read() $operand other))
|
|
40
34
|
}
|
|
41
35
|
}
|
|
42
36
|
};
|