polars-df 0.19.0 → 0.21.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 +211 -320
- data/LICENSE.txt +1 -1
- data/ext/polars/Cargo.toml +13 -9
- data/ext/polars/src/batched_csv.rs +2 -2
- data/ext/polars/src/catalog/mod.rs +1 -0
- data/ext/polars/src/catalog/unity.rs +450 -0
- data/ext/polars/src/conversion/any_value.rs +9 -19
- data/ext/polars/src/conversion/categorical.rs +30 -0
- data/ext/polars/src/conversion/chunked_array.rs +8 -8
- data/ext/polars/src/conversion/mod.rs +187 -109
- data/ext/polars/src/dataframe/construction.rs +2 -2
- data/ext/polars/src/dataframe/export.rs +2 -2
- data/ext/polars/src/dataframe/general.rs +4 -2
- data/ext/polars/src/dataframe/io.rs +2 -2
- data/ext/polars/src/exceptions.rs +1 -1
- data/ext/polars/src/expr/datatype.rs +14 -0
- data/ext/polars/src/expr/general.rs +36 -44
- data/ext/polars/src/expr/list.rs +27 -17
- data/ext/polars/src/expr/meta.rs +18 -41
- data/ext/polars/src/expr/mod.rs +3 -1
- data/ext/polars/src/expr/name.rs +2 -2
- data/ext/polars/src/expr/rolling.rs +1 -1
- data/ext/polars/src/expr/selector.rs +219 -0
- data/ext/polars/src/expr/string.rs +14 -7
- data/ext/polars/src/file.rs +12 -6
- data/ext/polars/src/functions/io.rs +2 -11
- data/ext/polars/src/functions/lazy.rs +22 -54
- data/ext/polars/src/functions/meta.rs +2 -2
- data/ext/polars/src/functions/misc.rs +1 -1
- data/ext/polars/src/functions/range.rs +14 -10
- data/ext/polars/src/functions/string_cache.rs +4 -5
- data/ext/polars/src/interop/numo/numo_rs.rs +1 -1
- data/ext/polars/src/interop/numo/to_numo_series.rs +1 -1
- data/ext/polars/src/io/mod.rs +102 -0
- data/ext/polars/src/lazyframe/general.rs +75 -113
- data/ext/polars/src/lazyframe/serde.rs +1 -1
- data/ext/polars/src/lazyframe/sink.rs +6 -6
- data/ext/polars/src/lib.rs +104 -26
- data/ext/polars/src/map/dataframe.rs +7 -7
- data/ext/polars/src/map/lazy.rs +1 -1
- data/ext/polars/src/map/mod.rs +31 -19
- data/ext/polars/src/map/series.rs +8 -8
- data/ext/polars/src/on_startup.rs +5 -2
- data/ext/polars/src/rb_modules.rs +1 -1
- data/ext/polars/src/series/construction.rs +11 -7
- data/ext/polars/src/series/export.rs +6 -4
- data/ext/polars/src/series/general.rs +12 -207
- data/ext/polars/src/series/import.rs +2 -2
- data/ext/polars/src/series/map.rs +227 -0
- data/ext/polars/src/series/mod.rs +2 -1
- data/ext/polars/src/series/scatter.rs +1 -1
- data/ext/polars/src/utils.rs +10 -2
- data/lib/polars/cat_name_space.rb +3 -43
- 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/convert.rb +10 -0
- data/lib/polars/data_frame.rb +151 -30
- data/lib/polars/data_types.rb +47 -3
- data/lib/polars/exceptions.rb +7 -2
- data/lib/polars/expr.rb +48 -39
- data/lib/polars/functions/col.rb +6 -5
- data/lib/polars/functions/eager.rb +1 -1
- data/lib/polars/functions/lazy.rb +114 -15
- data/lib/polars/functions/repeat.rb +4 -0
- data/lib/polars/io/csv.rb +18 -0
- data/lib/polars/io/json.rb +16 -0
- data/lib/polars/io/ndjson.rb +13 -0
- data/lib/polars/io/parquet.rb +45 -63
- data/lib/polars/io/scan_options.rb +47 -0
- data/lib/polars/lazy_frame.rb +163 -75
- data/lib/polars/list_expr.rb +213 -17
- data/lib/polars/list_name_space.rb +121 -8
- data/lib/polars/meta_expr.rb +14 -29
- data/lib/polars/scan_cast_options.rb +64 -0
- data/lib/polars/schema.rb +6 -1
- data/lib/polars/selector.rb +138 -0
- data/lib/polars/selectors.rb +931 -202
- data/lib/polars/series.rb +46 -19
- data/lib/polars/string_expr.rb +24 -3
- data/lib/polars/string_name_space.rb +12 -1
- data/lib/polars/utils/parse.rb +40 -0
- data/lib/polars/utils.rb +5 -1
- data/lib/polars/version.rb +1 -1
- data/lib/polars.rb +8 -0
- metadata +17 -2
@@ -1,6 +1,6 @@
|
|
1
|
-
use magnus::{
|
1
|
+
use magnus::{IntoValue, RArray, TryConvert, Value, class, prelude::*, typed_data::Obj};
|
2
2
|
use polars::prelude::*;
|
3
|
-
use polars_core::frame::row::{
|
3
|
+
use polars_core::frame::row::{Row, rows_to_schema_first_non_null};
|
4
4
|
use polars_core::series::SeriesIter;
|
5
5
|
|
6
6
|
use super::*;
|
@@ -144,7 +144,7 @@ where
|
|
144
144
|
let tpl = (RArray::from_iter(iter),);
|
145
145
|
match lambda.funcall::<_, _, Value>("call", tpl) {
|
146
146
|
Ok(val) => T::try_convert(val).ok(),
|
147
|
-
Err(e) => panic!("ruby function failed {}"
|
147
|
+
Err(e) => panic!("ruby function failed {e}"),
|
148
148
|
}
|
149
149
|
})
|
150
150
|
}
|
@@ -157,7 +157,7 @@ pub fn apply_lambda_with_primitive_out_type<D>(
|
|
157
157
|
first_value: Option<D::Native>,
|
158
158
|
) -> ChunkedArray<D>
|
159
159
|
where
|
160
|
-
D:
|
160
|
+
D: RbPolarsNumericType,
|
161
161
|
D::Native: IntoValue + TryConvert,
|
162
162
|
{
|
163
163
|
let skip = usize::from(first_value.is_some());
|
@@ -247,11 +247,11 @@ pub fn apply_lambda_with_list_out_type(
|
|
247
247
|
if val.is_nil() {
|
248
248
|
None
|
249
249
|
} else {
|
250
|
-
panic!("should return a Series, got a {:?}"
|
250
|
+
panic!("should return a Series, got a {val:?}")
|
251
251
|
}
|
252
252
|
}
|
253
253
|
},
|
254
|
-
Err(e) => panic!("ruby function failed {}"
|
254
|
+
Err(e) => panic!("ruby function failed {e}"),
|
255
255
|
}
|
256
256
|
});
|
257
257
|
iterator_to_list(
|
@@ -302,7 +302,7 @@ pub fn apply_lambda_with_rows_output<'a>(
|
|
302
302
|
None => Ok(&null_row),
|
303
303
|
}
|
304
304
|
}
|
305
|
-
Err(e) => panic!("ruby function failed {}"
|
305
|
+
Err(e) => panic!("ruby function failed {e}"),
|
306
306
|
}
|
307
307
|
});
|
308
308
|
|
data/ext/polars/src/map/lazy.rs
CHANGED
data/ext/polars/src/map/mod.rs
CHANGED
@@ -2,27 +2,37 @@ pub mod dataframe;
|
|
2
2
|
pub mod lazy;
|
3
3
|
pub mod series;
|
4
4
|
|
5
|
-
use magnus::{
|
5
|
+
use magnus::{RHash, Value, prelude::*};
|
6
6
|
use polars::chunked_array::builder::get_list_builder;
|
7
7
|
use polars::prelude::*;
|
8
|
-
use polars_core::utils::CustomIterTools;
|
9
8
|
use polars_core::POOL;
|
9
|
+
use polars_core::utils::CustomIterTools;
|
10
10
|
use rayon::prelude::*;
|
11
11
|
|
12
|
-
use crate::{ObjectValue, RbPolarsErr, RbResult, RbSeries, Wrap};
|
12
|
+
use crate::{ObjectValue, RbPolarsErr, RbResult, RbSeries, RbValueError, Wrap};
|
13
|
+
|
14
|
+
pub trait RbPolarsNumericType: PolarsNumericType {}
|
13
15
|
|
14
|
-
|
16
|
+
impl RbPolarsNumericType for UInt8Type {}
|
17
|
+
impl RbPolarsNumericType for UInt16Type {}
|
18
|
+
impl RbPolarsNumericType for UInt32Type {}
|
19
|
+
impl RbPolarsNumericType for UInt64Type {}
|
20
|
+
impl RbPolarsNumericType for Int8Type {}
|
21
|
+
impl RbPolarsNumericType for Int16Type {}
|
22
|
+
impl RbPolarsNumericType for Int32Type {}
|
23
|
+
impl RbPolarsNumericType for Int64Type {}
|
24
|
+
impl RbPolarsNumericType for Float32Type {}
|
25
|
+
impl RbPolarsNumericType for Float64Type {}
|
15
26
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
impl RbArrowPrimitiveType for Float64Type {}
|
27
|
+
pub(super) fn check_nested_object(dt: &DataType) -> RbResult<()> {
|
28
|
+
if dt.contains_objects() {
|
29
|
+
Err(RbValueError::new_err(
|
30
|
+
"nested objects are not allowed\n\nSet `return_dtype: Polars::Object` to use Ruby's native nesting.",
|
31
|
+
))
|
32
|
+
} else {
|
33
|
+
Ok(())
|
34
|
+
}
|
35
|
+
}
|
26
36
|
|
27
37
|
fn iterator_to_struct(
|
28
38
|
it: impl Iterator<Item = Option<Value>>,
|
@@ -37,7 +47,7 @@ fn iterator_to_struct(
|
|
37
47
|
_ => {
|
38
48
|
return Err(crate::exceptions::ComputeError::new_err(format!(
|
39
49
|
"expected struct got {first_value:?}",
|
40
|
-
)))
|
50
|
+
)));
|
41
51
|
}
|
42
52
|
};
|
43
53
|
|
@@ -70,9 +80,11 @@ fn iterator_to_struct(
|
|
70
80
|
Some(dict) => {
|
71
81
|
let dict = RHash::try_convert(dict)?;
|
72
82
|
if dict.len() != struct_width {
|
73
|
-
return Err(crate::exceptions::ComputeError::new_err(
|
74
|
-
|
75
|
-
|
83
|
+
return Err(crate::exceptions::ComputeError::new_err(format!(
|
84
|
+
"Cannot create struct type.\n> The struct dtype expects {} fields, but it got a dict with {} fields.",
|
85
|
+
struct_width,
|
86
|
+
dict.len()
|
87
|
+
)));
|
76
88
|
}
|
77
89
|
// we ignore the keys of the rest of the dicts
|
78
90
|
// the first item determines the output name
|
@@ -109,7 +121,7 @@ fn iterator_to_primitive<T>(
|
|
109
121
|
capacity: usize,
|
110
122
|
) -> ChunkedArray<T>
|
111
123
|
where
|
112
|
-
T:
|
124
|
+
T: RbPolarsNumericType,
|
113
125
|
{
|
114
126
|
// safety: we know the iterators len
|
115
127
|
let mut ca: ChunkedArray<T> = unsafe {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
use magnus::{class, prelude::*, typed_data::Obj
|
1
|
+
use magnus::{IntoValue, TryConvert, Value, class, prelude::*, typed_data::Obj};
|
2
2
|
use polars::prelude::*;
|
3
3
|
|
4
4
|
use super::*;
|
@@ -85,7 +85,7 @@ pub trait ApplyLambda<'a> {
|
|
85
85
|
first_value: Option<D::Native>,
|
86
86
|
) -> RbResult<ChunkedArray<D>>
|
87
87
|
where
|
88
|
-
D:
|
88
|
+
D: RbPolarsNumericType,
|
89
89
|
D::Native: IntoValue + TryConvert;
|
90
90
|
|
91
91
|
/// Apply a lambda with a boolean output type
|
@@ -143,7 +143,7 @@ where
|
|
143
143
|
{
|
144
144
|
match call_lambda(lambda, in_val) {
|
145
145
|
Ok(out) => S::try_convert(out),
|
146
|
-
Err(e) => panic!("ruby function failed {}"
|
146
|
+
Err(e) => panic!("ruby function failed {e}"),
|
147
147
|
}
|
148
148
|
}
|
149
149
|
|
@@ -219,7 +219,7 @@ impl<'a> ApplyLambda<'a> for BooleanChunked {
|
|
219
219
|
first_value: Option<D::Native>,
|
220
220
|
) -> RbResult<ChunkedArray<D>>
|
221
221
|
where
|
222
|
-
D:
|
222
|
+
D: RbPolarsNumericType,
|
223
223
|
D::Native: IntoValue + TryConvert,
|
224
224
|
{
|
225
225
|
let skip = usize::from(first_value.is_some());
|
@@ -438,7 +438,7 @@ impl<'a> ApplyLambda<'a> for BooleanChunked {
|
|
438
438
|
|
439
439
|
impl<'a, T> ApplyLambda<'a> for ChunkedArray<T>
|
440
440
|
where
|
441
|
-
T:
|
441
|
+
T: RbPolarsNumericType + PolarsNumericType,
|
442
442
|
T::Native: IntoValue + TryConvert,
|
443
443
|
ChunkedArray<T>: IntoSeries,
|
444
444
|
{
|
@@ -503,7 +503,7 @@ where
|
|
503
503
|
first_value: Option<D::Native>,
|
504
504
|
) -> RbResult<ChunkedArray<D>>
|
505
505
|
where
|
506
|
-
D:
|
506
|
+
D: RbPolarsNumericType,
|
507
507
|
D::Native: IntoValue + TryConvert,
|
508
508
|
{
|
509
509
|
let skip = usize::from(first_value.is_some());
|
@@ -782,7 +782,7 @@ impl<'a> ApplyLambda<'a> for StringChunked {
|
|
782
782
|
first_value: Option<D::Native>,
|
783
783
|
) -> RbResult<ChunkedArray<D>>
|
784
784
|
where
|
785
|
-
D:
|
785
|
+
D: RbPolarsNumericType,
|
786
786
|
D::Native: IntoValue + TryConvert,
|
787
787
|
{
|
788
788
|
let skip = usize::from(first_value.is_some());
|
@@ -1047,7 +1047,7 @@ impl<'a> ApplyLambda<'a> for StructChunked {
|
|
1047
1047
|
first_value: Option<D::Native>,
|
1048
1048
|
) -> RbResult<ChunkedArray<D>>
|
1049
1049
|
where
|
1050
|
-
D:
|
1050
|
+
D: RbPolarsNumericType,
|
1051
1051
|
D::Native: IntoValue + TryConvert,
|
1052
1052
|
{
|
1053
1053
|
let skip = usize::from(first_value.is_some());
|
@@ -9,8 +9,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
11
|
|
12
|
-
use crate::prelude::ObjectValue;
|
13
12
|
use crate::Wrap;
|
13
|
+
use crate::prelude::ObjectValue;
|
14
14
|
|
15
15
|
static POLARS_REGISTRY_INIT_LOCK: OnceLock<()> = OnceLock::new();
|
16
16
|
|
@@ -39,6 +39,9 @@ pub(crate) fn register_startup_deps() {
|
|
39
39
|
object_converter,
|
40
40
|
rbobject_converter,
|
41
41
|
physical_dtype,
|
42
|
-
)
|
42
|
+
);
|
43
|
+
// TODO
|
44
|
+
// Register warning function for `polars_warn!`.
|
45
|
+
// polars_error::set_warning_function(warning_function);
|
43
46
|
});
|
44
47
|
}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
use magnus::{
|
1
|
+
use magnus::{RArray, RString, prelude::*};
|
2
2
|
use polars_core::prelude::*;
|
3
3
|
|
4
4
|
use crate::any_value::rb_object_to_any_value;
|
5
|
-
use crate::conversion::{slice_extract_wrapped, vec_extract_wrapped
|
5
|
+
use crate::conversion::{Wrap, slice_extract_wrapped, vec_extract_wrapped};
|
6
6
|
use crate::prelude::ObjectValue;
|
7
7
|
use crate::series::to_series;
|
8
8
|
use crate::{RbPolarsErr, RbResult, RbSeries, RbTypeError, RbValueError};
|
@@ -122,13 +122,17 @@ impl RbSeries {
|
|
122
122
|
.into_iter()
|
123
123
|
.map(|v| rb_object_to_any_value(v, strict))
|
124
124
|
.collect::<RbResult<Vec<AnyValue>>>()?;
|
125
|
-
let s =
|
126
|
-
|
127
|
-
|
128
|
-
|
125
|
+
let s = Series::from_any_values_and_dtype(
|
126
|
+
name.into(),
|
127
|
+
any_values.as_slice(),
|
128
|
+
&dtype.0,
|
129
|
+
strict,
|
130
|
+
)
|
131
|
+
.map_err(|e| {
|
132
|
+
RbTypeError::new_err(format!(
|
129
133
|
"{e}\n\nHint: Try setting `strict: false` to allow passing data with mixed types."
|
130
134
|
))
|
131
|
-
|
135
|
+
})?;
|
132
136
|
Ok(s.into())
|
133
137
|
}
|
134
138
|
|
@@ -1,8 +1,8 @@
|
|
1
|
-
use magnus::{
|
1
|
+
use magnus::{IntoValue, RArray, Value, value::qnil};
|
2
2
|
use polars_core::prelude::*;
|
3
3
|
|
4
|
-
use crate::prelude::*;
|
5
4
|
use crate::RbSeries;
|
5
|
+
use crate::prelude::*;
|
6
6
|
|
7
7
|
impl RbSeries {
|
8
8
|
/// Convert this Series to a Ruby array.
|
@@ -25,7 +25,9 @@ impl RbSeries {
|
|
25
25
|
DataType::Float32 => RArray::from_iter(series.f32().unwrap()).into_value(),
|
26
26
|
DataType::Float64 => RArray::from_iter(series.f64().unwrap()).into_value(),
|
27
27
|
DataType::Categorical(_, _) | DataType::Enum(_, _) => {
|
28
|
-
|
28
|
+
with_match_categorical_physical_type!(series.dtype().cat_physical().unwrap(), |$C| {
|
29
|
+
RArray::from_iter(series.cat::<$C>().unwrap().iter_str()).into_value()
|
30
|
+
})
|
29
31
|
}
|
30
32
|
DataType::Object(_) => {
|
31
33
|
let v = RArray::with_capacity(series.len());
|
@@ -132,7 +134,7 @@ impl RbSeries {
|
|
132
134
|
unreachable!()
|
133
135
|
}
|
134
136
|
};
|
135
|
-
rblist
|
137
|
+
rblist.into_value()
|
136
138
|
}
|
137
139
|
|
138
140
|
to_a_recursive(series)
|
@@ -1,10 +1,8 @@
|
|
1
|
-
use magnus::{
|
1
|
+
use magnus::{Error, IntoValue, Value, exception};
|
2
2
|
use polars::prelude::*;
|
3
3
|
use polars::series::IsSorted;
|
4
4
|
|
5
|
-
use crate::apply_method_all_arrow_series2;
|
6
5
|
use crate::conversion::*;
|
7
|
-
use crate::map::series::{call_lambda_and_extract, ApplyLambda};
|
8
6
|
use crate::{RbDataFrame, RbPolarsErr, RbResult, RbSeries};
|
9
7
|
|
10
8
|
impl RbSeries {
|
@@ -42,21 +40,15 @@ impl RbSeries {
|
|
42
40
|
}
|
43
41
|
|
44
42
|
pub fn cat_uses_lexical_ordering(&self) -> RbResult<bool> {
|
45
|
-
|
46
|
-
let ca = binding.categorical().map_err(RbPolarsErr::from)?;
|
47
|
-
Ok(ca.uses_lexical_ordering())
|
43
|
+
Ok(true)
|
48
44
|
}
|
49
45
|
|
50
46
|
pub fn cat_is_local(&self) -> RbResult<bool> {
|
51
|
-
|
52
|
-
let ca = binding.categorical().map_err(RbPolarsErr::from)?;
|
53
|
-
Ok(ca.get_rev_map().is_local())
|
47
|
+
Ok(false)
|
54
48
|
}
|
55
49
|
|
56
50
|
pub fn cat_to_local(&self) -> RbResult<Self> {
|
57
|
-
|
58
|
-
let ca = binding.categorical().map_err(RbPolarsErr::from)?;
|
59
|
-
Ok(ca.to_local().into_series().into())
|
51
|
+
Ok(self.clone())
|
60
52
|
}
|
61
53
|
|
62
54
|
pub fn estimated_size(&self) -> usize {
|
@@ -75,7 +67,7 @@ impl RbSeries {
|
|
75
67
|
if val == v_trunc {
|
76
68
|
val
|
77
69
|
} else {
|
78
|
-
format!("{}…"
|
70
|
+
format!("{v_trunc}…")
|
79
71
|
}
|
80
72
|
} else {
|
81
73
|
val
|
@@ -305,198 +297,6 @@ impl RbSeries {
|
|
305
297
|
RbSeries::new(self.series.borrow().clone())
|
306
298
|
}
|
307
299
|
|
308
|
-
pub fn apply_lambda(
|
309
|
-
&self,
|
310
|
-
lambda: Value,
|
311
|
-
output_type: Option<Wrap<DataType>>,
|
312
|
-
skip_nulls: bool,
|
313
|
-
) -> RbResult<Self> {
|
314
|
-
let series = &self.series.borrow();
|
315
|
-
|
316
|
-
let output_type = output_type.map(|dt| dt.0);
|
317
|
-
|
318
|
-
macro_rules! dispatch_apply {
|
319
|
-
($self:expr, $method:ident, $($args:expr),*) => {
|
320
|
-
if matches!($self.dtype(), DataType::Object(_)) {
|
321
|
-
// let ca = $self.0.unpack::<ObjectType<ObjectValue>>().unwrap();
|
322
|
-
// ca.$method($($args),*)
|
323
|
-
todo!()
|
324
|
-
} else {
|
325
|
-
apply_method_all_arrow_series2!(
|
326
|
-
$self,
|
327
|
-
$method,
|
328
|
-
$($args),*
|
329
|
-
)
|
330
|
-
}
|
331
|
-
|
332
|
-
}
|
333
|
-
|
334
|
-
}
|
335
|
-
|
336
|
-
if matches!(
|
337
|
-
series.dtype(),
|
338
|
-
DataType::Datetime(_, _)
|
339
|
-
| DataType::Date
|
340
|
-
| DataType::Duration(_)
|
341
|
-
| DataType::Categorical(_, _)
|
342
|
-
| DataType::Time
|
343
|
-
) || !skip_nulls
|
344
|
-
{
|
345
|
-
let mut avs = Vec::with_capacity(series.len());
|
346
|
-
let iter = series.iter().map(|av| {
|
347
|
-
let input = Wrap(av);
|
348
|
-
call_lambda_and_extract::<_, Wrap<AnyValue>>(lambda, input)
|
349
|
-
.unwrap()
|
350
|
-
.0
|
351
|
-
});
|
352
|
-
avs.extend(iter);
|
353
|
-
return Ok(Series::new(self.name().into(), &avs).into());
|
354
|
-
}
|
355
|
-
|
356
|
-
let out = match output_type {
|
357
|
-
Some(DataType::Int8) => {
|
358
|
-
let ca: Int8Chunked = dispatch_apply!(
|
359
|
-
series,
|
360
|
-
apply_lambda_with_primitive_out_type,
|
361
|
-
lambda,
|
362
|
-
0,
|
363
|
-
None
|
364
|
-
)?;
|
365
|
-
ca.into_series()
|
366
|
-
}
|
367
|
-
Some(DataType::Int16) => {
|
368
|
-
let ca: Int16Chunked = dispatch_apply!(
|
369
|
-
series,
|
370
|
-
apply_lambda_with_primitive_out_type,
|
371
|
-
lambda,
|
372
|
-
0,
|
373
|
-
None
|
374
|
-
)?;
|
375
|
-
ca.into_series()
|
376
|
-
}
|
377
|
-
Some(DataType::Int32) => {
|
378
|
-
let ca: Int32Chunked = dispatch_apply!(
|
379
|
-
series,
|
380
|
-
apply_lambda_with_primitive_out_type,
|
381
|
-
lambda,
|
382
|
-
0,
|
383
|
-
None
|
384
|
-
)?;
|
385
|
-
ca.into_series()
|
386
|
-
}
|
387
|
-
Some(DataType::Int64) => {
|
388
|
-
let ca: Int64Chunked = dispatch_apply!(
|
389
|
-
series,
|
390
|
-
apply_lambda_with_primitive_out_type,
|
391
|
-
lambda,
|
392
|
-
0,
|
393
|
-
None
|
394
|
-
)?;
|
395
|
-
ca.into_series()
|
396
|
-
}
|
397
|
-
Some(DataType::UInt8) => {
|
398
|
-
let ca: UInt8Chunked = dispatch_apply!(
|
399
|
-
series,
|
400
|
-
apply_lambda_with_primitive_out_type,
|
401
|
-
lambda,
|
402
|
-
0,
|
403
|
-
None
|
404
|
-
)?;
|
405
|
-
ca.into_series()
|
406
|
-
}
|
407
|
-
Some(DataType::UInt16) => {
|
408
|
-
let ca: UInt16Chunked = dispatch_apply!(
|
409
|
-
series,
|
410
|
-
apply_lambda_with_primitive_out_type,
|
411
|
-
lambda,
|
412
|
-
0,
|
413
|
-
None
|
414
|
-
)?;
|
415
|
-
ca.into_series()
|
416
|
-
}
|
417
|
-
Some(DataType::UInt32) => {
|
418
|
-
let ca: UInt32Chunked = dispatch_apply!(
|
419
|
-
series,
|
420
|
-
apply_lambda_with_primitive_out_type,
|
421
|
-
lambda,
|
422
|
-
0,
|
423
|
-
None
|
424
|
-
)?;
|
425
|
-
ca.into_series()
|
426
|
-
}
|
427
|
-
Some(DataType::UInt64) => {
|
428
|
-
let ca: UInt64Chunked = dispatch_apply!(
|
429
|
-
series,
|
430
|
-
apply_lambda_with_primitive_out_type,
|
431
|
-
lambda,
|
432
|
-
0,
|
433
|
-
None
|
434
|
-
)?;
|
435
|
-
ca.into_series()
|
436
|
-
}
|
437
|
-
Some(DataType::Float32) => {
|
438
|
-
let ca: Float32Chunked = dispatch_apply!(
|
439
|
-
series,
|
440
|
-
apply_lambda_with_primitive_out_type,
|
441
|
-
lambda,
|
442
|
-
0,
|
443
|
-
None
|
444
|
-
)?;
|
445
|
-
ca.into_series()
|
446
|
-
}
|
447
|
-
Some(DataType::Float64) => {
|
448
|
-
let ca: Float64Chunked = dispatch_apply!(
|
449
|
-
series,
|
450
|
-
apply_lambda_with_primitive_out_type,
|
451
|
-
lambda,
|
452
|
-
0,
|
453
|
-
None
|
454
|
-
)?;
|
455
|
-
ca.into_series()
|
456
|
-
}
|
457
|
-
Some(DataType::Boolean) => {
|
458
|
-
let ca: BooleanChunked =
|
459
|
-
dispatch_apply!(series, apply_lambda_with_bool_out_type, lambda, 0, None)?;
|
460
|
-
ca.into_series()
|
461
|
-
}
|
462
|
-
Some(DataType::Date) => {
|
463
|
-
let ca: Int32Chunked = dispatch_apply!(
|
464
|
-
series,
|
465
|
-
apply_lambda_with_primitive_out_type,
|
466
|
-
lambda,
|
467
|
-
0,
|
468
|
-
None
|
469
|
-
)?;
|
470
|
-
ca.into_date().into_series()
|
471
|
-
}
|
472
|
-
Some(DataType::Datetime(tu, tz)) => {
|
473
|
-
let ca: Int64Chunked = dispatch_apply!(
|
474
|
-
series,
|
475
|
-
apply_lambda_with_primitive_out_type,
|
476
|
-
lambda,
|
477
|
-
0,
|
478
|
-
None
|
479
|
-
)?;
|
480
|
-
ca.into_datetime(tu, tz).into_series()
|
481
|
-
}
|
482
|
-
Some(DataType::String) => {
|
483
|
-
let ca = dispatch_apply!(series, apply_lambda_with_utf8_out_type, lambda, 0, None)?;
|
484
|
-
|
485
|
-
ca.into_series()
|
486
|
-
}
|
487
|
-
Some(DataType::Object(_)) => {
|
488
|
-
let ca =
|
489
|
-
dispatch_apply!(series, apply_lambda_with_object_out_type, lambda, 0, None)?;
|
490
|
-
ca.into_series()
|
491
|
-
}
|
492
|
-
None => return dispatch_apply!(series, apply_lambda_unknown, lambda),
|
493
|
-
|
494
|
-
_ => return dispatch_apply!(series, apply_lambda_unknown, lambda),
|
495
|
-
};
|
496
|
-
|
497
|
-
Ok(RbSeries::new(out))
|
498
|
-
}
|
499
|
-
|
500
300
|
pub fn zip_with(&self, mask: &RbSeries, other: &RbSeries) -> RbResult<Self> {
|
501
301
|
let binding = mask.series.borrow();
|
502
302
|
let mask = binding.bool().map_err(RbPolarsErr::from)?;
|
@@ -508,11 +308,16 @@ impl RbSeries {
|
|
508
308
|
Ok(RbSeries::new(s))
|
509
309
|
}
|
510
310
|
|
511
|
-
pub fn to_dummies(
|
311
|
+
pub fn to_dummies(
|
312
|
+
&self,
|
313
|
+
sep: Option<String>,
|
314
|
+
drop_first: bool,
|
315
|
+
drop_nulls: bool,
|
316
|
+
) -> RbResult<RbDataFrame> {
|
512
317
|
let df = self
|
513
318
|
.series
|
514
319
|
.borrow()
|
515
|
-
.to_dummies(sep.as_deref(), drop_first)
|
320
|
+
.to_dummies(sep.as_deref(), drop_first, drop_nulls)
|
516
321
|
.map_err(RbPolarsErr::from)?;
|
517
322
|
Ok(df.into())
|
518
323
|
}
|
@@ -1,13 +1,13 @@
|
|
1
1
|
use arrow::array::Array;
|
2
2
|
use arrow::ffi::{ArrowArrayStream, ArrowArrayStreamReader};
|
3
|
-
use magnus::prelude::*;
|
4
3
|
use magnus::Value;
|
4
|
+
use magnus::prelude::*;
|
5
5
|
use polars::prelude::*;
|
6
6
|
|
7
7
|
use super::RbSeries;
|
8
8
|
|
9
|
-
use crate::exceptions::RbValueError;
|
10
9
|
use crate::RbResult;
|
10
|
+
use crate::exceptions::RbValueError;
|
11
11
|
|
12
12
|
/// Import `arrow_c_stream` across Ruby boundary.
|
13
13
|
fn call_arrow_c_stream(ob: Value) -> RbResult<Value> {
|