polars-df 0.15.0 → 0.26.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 +274 -0
- data/Cargo.lock +1465 -867
- data/Cargo.toml +3 -0
- data/LICENSE.txt +2 -2
- data/README.md +87 -37
- data/ext/polars/Cargo.toml +47 -16
- 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/mod.rs +1 -0
- data/ext/polars/src/catalog/unity.rs +470 -0
- data/ext/polars/src/conversion/any_value.rs +99 -84
- data/ext/polars/src/conversion/categorical.rs +30 -0
- data/ext/polars/src/conversion/chunked_array.rs +71 -62
- data/ext/polars/src/conversion/datetime.rs +63 -0
- data/ext/polars/src/conversion/mod.rs +796 -312
- data/ext/polars/src/dataframe/construction.rs +6 -18
- data/ext/polars/src/dataframe/export.rs +30 -39
- data/ext/polars/src/dataframe/general.rs +294 -362
- data/ext/polars/src/dataframe/io.rs +33 -150
- data/ext/polars/src/dataframe/map.rs +175 -0
- data/ext/polars/src/dataframe/mod.rs +37 -5
- data/ext/polars/src/dataframe/serde.rs +23 -8
- data/ext/polars/src/error.rs +44 -7
- data/ext/polars/src/exceptions.rs +21 -8
- data/ext/polars/src/expr/array.rs +86 -22
- data/ext/polars/src/expr/binary.rs +50 -1
- data/ext/polars/src/expr/bitwise.rs +39 -0
- data/ext/polars/src/expr/categorical.rs +20 -0
- data/ext/polars/src/expr/datatype.rs +51 -0
- data/ext/polars/src/expr/datetime.rs +99 -41
- data/ext/polars/src/expr/extension.rs +12 -0
- data/ext/polars/src/expr/general.rs +252 -128
- data/ext/polars/src/expr/list.rs +56 -60
- data/ext/polars/src/expr/meta.rs +30 -35
- data/ext/polars/src/expr/mod.rs +28 -6
- data/ext/polars/src/expr/name.rs +29 -14
- data/ext/polars/src/expr/rolling.rs +111 -3
- data/ext/polars/src/expr/selector.rs +219 -0
- data/ext/polars/src/expr/serde.rs +28 -0
- data/ext/polars/src/expr/string.rs +118 -20
- data/ext/polars/src/expr/struct.rs +14 -1
- data/ext/polars/src/file.rs +194 -86
- data/ext/polars/src/functions/aggregation.rs +13 -12
- data/ext/polars/src/functions/business.rs +2 -3
- data/ext/polars/src/functions/eager.rs +3 -2
- data/ext/polars/src/functions/io.rs +90 -18
- data/ext/polars/src/functions/lazy.rs +267 -118
- data/ext/polars/src/functions/meta.rs +8 -7
- data/ext/polars/src/functions/misc.rs +1 -1
- data/ext/polars/src/functions/mod.rs +2 -1
- data/ext/polars/src/functions/range.rs +88 -31
- data/ext/polars/src/functions/strings.rs +6 -0
- data/ext/polars/src/functions/utils.rs +8 -0
- data/ext/polars/src/interop/arrow/mod.rs +52 -1
- data/ext/polars/src/interop/arrow/{to_ruby.rs → to_rb.rs} +37 -7
- 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 +72 -50
- data/ext/polars/src/io/cloud_options.rs +107 -0
- data/ext/polars/src/io/mod.rs +4 -0
- data/ext/polars/src/io/scan_options.rs +113 -0
- data/ext/polars/src/io/sink_options.rs +46 -0
- data/ext/polars/src/io/sink_output.rs +21 -0
- data/ext/polars/src/lazyframe/exitable.rs +39 -0
- data/ext/polars/src/lazyframe/general.rs +846 -368
- data/ext/polars/src/lazyframe/mod.rs +58 -5
- data/ext/polars/src/lazyframe/optflags.rs +59 -0
- data/ext/polars/src/lazyframe/serde.rs +36 -4
- data/ext/polars/src/lazyframe/sink.rs +46 -0
- data/ext/polars/src/lazygroupby.rs +38 -9
- data/ext/polars/src/lib.rs +574 -165
- data/ext/polars/src/map/lazy.rs +44 -74
- data/ext/polars/src/map/mod.rs +18 -254
- data/ext/polars/src/map/series.rs +241 -1087
- data/ext/polars/src/on_startup.rs +192 -9
- data/ext/polars/src/prelude.rs +1 -0
- data/ext/polars/src/rb_modules.rs +10 -57
- data/ext/polars/src/ruby/exceptions.rs +26 -0
- data/ext/polars/src/ruby/gvl.rs +104 -0
- data/ext/polars/src/ruby/lazy.rs +46 -0
- data/ext/polars/src/ruby/mod.rs +11 -0
- data/ext/polars/src/ruby/numo.rs +52 -0
- data/ext/polars/src/ruby/plan_callback.rs +198 -0
- data/ext/polars/src/ruby/rb_modules.rs +16 -0
- data/ext/polars/src/ruby/ruby_convert_registry.rs +51 -0
- data/ext/polars/src/ruby/ruby_function.rs +11 -0
- data/ext/polars/src/ruby/ruby_udf.rs +164 -0
- data/ext/polars/src/ruby/thread.rs +65 -0
- data/ext/polars/src/ruby/utils.rs +39 -0
- data/ext/polars/src/series/aggregation.rs +116 -91
- 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 +80 -70
- data/ext/polars/src/series/export.rs +98 -56
- data/ext/polars/src/series/general.rs +323 -440
- data/ext/polars/src/series/import.rs +22 -5
- data/ext/polars/src/series/map.rs +103 -0
- data/ext/polars/src/series/mod.rs +57 -15
- data/ext/polars/src/series/scatter.rs +139 -82
- 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 +105 -4
- data/lib/polars/array_expr.rb +500 -22
- data/lib/polars/array_name_space.rb +384 -10
- data/lib/polars/batched_csv_reader.rb +48 -66
- data/lib/polars/binary_expr.rb +217 -0
- data/lib/polars/binary_name_space.rb +155 -1
- data/lib/polars/cat_expr.rb +224 -0
- data/lib/polars/cat_name_space.rb +132 -32
- data/lib/polars/catalog/unity/catalog_info.rb +20 -0
- data/lib/polars/catalog/unity/column_info.rb +31 -0
- data/lib/polars/catalog/unity/namespace_info.rb +21 -0
- data/lib/polars/catalog/unity/table_info.rb +50 -0
- data/lib/polars/catalog.rb +448 -0
- data/lib/polars/collect_batches.rb +22 -0
- data/lib/polars/config.rb +3 -3
- data/lib/polars/convert.rb +201 -36
- data/lib/polars/data_frame.rb +2851 -1017
- data/lib/polars/data_frame_plot.rb +173 -0
- data/lib/polars/data_type_expr.rb +52 -0
- data/lib/polars/data_type_group.rb +6 -0
- data/lib/polars/data_types.rb +118 -18
- data/lib/polars/date_time_expr.rb +426 -84
- data/lib/polars/date_time_name_space.rb +384 -111
- data/lib/polars/dynamic_group_by.rb +102 -10
- data/lib/polars/exceptions.rb +50 -5
- data/lib/polars/expr.rb +2159 -915
- data/lib/polars/extension_expr.rb +39 -0
- data/lib/polars/extension_name_space.rb +39 -0
- data/lib/polars/functions/aggregation/horizontal.rb +11 -6
- data/lib/polars/functions/aggregation/vertical.rb +2 -3
- data/lib/polars/functions/as_datatype.rb +290 -8
- data/lib/polars/functions/business.rb +95 -0
- data/lib/polars/functions/col.rb +6 -5
- data/lib/polars/functions/datatype.rb +62 -0
- data/lib/polars/functions/eager.rb +426 -24
- data/lib/polars/functions/escape_regex.rb +21 -0
- data/lib/polars/functions/lazy.rb +813 -195
- data/lib/polars/functions/lit.rb +21 -10
- data/lib/polars/functions/range/int_range.rb +74 -2
- data/lib/polars/functions/range/linear_space.rb +195 -0
- data/lib/polars/functions/range/time_range.rb +1 -1
- data/lib/polars/functions/repeat.rb +7 -12
- data/lib/polars/functions/whenthen.rb +2 -2
- data/lib/polars/group_by.rb +188 -58
- data/lib/polars/iceberg_dataset.rb +108 -0
- data/lib/polars/in_process_query.rb +37 -0
- data/lib/polars/io/cloud.rb +18 -0
- data/lib/polars/io/csv.rb +336 -128
- data/lib/polars/io/database.rb +19 -4
- data/lib/polars/io/delta.rb +134 -0
- data/lib/polars/io/iceberg.rb +34 -0
- data/lib/polars/io/ipc.rb +63 -63
- data/lib/polars/io/json.rb +16 -0
- data/lib/polars/io/lines.rb +172 -0
- data/lib/polars/io/ndjson.rb +176 -20
- data/lib/polars/io/parquet.rb +173 -95
- data/lib/polars/io/scan_options.rb +55 -0
- data/lib/polars/io/sink_options.rb +27 -0
- data/lib/polars/io/utils.rb +17 -0
- data/lib/polars/lazy_frame.rb +3017 -622
- data/lib/polars/lazy_group_by.rb +436 -2
- data/lib/polars/list_expr.rb +551 -59
- data/lib/polars/list_name_space.rb +465 -51
- data/lib/polars/meta_expr.rb +146 -24
- data/lib/polars/name_expr.rb +87 -2
- data/lib/polars/query_opt_flags.rb +264 -0
- data/lib/polars/rolling_group_by.rb +90 -5
- data/lib/polars/scan_cast_options.rb +86 -0
- data/lib/polars/schema.rb +128 -0
- data/lib/polars/selector.rb +245 -0
- data/lib/polars/selectors.rb +1048 -201
- data/lib/polars/series.rb +2522 -774
- data/lib/polars/series_plot.rb +72 -0
- data/lib/polars/slice.rb +1 -1
- data/lib/polars/sql_context.rb +13 -6
- data/lib/polars/string_cache.rb +19 -72
- data/lib/polars/string_expr.rb +561 -107
- data/lib/polars/string_name_space.rb +781 -109
- data/lib/polars/struct_expr.rb +139 -18
- data/lib/polars/struct_name_space.rb +19 -1
- 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 +350 -0
- data/lib/polars/utils/construction/utils.rb +9 -0
- data/lib/polars/utils/convert.rb +18 -8
- data/lib/polars/utils/deprecation.rb +11 -0
- data/lib/polars/utils/parse.rb +62 -9
- data/lib/polars/utils/reduce_balanced.rb +43 -0
- data/lib/polars/utils/serde.rb +22 -0
- data/lib/polars/utils/unstable.rb +19 -0
- data/lib/polars/utils/various.rb +86 -1
- data/lib/polars/utils.rb +63 -48
- data/lib/polars/version.rb +1 -1
- data/lib/polars.rb +85 -2
- metadata +80 -28
- data/ext/polars/src/allocator.rs +0 -13
- data/ext/polars/src/batched_csv.rs +0 -138
- data/ext/polars/src/functions/string_cache.rs +0 -25
- data/ext/polars/src/map/dataframe.rs +0 -338
- data/lib/polars/plot.rb +0 -109
data/ext/polars/src/map/lazy.rs
CHANGED
|
@@ -1,79 +1,49 @@
|
|
|
1
|
-
use magnus::{
|
|
1
|
+
use magnus::{KwArgs, RArray, Ruby, Value, prelude::*, value::Opaque};
|
|
2
2
|
use polars::prelude::*;
|
|
3
3
|
|
|
4
|
-
use crate::
|
|
5
|
-
use crate::
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// Wrap this RbSeries object in the Ruby side Series wrapper
|
|
37
|
-
let ruby_series_wrapper_a: Value = utils().funcall("wrap_s", (rbseries_a,)).unwrap();
|
|
38
|
-
let ruby_series_wrapper_b: Value = utils().funcall("wrap_s", (rbseries_b,)).unwrap();
|
|
39
|
-
|
|
40
|
-
// call the lambda and get a Ruby side Series wrapper
|
|
41
|
-
let result_series_wrapper: Value =
|
|
42
|
-
match lambda.funcall("call", (ruby_series_wrapper_a, ruby_series_wrapper_b)) {
|
|
43
|
-
Ok(rbobj) => rbobj,
|
|
44
|
-
Err(e) => polars_bail!(
|
|
45
|
-
ComputeError: "custom Ruby function failed: {}", e,
|
|
46
|
-
),
|
|
47
|
-
};
|
|
48
|
-
let rbseries = if let Ok(rbexpr) = result_series_wrapper.funcall::<_, _, &RbExpr>("_rbexpr", ())
|
|
49
|
-
{
|
|
50
|
-
let expr = rbexpr.inner.clone();
|
|
51
|
-
let df = DataFrame::empty();
|
|
52
|
-
let out = df
|
|
53
|
-
.lazy()
|
|
54
|
-
.select([expr])
|
|
55
|
-
.with_predicate_pushdown(false)
|
|
56
|
-
.with_projection_pushdown(false)
|
|
57
|
-
.collect()?;
|
|
58
|
-
|
|
59
|
-
let s = out.select_at_idx(0).unwrap().clone();
|
|
60
|
-
RbSeries::new(s.take_materialized_series())
|
|
61
|
-
} else {
|
|
62
|
-
return Some(to_series(result_series_wrapper, "")).transpose();
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// Finally get the actual Series
|
|
66
|
-
let binding = rbseries.series.borrow();
|
|
67
|
-
Ok(Some(binding.clone()))
|
|
4
|
+
use crate::expr::ToExprs;
|
|
5
|
+
use crate::expr::datatype::RbDataTypeExpr;
|
|
6
|
+
use crate::ruby::ruby_udf::{RubyUdfExpression, RubyUdfExt};
|
|
7
|
+
use crate::ruby::utils::{TryIntoValue, to_pl_err};
|
|
8
|
+
use crate::{RbExpr, RbResult, RbSeries, Wrap};
|
|
9
|
+
|
|
10
|
+
pub(crate) fn call_lambda_with_series(
|
|
11
|
+
rb: &Ruby,
|
|
12
|
+
s: &[Column],
|
|
13
|
+
output_dtype: Option<DataType>,
|
|
14
|
+
lambda: Opaque<Value>,
|
|
15
|
+
) -> PolarsResult<Column> {
|
|
16
|
+
let lambda = rb.get_inner(lambda);
|
|
17
|
+
|
|
18
|
+
// Set return_dtype in kwargs
|
|
19
|
+
let dict = rb.hash_new();
|
|
20
|
+
let output_dtype = output_dtype
|
|
21
|
+
.map(|v| Wrap(v).try_into_value_with(rb))
|
|
22
|
+
.transpose()
|
|
23
|
+
.map_err(to_pl_err)?;
|
|
24
|
+
dict.aset(rb.sym_new("return_dtype"), output_dtype)
|
|
25
|
+
.map_err(to_pl_err)?;
|
|
26
|
+
|
|
27
|
+
let series_objects = rb.ary_from_iter(
|
|
28
|
+
s.iter()
|
|
29
|
+
.map(|c| RbSeries::new(c.as_materialized_series().clone())),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
let result = lambda.funcall::<_, _, &RbSeries>("call", (series_objects, KwArgs(dict)));
|
|
33
|
+
result
|
|
34
|
+
.map_err(to_pl_err)
|
|
35
|
+
.map(|s| s.clone().series.into_inner().into_column())
|
|
68
36
|
}
|
|
69
37
|
|
|
70
|
-
pub fn
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
38
|
+
pub fn map_expr(
|
|
39
|
+
rbexpr: RArray,
|
|
40
|
+
lambda: Value,
|
|
41
|
+
output_type: Option<&RbDataTypeExpr>,
|
|
42
|
+
is_elementwise: bool,
|
|
43
|
+
returns_scalar: bool,
|
|
44
|
+
) -> RbResult<RbExpr> {
|
|
45
|
+
let output_type = output_type.map(|v| v.inner.clone());
|
|
46
|
+
let func = RubyUdfExpression::new(lambda, output_type, is_elementwise, returns_scalar);
|
|
47
|
+
let exprs = rbexpr.to_exprs()?;
|
|
48
|
+
Ok(Expr::map_many_ruby(exprs, func).into())
|
|
79
49
|
}
|
data/ext/polars/src/map/mod.rs
CHANGED
|
@@ -1,259 +1,23 @@
|
|
|
1
|
-
pub mod dataframe;
|
|
2
1
|
pub mod lazy;
|
|
3
2
|
pub mod series;
|
|
4
3
|
|
|
5
|
-
use magnus::{
|
|
6
|
-
use polars::chunked_array::builder::get_list_builder;
|
|
4
|
+
use magnus::{Ruby, Value, prelude::*};
|
|
7
5
|
use polars::prelude::*;
|
|
8
|
-
use polars_core::export::rayon::prelude::*;
|
|
9
|
-
use polars_core::utils::CustomIterTools;
|
|
10
|
-
use polars_core::POOL;
|
|
11
6
|
|
|
12
|
-
use crate::{
|
|
13
|
-
|
|
14
|
-
pub trait
|
|
15
|
-
|
|
16
|
-
impl
|
|
17
|
-
impl
|
|
18
|
-
impl
|
|
19
|
-
impl
|
|
20
|
-
impl
|
|
21
|
-
impl
|
|
22
|
-
impl
|
|
23
|
-
impl
|
|
24
|
-
impl
|
|
25
|
-
impl
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
init_null_count: usize,
|
|
30
|
-
first_value: AnyValue,
|
|
31
|
-
name: PlSmallStr,
|
|
32
|
-
capacity: usize,
|
|
33
|
-
) -> RbResult<RbSeries> {
|
|
34
|
-
let (vals, flds) = match &first_value {
|
|
35
|
-
av @ AnyValue::Struct(_, _, flds) => (av._iter_struct_av().collect::<Vec<_>>(), &**flds),
|
|
36
|
-
AnyValue::StructOwned(payload) => (payload.0.clone(), &*payload.1),
|
|
37
|
-
_ => {
|
|
38
|
-
return Err(crate::exceptions::ComputeError::new_err(format!(
|
|
39
|
-
"expected struct got {first_value:?}",
|
|
40
|
-
)))
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
let struct_width = vals.len();
|
|
45
|
-
|
|
46
|
-
// every item in the struct is kept as its own buffer of anyvalues
|
|
47
|
-
// so as struct with 2 items: {a, b}
|
|
48
|
-
// will have
|
|
49
|
-
// [
|
|
50
|
-
// [ a values ]
|
|
51
|
-
// [ b values ]
|
|
52
|
-
// ]
|
|
53
|
-
let mut items = Vec::with_capacity(vals.len());
|
|
54
|
-
for item in vals {
|
|
55
|
-
let mut buf = Vec::with_capacity(capacity);
|
|
56
|
-
for _ in 0..init_null_count {
|
|
57
|
-
buf.push(AnyValue::Null);
|
|
58
|
-
}
|
|
59
|
-
buf.push(item.clone());
|
|
60
|
-
items.push(buf);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
for dict in it {
|
|
64
|
-
match dict {
|
|
65
|
-
None => {
|
|
66
|
-
for field_items in &mut items {
|
|
67
|
-
field_items.push(AnyValue::Null);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
Some(dict) => {
|
|
71
|
-
let dict = RHash::try_convert(dict)?;
|
|
72
|
-
if dict.len() != struct_width {
|
|
73
|
-
return Err(crate::exceptions::ComputeError::new_err(
|
|
74
|
-
format!("Cannot create struct type.\n> The struct dtype expects {} fields, but it got a dict with {} fields.", struct_width, dict.len())
|
|
75
|
-
));
|
|
76
|
-
}
|
|
77
|
-
// we ignore the keys of the rest of the dicts
|
|
78
|
-
// the first item determines the output name
|
|
79
|
-
todo!()
|
|
80
|
-
// for ((_, val), field_items) in dict.iter().zip(&mut items) {
|
|
81
|
-
// let item = Wrap::<AnyValue>::try_convert(val)?;
|
|
82
|
-
// field_items.push(item.0)
|
|
83
|
-
// }
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
let fields = POOL.install(|| {
|
|
89
|
-
items
|
|
90
|
-
.par_iter()
|
|
91
|
-
.zip(flds)
|
|
92
|
-
.map(|(av, fld)| Series::new(fld.name().clone(), av))
|
|
93
|
-
.collect::<Vec<_>>()
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
Ok(
|
|
97
|
-
StructChunked::from_series(name, fields[0].len(), fields.iter())
|
|
98
|
-
.unwrap()
|
|
99
|
-
.into_series()
|
|
100
|
-
.into(),
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
fn iterator_to_primitive<T>(
|
|
105
|
-
it: impl Iterator<Item = Option<T::Native>>,
|
|
106
|
-
init_null_count: usize,
|
|
107
|
-
first_value: Option<T::Native>,
|
|
108
|
-
name: PlSmallStr,
|
|
109
|
-
capacity: usize,
|
|
110
|
-
) -> ChunkedArray<T>
|
|
111
|
-
where
|
|
112
|
-
T: RbArrowPrimitiveType,
|
|
113
|
-
{
|
|
114
|
-
// safety: we know the iterators len
|
|
115
|
-
let mut ca: ChunkedArray<T> = unsafe {
|
|
116
|
-
if init_null_count > 0 {
|
|
117
|
-
(0..init_null_count)
|
|
118
|
-
.map(|_| None)
|
|
119
|
-
.chain(std::iter::once(first_value))
|
|
120
|
-
.chain(it)
|
|
121
|
-
.trust_my_length(capacity)
|
|
122
|
-
.collect_trusted()
|
|
123
|
-
} else if first_value.is_some() {
|
|
124
|
-
std::iter::once(first_value)
|
|
125
|
-
.chain(it)
|
|
126
|
-
.trust_my_length(capacity)
|
|
127
|
-
.collect_trusted()
|
|
128
|
-
} else {
|
|
129
|
-
it.collect()
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
debug_assert_eq!(ca.len(), capacity);
|
|
133
|
-
ca.rename(name);
|
|
134
|
-
ca
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
fn iterator_to_bool(
|
|
138
|
-
it: impl Iterator<Item = Option<bool>>,
|
|
139
|
-
init_null_count: usize,
|
|
140
|
-
first_value: Option<bool>,
|
|
141
|
-
name: PlSmallStr,
|
|
142
|
-
capacity: usize,
|
|
143
|
-
) -> ChunkedArray<BooleanType> {
|
|
144
|
-
// safety: we know the iterators len
|
|
145
|
-
let mut ca: BooleanChunked = unsafe {
|
|
146
|
-
if init_null_count > 0 {
|
|
147
|
-
(0..init_null_count)
|
|
148
|
-
.map(|_| None)
|
|
149
|
-
.chain(std::iter::once(first_value))
|
|
150
|
-
.chain(it)
|
|
151
|
-
.trust_my_length(capacity)
|
|
152
|
-
.collect_trusted()
|
|
153
|
-
} else if first_value.is_some() {
|
|
154
|
-
std::iter::once(first_value)
|
|
155
|
-
.chain(it)
|
|
156
|
-
.trust_my_length(capacity)
|
|
157
|
-
.collect_trusted()
|
|
158
|
-
} else {
|
|
159
|
-
it.collect()
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
debug_assert_eq!(ca.len(), capacity);
|
|
163
|
-
ca.rename(name);
|
|
164
|
-
ca
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
fn iterator_to_object(
|
|
168
|
-
it: impl Iterator<Item = Option<ObjectValue>>,
|
|
169
|
-
init_null_count: usize,
|
|
170
|
-
first_value: Option<ObjectValue>,
|
|
171
|
-
name: PlSmallStr,
|
|
172
|
-
capacity: usize,
|
|
173
|
-
) -> ObjectChunked<ObjectValue> {
|
|
174
|
-
// safety: we know the iterators len
|
|
175
|
-
let mut ca: ObjectChunked<ObjectValue> = unsafe {
|
|
176
|
-
if init_null_count > 0 {
|
|
177
|
-
(0..init_null_count)
|
|
178
|
-
.map(|_| None)
|
|
179
|
-
.chain(std::iter::once(first_value))
|
|
180
|
-
.chain(it)
|
|
181
|
-
.trust_my_length(capacity)
|
|
182
|
-
.collect_trusted()
|
|
183
|
-
} else if first_value.is_some() {
|
|
184
|
-
std::iter::once(first_value)
|
|
185
|
-
.chain(it)
|
|
186
|
-
.trust_my_length(capacity)
|
|
187
|
-
.collect_trusted()
|
|
188
|
-
} else {
|
|
189
|
-
it.collect()
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
debug_assert_eq!(ca.len(), capacity);
|
|
193
|
-
ca.rename(name);
|
|
194
|
-
ca
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
fn iterator_to_utf8(
|
|
198
|
-
it: impl Iterator<Item = Option<String>>,
|
|
199
|
-
init_null_count: usize,
|
|
200
|
-
first_value: Option<&str>,
|
|
201
|
-
name: PlSmallStr,
|
|
202
|
-
capacity: usize,
|
|
203
|
-
) -> StringChunked {
|
|
204
|
-
let first_value = first_value.map(|v| v.to_string());
|
|
205
|
-
|
|
206
|
-
// safety: we know the iterators len
|
|
207
|
-
let mut ca: StringChunked = unsafe {
|
|
208
|
-
if init_null_count > 0 {
|
|
209
|
-
(0..init_null_count)
|
|
210
|
-
.map(|_| None)
|
|
211
|
-
.chain(std::iter::once(first_value))
|
|
212
|
-
.chain(it)
|
|
213
|
-
.trust_my_length(capacity)
|
|
214
|
-
.collect_trusted()
|
|
215
|
-
} else if first_value.is_some() {
|
|
216
|
-
std::iter::once(first_value)
|
|
217
|
-
.chain(it)
|
|
218
|
-
.trust_my_length(capacity)
|
|
219
|
-
.collect_trusted()
|
|
220
|
-
} else {
|
|
221
|
-
it.collect()
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
debug_assert_eq!(ca.len(), capacity);
|
|
225
|
-
ca.rename(name);
|
|
226
|
-
ca
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
fn iterator_to_list(
|
|
230
|
-
dt: &DataType,
|
|
231
|
-
it: impl Iterator<Item = Option<Series>>,
|
|
232
|
-
init_null_count: usize,
|
|
233
|
-
first_value: Option<&Series>,
|
|
234
|
-
name: PlSmallStr,
|
|
235
|
-
capacity: usize,
|
|
236
|
-
) -> RbResult<ListChunked> {
|
|
237
|
-
let mut builder = get_list_builder(dt, capacity * 5, capacity, name);
|
|
238
|
-
for _ in 0..init_null_count {
|
|
239
|
-
builder.append_null()
|
|
240
|
-
}
|
|
241
|
-
builder
|
|
242
|
-
.append_opt_series(first_value)
|
|
243
|
-
.map_err(RbPolarsErr::from)?;
|
|
244
|
-
for opt_val in it {
|
|
245
|
-
match opt_val {
|
|
246
|
-
None => builder.append_null(),
|
|
247
|
-
Some(s) => {
|
|
248
|
-
if s.len() == 0 && s.dtype() != dt {
|
|
249
|
-
builder
|
|
250
|
-
.append_series(&Series::full_null(PlSmallStr::EMPTY, 0, dt))
|
|
251
|
-
.unwrap()
|
|
252
|
-
} else {
|
|
253
|
-
builder.append_series(&s).map_err(RbPolarsErr::from)?
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
Ok(builder.finish())
|
|
259
|
-
}
|
|
7
|
+
use crate::{RbResult, RbSeries};
|
|
8
|
+
|
|
9
|
+
pub trait RbPolarsNumericType: PolarsNumericType {}
|
|
10
|
+
|
|
11
|
+
impl RbPolarsNumericType for UInt8Type {}
|
|
12
|
+
impl RbPolarsNumericType for UInt16Type {}
|
|
13
|
+
impl RbPolarsNumericType for UInt32Type {}
|
|
14
|
+
impl RbPolarsNumericType for UInt64Type {}
|
|
15
|
+
impl RbPolarsNumericType for UInt128Type {}
|
|
16
|
+
impl RbPolarsNumericType for Int8Type {}
|
|
17
|
+
impl RbPolarsNumericType for Int16Type {}
|
|
18
|
+
impl RbPolarsNumericType for Int32Type {}
|
|
19
|
+
impl RbPolarsNumericType for Int64Type {}
|
|
20
|
+
impl RbPolarsNumericType for Int128Type {}
|
|
21
|
+
impl RbPolarsNumericType for Float16Type {}
|
|
22
|
+
impl RbPolarsNumericType for Float32Type {}
|
|
23
|
+
impl RbPolarsNumericType for Float64Type {}
|