polars-df 0.7.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -0
- data/Cargo.lock +353 -237
- data/Cargo.toml +0 -3
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/ext/polars/Cargo.toml +17 -6
- data/ext/polars/src/batched_csv.rs +6 -7
- data/ext/polars/src/conversion/anyvalue.rs +185 -0
- data/ext/polars/src/conversion/chunked_array.rs +140 -0
- data/ext/polars/src/{conversion.rs → conversion/mod.rs} +268 -347
- data/ext/polars/src/dataframe.rs +96 -116
- data/ext/polars/src/expr/array.rs +74 -0
- data/ext/polars/src/expr/categorical.rs +8 -1
- data/ext/polars/src/expr/datetime.rs +22 -56
- data/ext/polars/src/expr/general.rs +124 -37
- data/ext/polars/src/expr/list.rs +52 -4
- data/ext/polars/src/expr/meta.rs +48 -0
- data/ext/polars/src/expr/rolling.rs +16 -10
- data/ext/polars/src/expr/string.rs +68 -17
- data/ext/polars/src/expr/struct.rs +8 -4
- data/ext/polars/src/functions/aggregation.rs +6 -0
- data/ext/polars/src/functions/lazy.rs +103 -48
- data/ext/polars/src/functions/meta.rs +45 -1
- data/ext/polars/src/functions/range.rs +5 -10
- data/ext/polars/src/functions/string_cache.rs +14 -0
- data/ext/polars/src/{lazyframe.rs → lazyframe/mod.rs} +166 -41
- data/ext/polars/src/lib.rs +245 -187
- data/ext/polars/src/map/dataframe.rs +1 -1
- data/ext/polars/src/map/mod.rs +2 -2
- data/ext/polars/src/map/series.rs +6 -6
- data/ext/polars/src/object.rs +0 -30
- data/ext/polars/src/on_startup.rs +32 -0
- data/ext/polars/src/series/aggregation.rs +23 -0
- data/ext/polars/src/series/construction.rs +1 -1
- data/ext/polars/src/series/export.rs +2 -2
- data/ext/polars/src/{series.rs → series/mod.rs} +45 -21
- data/ext/polars/src/series/{set_at_idx.rs → scatter.rs} +18 -18
- data/ext/polars/src/utils.rs +1 -1
- data/lib/polars/array_expr.rb +449 -0
- data/lib/polars/array_name_space.rb +346 -0
- data/lib/polars/cat_expr.rb +24 -0
- data/lib/polars/cat_name_space.rb +75 -0
- data/lib/polars/config.rb +2 -2
- data/lib/polars/data_frame.rb +248 -108
- data/lib/polars/data_types.rb +195 -29
- data/lib/polars/date_time_expr.rb +41 -24
- data/lib/polars/date_time_name_space.rb +12 -12
- data/lib/polars/exceptions.rb +12 -1
- data/lib/polars/expr.rb +1080 -195
- data/lib/polars/functions/aggregation/horizontal.rb +246 -0
- data/lib/polars/functions/aggregation/vertical.rb +282 -0
- data/lib/polars/functions/as_datatype.rb +248 -0
- data/lib/polars/functions/col.rb +47 -0
- data/lib/polars/functions/eager.rb +182 -0
- data/lib/polars/functions/lazy.rb +1280 -0
- data/lib/polars/functions/len.rb +49 -0
- data/lib/polars/functions/lit.rb +35 -0
- data/lib/polars/functions/random.rb +16 -0
- data/lib/polars/functions/range/date_range.rb +103 -0
- data/lib/polars/functions/range/int_range.rb +51 -0
- data/lib/polars/functions/repeat.rb +144 -0
- data/lib/polars/functions/whenthen.rb +27 -0
- data/lib/polars/functions.rb +29 -416
- data/lib/polars/group_by.rb +3 -3
- data/lib/polars/io.rb +21 -28
- data/lib/polars/lazy_frame.rb +390 -76
- data/lib/polars/list_expr.rb +152 -6
- data/lib/polars/list_name_space.rb +102 -0
- data/lib/polars/meta_expr.rb +175 -7
- data/lib/polars/series.rb +557 -59
- data/lib/polars/sql_context.rb +1 -1
- data/lib/polars/string_cache.rb +75 -0
- data/lib/polars/string_expr.rb +412 -96
- data/lib/polars/string_name_space.rb +4 -4
- data/lib/polars/struct_expr.rb +1 -1
- data/lib/polars/struct_name_space.rb +1 -1
- data/lib/polars/testing.rb +507 -0
- data/lib/polars/utils.rb +64 -20
- data/lib/polars/version.rb +1 -1
- data/lib/polars.rb +15 -2
- metadata +40 -9
- data/lib/polars/lazy_functions.rb +0 -1197
@@ -1,7 +1,7 @@
|
|
1
1
|
use polars::prelude::*;
|
2
2
|
|
3
3
|
use crate::conversion::Wrap;
|
4
|
-
use crate::RbExpr;
|
4
|
+
use crate::{RbExpr, RbPolarsErr, RbResult};
|
5
5
|
|
6
6
|
impl RbExpr {
|
7
7
|
pub fn str_concat(&self, delimiter: String, ignore_nulls: bool) -> Self {
|
@@ -107,8 +107,12 @@ impl RbExpr {
|
|
107
107
|
.into()
|
108
108
|
}
|
109
109
|
|
110
|
-
pub fn str_slice(&self, start:
|
111
|
-
self.inner
|
110
|
+
pub fn str_slice(&self, start: &Self, length: &Self) -> Self {
|
111
|
+
self.inner
|
112
|
+
.clone()
|
113
|
+
.str()
|
114
|
+
.slice(start.inner.clone(), length.inner.clone())
|
115
|
+
.into()
|
112
116
|
}
|
113
117
|
|
114
118
|
pub fn str_explode(&self) -> Self {
|
@@ -147,6 +151,10 @@ impl RbExpr {
|
|
147
151
|
.into()
|
148
152
|
}
|
149
153
|
|
154
|
+
pub fn str_reverse(&self) -> Self {
|
155
|
+
self.inner.clone().str().reverse().into()
|
156
|
+
}
|
157
|
+
|
150
158
|
pub fn str_pad_start(&self, length: usize, fillchar: char) -> Self {
|
151
159
|
self.clone().inner.str().pad_start(length, fillchar).into()
|
152
160
|
}
|
@@ -155,8 +163,8 @@ impl RbExpr {
|
|
155
163
|
self.clone().inner.str().pad_end(length, fillchar).into()
|
156
164
|
}
|
157
165
|
|
158
|
-
pub fn str_zfill(&self,
|
159
|
-
self.clone().inner.str().zfill(
|
166
|
+
pub fn str_zfill(&self, length: &Self) -> Self {
|
167
|
+
self.clone().inner.str().zfill(length.inner.clone()).into()
|
160
168
|
}
|
161
169
|
|
162
170
|
pub fn str_contains(&self, pat: &RbExpr, literal: Option<bool>, strict: bool) -> Self {
|
@@ -192,7 +200,7 @@ impl RbExpr {
|
|
192
200
|
self.clone()
|
193
201
|
.inner
|
194
202
|
.map(
|
195
|
-
move |s| s.
|
203
|
+
move |s| s.str().map(|s| Some(s.hex_encode().into_series())),
|
196
204
|
GetOutput::same_type(),
|
197
205
|
)
|
198
206
|
.with_fmt("str.hex_encode")
|
@@ -203,7 +211,7 @@ impl RbExpr {
|
|
203
211
|
self.clone()
|
204
212
|
.inner
|
205
213
|
.map(
|
206
|
-
move |s| s.
|
214
|
+
move |s| s.str()?.hex_decode(strict).map(|s| Some(s.into_series())),
|
207
215
|
GetOutput::same_type(),
|
208
216
|
)
|
209
217
|
.with_fmt("str.hex_decode")
|
@@ -214,7 +222,7 @@ impl RbExpr {
|
|
214
222
|
self.clone()
|
215
223
|
.inner
|
216
224
|
.map(
|
217
|
-
move |s| s.
|
225
|
+
move |s| s.str().map(|s| Some(s.base64_encode().into_series())),
|
218
226
|
GetOutput::same_type(),
|
219
227
|
)
|
220
228
|
.with_fmt("str.base64_encode")
|
@@ -226,7 +234,7 @@ impl RbExpr {
|
|
226
234
|
.inner
|
227
235
|
.map(
|
228
236
|
move |s| {
|
229
|
-
s.
|
237
|
+
s.str()?
|
230
238
|
.base64_decode(strict)
|
231
239
|
.map(|s| Some(s.into_series()))
|
232
240
|
},
|
@@ -245,7 +253,7 @@ impl RbExpr {
|
|
245
253
|
.into()
|
246
254
|
}
|
247
255
|
|
248
|
-
pub fn
|
256
|
+
pub fn str_json_decode(
|
249
257
|
&self,
|
250
258
|
dtype: Option<Wrap<DataType>>,
|
251
259
|
infer_schema_len: Option<usize>,
|
@@ -258,8 +266,8 @@ impl RbExpr {
|
|
258
266
|
};
|
259
267
|
|
260
268
|
let function = move |s: Series| {
|
261
|
-
let ca = s.
|
262
|
-
match ca.
|
269
|
+
let ca = s.str()?;
|
270
|
+
match ca.json_decode(dtype.clone(), infer_schema_len) {
|
263
271
|
Ok(ca) => Ok(Some(ca.into_series())),
|
264
272
|
Err(e) => Err(PolarsError::ComputeError(format!("{e:?}").into())),
|
265
273
|
}
|
@@ -268,13 +276,13 @@ impl RbExpr {
|
|
268
276
|
self.clone()
|
269
277
|
.inner
|
270
278
|
.map(function, output_type)
|
271
|
-
.with_fmt("str.
|
279
|
+
.with_fmt("str.json_decode")
|
272
280
|
.into()
|
273
281
|
}
|
274
282
|
|
275
283
|
pub fn str_json_path_match(&self, pat: String) -> Self {
|
276
284
|
let function = move |s: Series| {
|
277
|
-
let ca = s.
|
285
|
+
let ca = s.str()?;
|
278
286
|
match ca.json_path_match(&pat) {
|
279
287
|
Ok(ca) => Ok(Some(ca.into_series())),
|
280
288
|
Err(e) => Err(PolarsError::ComputeError(format!("{:?}", e).into())),
|
@@ -282,13 +290,17 @@ impl RbExpr {
|
|
282
290
|
};
|
283
291
|
self.clone()
|
284
292
|
.inner
|
285
|
-
.map(function, GetOutput::from_type(DataType::
|
293
|
+
.map(function, GetOutput::from_type(DataType::String))
|
286
294
|
.with_fmt("str.json_path_match")
|
287
295
|
.into()
|
288
296
|
}
|
289
297
|
|
290
|
-
pub fn str_extract(&self, pat:
|
291
|
-
self.inner
|
298
|
+
pub fn str_extract(&self, pat: &Self, group_index: usize) -> Self {
|
299
|
+
self.inner
|
300
|
+
.clone()
|
301
|
+
.str()
|
302
|
+
.extract(pat.inner.clone(), group_index)
|
303
|
+
.into()
|
292
304
|
}
|
293
305
|
|
294
306
|
pub fn str_extract_all(&self, pat: &RbExpr) -> Self {
|
@@ -299,6 +311,16 @@ impl RbExpr {
|
|
299
311
|
.into()
|
300
312
|
}
|
301
313
|
|
314
|
+
pub fn str_extract_groups(&self, pat: String) -> RbResult<Self> {
|
315
|
+
Ok(self
|
316
|
+
.inner
|
317
|
+
.clone()
|
318
|
+
.str()
|
319
|
+
.extract_groups(&pat)
|
320
|
+
.map_err(RbPolarsErr::from)?
|
321
|
+
.into())
|
322
|
+
}
|
323
|
+
|
302
324
|
pub fn str_count_matches(&self, pat: &Self, literal: bool) -> Self {
|
303
325
|
self.inner
|
304
326
|
.clone()
|
@@ -338,4 +360,33 @@ impl RbExpr {
|
|
338
360
|
pub fn str_splitn(&self, by: &Self, n: usize) -> Self {
|
339
361
|
self.inner.clone().str().splitn(by.inner.clone(), n).into()
|
340
362
|
}
|
363
|
+
|
364
|
+
pub fn str_to_decimal(&self, infer_len: usize) -> Self {
|
365
|
+
self.inner.clone().str().to_decimal(infer_len).into()
|
366
|
+
}
|
367
|
+
|
368
|
+
pub fn str_contains_any(&self, patterns: &RbExpr, ascii_case_insensitive: bool) -> Self {
|
369
|
+
self.inner
|
370
|
+
.clone()
|
371
|
+
.str()
|
372
|
+
.contains_any(patterns.inner.clone(), ascii_case_insensitive)
|
373
|
+
.into()
|
374
|
+
}
|
375
|
+
|
376
|
+
pub fn str_replace_many(
|
377
|
+
&self,
|
378
|
+
patterns: &RbExpr,
|
379
|
+
replace_with: &RbExpr,
|
380
|
+
ascii_case_insensitive: bool,
|
381
|
+
) -> Self {
|
382
|
+
self.inner
|
383
|
+
.clone()
|
384
|
+
.str()
|
385
|
+
.replace_many(
|
386
|
+
patterns.inner.clone(),
|
387
|
+
replace_with.inner.clone(),
|
388
|
+
ascii_case_insensitive,
|
389
|
+
)
|
390
|
+
.into()
|
391
|
+
}
|
341
392
|
}
|
@@ -1,15 +1,19 @@
|
|
1
1
|
use crate::RbExpr;
|
2
2
|
|
3
3
|
impl RbExpr {
|
4
|
-
pub fn struct_field_by_name(&self, name: String) -> Self {
|
5
|
-
self.inner.clone().struct_().field_by_name(&name).into()
|
6
|
-
}
|
7
|
-
|
8
4
|
pub fn struct_field_by_index(&self, index: i64) -> Self {
|
9
5
|
self.inner.clone().struct_().field_by_index(index).into()
|
10
6
|
}
|
11
7
|
|
8
|
+
pub fn struct_field_by_name(&self, name: String) -> Self {
|
9
|
+
self.inner.clone().struct_().field_by_name(&name).into()
|
10
|
+
}
|
11
|
+
|
12
12
|
pub fn struct_rename_fields(&self, names: Vec<String>) -> Self {
|
13
13
|
self.inner.clone().struct_().rename_fields(names).into()
|
14
14
|
}
|
15
|
+
|
16
|
+
pub fn struct_json_encode(&self) -> Self {
|
17
|
+
self.inner.clone().struct_().json_encode().into()
|
18
|
+
}
|
15
19
|
}
|
@@ -33,3 +33,9 @@ pub fn sum_horizontal(exprs: RArray) -> RbResult<RbExpr> {
|
|
33
33
|
let e = dsl::sum_horizontal(exprs).map_err(RbPolarsErr::from)?;
|
34
34
|
Ok(e.into())
|
35
35
|
}
|
36
|
+
|
37
|
+
pub fn mean_horizontal(exprs: RArray) -> RbResult<RbExpr> {
|
38
|
+
let exprs = rb_exprs_to_exprs(exprs)?;
|
39
|
+
let e = dsl::mean_horizontal(exprs).map_err(RbPolarsErr::from)?;
|
40
|
+
Ok(e.into())
|
41
|
+
}
|
@@ -17,6 +17,44 @@ macro_rules! set_unwrapped_or_0 {
|
|
17
17
|
};
|
18
18
|
}
|
19
19
|
|
20
|
+
pub fn rolling_corr(
|
21
|
+
x: &RbExpr,
|
22
|
+
y: &RbExpr,
|
23
|
+
window_size: IdxSize,
|
24
|
+
min_periods: IdxSize,
|
25
|
+
ddof: u8,
|
26
|
+
) -> RbExpr {
|
27
|
+
dsl::rolling_corr(
|
28
|
+
x.inner.clone(),
|
29
|
+
y.inner.clone(),
|
30
|
+
RollingCovOptions {
|
31
|
+
min_periods,
|
32
|
+
window_size,
|
33
|
+
ddof,
|
34
|
+
},
|
35
|
+
)
|
36
|
+
.into()
|
37
|
+
}
|
38
|
+
|
39
|
+
pub fn rolling_cov(
|
40
|
+
x: &RbExpr,
|
41
|
+
y: &RbExpr,
|
42
|
+
window_size: IdxSize,
|
43
|
+
min_periods: IdxSize,
|
44
|
+
ddof: u8,
|
45
|
+
) -> RbExpr {
|
46
|
+
dsl::rolling_cov(
|
47
|
+
x.inner.clone(),
|
48
|
+
y.inner.clone(),
|
49
|
+
RollingCovOptions {
|
50
|
+
min_periods,
|
51
|
+
window_size,
|
52
|
+
ddof,
|
53
|
+
},
|
54
|
+
)
|
55
|
+
.into()
|
56
|
+
}
|
57
|
+
|
20
58
|
pub fn arg_sort_by(by: RArray, descending: Vec<bool>) -> RbResult<RbExpr> {
|
21
59
|
let by = rb_exprs_to_exprs(by)?;
|
22
60
|
Ok(dsl::arg_sort_by(by, &descending).into())
|
@@ -83,6 +121,47 @@ pub fn concat_lf(
|
|
83
121
|
Ok(lf.into())
|
84
122
|
}
|
85
123
|
|
124
|
+
pub fn concat_list(s: RArray) -> RbResult<RbExpr> {
|
125
|
+
let s = rb_exprs_to_exprs(s)?;
|
126
|
+
let expr = dsl::concat_list(s).map_err(RbPolarsErr::from)?;
|
127
|
+
Ok(expr.into())
|
128
|
+
}
|
129
|
+
|
130
|
+
pub fn concat_str(s: RArray, separator: String, ignore_nulls: bool) -> RbResult<RbExpr> {
|
131
|
+
let s = rb_exprs_to_exprs(s)?;
|
132
|
+
Ok(dsl::concat_str(s, &separator, ignore_nulls).into())
|
133
|
+
}
|
134
|
+
|
135
|
+
pub fn len() -> RbExpr {
|
136
|
+
dsl::len().into()
|
137
|
+
}
|
138
|
+
|
139
|
+
pub fn cov(a: &RbExpr, b: &RbExpr, ddof: u8) -> RbExpr {
|
140
|
+
polars::lazy::dsl::cov(a.inner.clone(), b.inner.clone(), ddof).into()
|
141
|
+
}
|
142
|
+
|
143
|
+
pub fn arctan2(y: &RbExpr, x: &RbExpr) -> RbExpr {
|
144
|
+
y.inner.clone().arctan2(x.inner.clone()).into()
|
145
|
+
}
|
146
|
+
|
147
|
+
pub fn arctan2d(y: &RbExpr, x: &RbExpr) -> RbExpr {
|
148
|
+
y.inner.clone().arctan2(x.inner.clone()).degrees().into()
|
149
|
+
}
|
150
|
+
|
151
|
+
pub fn cum_fold(
|
152
|
+
acc: &RbExpr,
|
153
|
+
lambda: Value,
|
154
|
+
exprs: RArray,
|
155
|
+
include_init: bool,
|
156
|
+
) -> RbResult<RbExpr> {
|
157
|
+
let exprs = rb_exprs_to_exprs(exprs)?;
|
158
|
+
let lambda = Opaque::from(lambda);
|
159
|
+
|
160
|
+
let func =
|
161
|
+
move |a: Series, b: Series| binary_lambda(Ruby::get().unwrap().get_inner(lambda), a, b);
|
162
|
+
Ok(dsl::cum_fold_exprs(acc.inner.clone(), func, exprs, include_init).into())
|
163
|
+
}
|
164
|
+
|
86
165
|
pub fn concat_lf_diagonal(
|
87
166
|
lfs: RArray,
|
88
167
|
rechunk: bool,
|
@@ -110,6 +189,19 @@ pub fn concat_lf_diagonal(
|
|
110
189
|
Ok(lf.into())
|
111
190
|
}
|
112
191
|
|
192
|
+
pub fn dtype_cols(dtypes: Vec<DataType>) -> RbExpr {
|
193
|
+
dsl::dtype_cols(dtypes).into()
|
194
|
+
}
|
195
|
+
|
196
|
+
pub fn dtype_cols2(dtypes: RArray) -> RbResult<RbExpr> {
|
197
|
+
let dtypes = dtypes
|
198
|
+
.each()
|
199
|
+
.map(|v| Wrap::<DataType>::try_convert(v?))
|
200
|
+
.collect::<RbResult<Vec<Wrap<DataType>>>>()?;
|
201
|
+
let dtypes = vec_extract_wrapped(dtypes);
|
202
|
+
Ok(crate::functions::lazy::dtype_cols(dtypes))
|
203
|
+
}
|
204
|
+
|
113
205
|
#[allow(clippy::too_many_arguments)]
|
114
206
|
pub fn duration(
|
115
207
|
weeks: Option<&RbExpr>,
|
@@ -146,38 +238,21 @@ pub fn duration(
|
|
146
238
|
dsl::duration(args).into()
|
147
239
|
}
|
148
240
|
|
149
|
-
pub fn count() -> RbExpr {
|
150
|
-
dsl::count().into()
|
151
|
-
}
|
152
|
-
|
153
241
|
pub fn first() -> RbExpr {
|
154
242
|
dsl::first().into()
|
155
243
|
}
|
156
244
|
|
157
|
-
pub fn last() -> RbExpr {
|
158
|
-
dsl::last().into()
|
159
|
-
}
|
160
|
-
|
161
|
-
pub fn dtype_cols(dtypes: Vec<DataType>) -> RbExpr {
|
162
|
-
dsl::dtype_cols(dtypes).into()
|
163
|
-
}
|
164
|
-
|
165
245
|
pub fn fold(acc: &RbExpr, lambda: Value, exprs: RArray) -> RbResult<RbExpr> {
|
166
246
|
let exprs = rb_exprs_to_exprs(exprs)?;
|
167
247
|
let lambda = Opaque::from(lambda);
|
168
248
|
|
169
249
|
let func =
|
170
250
|
move |a: Series, b: Series| binary_lambda(Ruby::get().unwrap().get_inner(lambda), a, b);
|
171
|
-
Ok(
|
251
|
+
Ok(dsl::fold_exprs(acc.inner.clone(), func, exprs).into())
|
172
252
|
}
|
173
253
|
|
174
|
-
pub fn
|
175
|
-
|
176
|
-
let lambda = Opaque::from(lambda);
|
177
|
-
|
178
|
-
let func =
|
179
|
-
move |a: Series, b: Series| binary_lambda(Ruby::get().unwrap().get_inner(lambda), a, b);
|
180
|
-
Ok(polars::lazy::dsl::cum_fold_exprs(acc.inner.clone(), func, exprs, include_init).into())
|
254
|
+
pub fn last() -> RbExpr {
|
255
|
+
dsl::last().into()
|
181
256
|
}
|
182
257
|
|
183
258
|
pub fn lit(value: Value, allow_object: bool) -> RbResult<RbExpr> {
|
@@ -219,6 +294,10 @@ pub fn lit(value: Value, allow_object: bool) -> RbResult<RbExpr> {
|
|
219
294
|
}
|
220
295
|
}
|
221
296
|
|
297
|
+
pub fn pearson_corr(a: &RbExpr, b: &RbExpr, ddof: u8) -> RbExpr {
|
298
|
+
dsl::pearson_corr(a.inner.clone(), b.inner.clone(), ddof).into()
|
299
|
+
}
|
300
|
+
|
222
301
|
pub fn repeat(value: &RbExpr, n: &RbExpr, dtype: Option<Wrap<DataType>>) -> RbResult<RbExpr> {
|
223
302
|
let mut value = value.inner.clone();
|
224
303
|
let n = n.inner.clone();
|
@@ -228,7 +307,7 @@ pub fn repeat(value: &RbExpr, n: &RbExpr, dtype: Option<Wrap<DataType>>) -> RbRe
|
|
228
307
|
}
|
229
308
|
|
230
309
|
if let Expr::Literal(lv) = &value {
|
231
|
-
let av = lv.
|
310
|
+
let av = lv.to_any_value().unwrap();
|
232
311
|
// Integer inputs that fit in Int32 are parsed as such
|
233
312
|
if let DataType::Int64 = av.dtype() {
|
234
313
|
let int_value = av.try_extract::<i64>().unwrap();
|
@@ -240,35 +319,11 @@ pub fn repeat(value: &RbExpr, n: &RbExpr, dtype: Option<Wrap<DataType>>) -> RbRe
|
|
240
319
|
Ok(dsl::repeat(value, n).into())
|
241
320
|
}
|
242
321
|
|
243
|
-
pub fn pearson_corr(a: &RbExpr, b: &RbExpr, ddof: u8) -> RbExpr {
|
244
|
-
polars::lazy::dsl::pearson_corr(a.inner.clone(), b.inner.clone(), ddof).into()
|
245
|
-
}
|
246
|
-
|
247
322
|
pub fn spearman_rank_corr(a: &RbExpr, b: &RbExpr, ddof: u8, propagate_nans: bool) -> RbExpr {
|
248
|
-
|
249
|
-
.into()
|
250
|
-
}
|
251
|
-
|
252
|
-
pub fn cov(a: &RbExpr, b: &RbExpr, ddof: u8) -> RbExpr {
|
253
|
-
polars::lazy::dsl::cov(a.inner.clone(), b.inner.clone(), ddof).into()
|
254
|
-
}
|
255
|
-
|
256
|
-
pub fn concat_str(s: RArray, sep: String) -> RbResult<RbExpr> {
|
257
|
-
let s = rb_exprs_to_exprs(s)?;
|
258
|
-
Ok(dsl::concat_str(s, &sep).into())
|
323
|
+
dsl::spearman_rank_corr(a.inner.clone(), b.inner.clone(), ddof, propagate_nans).into()
|
259
324
|
}
|
260
325
|
|
261
|
-
pub fn
|
262
|
-
let
|
263
|
-
let expr = dsl::concat_list(s).map_err(RbPolarsErr::from)?;
|
326
|
+
pub fn sql_expr(sql: String) -> RbResult<RbExpr> {
|
327
|
+
let expr = polars::sql::sql_expr(&sql).map_err(RbPolarsErr::from)?;
|
264
328
|
Ok(expr.into())
|
265
329
|
}
|
266
|
-
|
267
|
-
pub fn dtype_cols2(dtypes: RArray) -> RbResult<RbExpr> {
|
268
|
-
let dtypes = dtypes
|
269
|
-
.each()
|
270
|
-
.map(|v| Wrap::<DataType>::try_convert(v?))
|
271
|
-
.collect::<RbResult<Vec<Wrap<DataType>>>>()?;
|
272
|
-
let dtypes = vec_extract_wrapped(dtypes);
|
273
|
-
Ok(crate::functions::lazy::dtype_cols(dtypes))
|
274
|
-
}
|
@@ -7,7 +7,7 @@ use polars_core::POOL;
|
|
7
7
|
use crate::conversion::Wrap;
|
8
8
|
use crate::{RbResult, RbValueError};
|
9
9
|
|
10
|
-
pub fn
|
10
|
+
pub fn get_index_type() -> Value {
|
11
11
|
Wrap(IDX_DTYPE).into_value()
|
12
12
|
}
|
13
13
|
|
@@ -36,3 +36,47 @@ pub fn get_float_fmt() -> RbResult<String> {
|
|
36
36
|
};
|
37
37
|
Ok(strfmt.to_string())
|
38
38
|
}
|
39
|
+
|
40
|
+
pub fn set_float_precision(precision: Option<usize>) -> RbResult<()> {
|
41
|
+
use polars_core::fmt::set_float_precision;
|
42
|
+
set_float_precision(precision);
|
43
|
+
Ok(())
|
44
|
+
}
|
45
|
+
|
46
|
+
pub fn get_float_precision() -> RbResult<Option<usize>> {
|
47
|
+
use polars_core::fmt::get_float_precision;
|
48
|
+
Ok(get_float_precision())
|
49
|
+
}
|
50
|
+
|
51
|
+
pub fn set_thousands_separator(sep: Option<char>) -> RbResult<()> {
|
52
|
+
use polars_core::fmt::set_thousands_separator;
|
53
|
+
set_thousands_separator(sep);
|
54
|
+
Ok(())
|
55
|
+
}
|
56
|
+
|
57
|
+
pub fn get_thousands_separator() -> RbResult<Option<String>> {
|
58
|
+
use polars_core::fmt::get_thousands_separator;
|
59
|
+
Ok(Some(get_thousands_separator()))
|
60
|
+
}
|
61
|
+
|
62
|
+
pub fn set_decimal_separator(sep: Option<char>) -> RbResult<()> {
|
63
|
+
use polars_core::fmt::set_decimal_separator;
|
64
|
+
set_decimal_separator(sep);
|
65
|
+
Ok(())
|
66
|
+
}
|
67
|
+
|
68
|
+
pub fn get_decimal_separator() -> RbResult<Option<char>> {
|
69
|
+
use polars_core::fmt::get_decimal_separator;
|
70
|
+
Ok(Some(get_decimal_separator()))
|
71
|
+
}
|
72
|
+
|
73
|
+
pub fn set_trim_decimal_zeros(trim: Option<bool>) -> RbResult<()> {
|
74
|
+
use polars_core::fmt::set_trim_decimal_zeros;
|
75
|
+
set_trim_decimal_zeros(trim);
|
76
|
+
Ok(())
|
77
|
+
}
|
78
|
+
|
79
|
+
pub fn get_trim_decimal_zeros() -> RbResult<Option<bool>> {
|
80
|
+
use polars_core::fmt::get_trim_decimal_zeros;
|
81
|
+
Ok(Some(get_trim_decimal_zeros()))
|
82
|
+
}
|
@@ -6,21 +6,16 @@ use crate::prelude::*;
|
|
6
6
|
use crate::RbExpr;
|
7
7
|
|
8
8
|
pub fn int_range(start: &RbExpr, end: &RbExpr, step: i64, dtype: Wrap<DataType>) -> RbExpr {
|
9
|
+
let start = start.inner.clone();
|
10
|
+
let end = end.inner.clone();
|
9
11
|
let dtype = dtype.0;
|
10
|
-
|
11
|
-
let mut result = dsl::int_range(start.inner.clone(), end.inner.clone(), step);
|
12
|
-
|
13
|
-
if dtype != DataType::Int64 {
|
14
|
-
result = result.cast(dtype)
|
15
|
-
}
|
16
|
-
|
17
|
-
result.into()
|
12
|
+
dsl::int_range(start, end, step, dtype).into()
|
18
13
|
}
|
19
14
|
|
20
|
-
pub fn int_ranges(start: &RbExpr, end: &RbExpr, step:
|
15
|
+
pub fn int_ranges(start: &RbExpr, end: &RbExpr, step: &RbExpr, dtype: Wrap<DataType>) -> RbExpr {
|
21
16
|
let dtype = dtype.0;
|
22
17
|
|
23
|
-
let mut result = dsl::int_ranges(start.inner.clone(), end.inner.clone(), step);
|
18
|
+
let mut result = dsl::int_ranges(start.inner.clone(), end.inner.clone(), step.inner.clone());
|
24
19
|
|
25
20
|
if dtype != DataType::Int64 {
|
26
21
|
result = result.cast(DataType::List(Box::new(dtype)))
|
@@ -1,3 +1,7 @@
|
|
1
|
+
use crate::RbResult;
|
2
|
+
use magnus::{RArray, Ruby, Value};
|
3
|
+
use polars_core::StringCacheHolder;
|
4
|
+
|
1
5
|
pub fn enable_string_cache() {
|
2
6
|
polars_core::enable_string_cache()
|
3
7
|
}
|
@@ -9,3 +13,13 @@ pub fn disable_string_cache() {
|
|
9
13
|
pub fn using_string_cache() -> bool {
|
10
14
|
polars_core::using_string_cache()
|
11
15
|
}
|
16
|
+
|
17
|
+
#[magnus::wrap(class = "Polars::RbStringCacheHolder")]
|
18
|
+
pub struct RbStringCacheHolder {}
|
19
|
+
|
20
|
+
impl RbStringCacheHolder {
|
21
|
+
pub fn hold() -> RbResult<Value> {
|
22
|
+
let _hold = StringCacheHolder::hold();
|
23
|
+
Ruby::get().unwrap().yield_splat(RArray::new())
|
24
|
+
}
|
25
|
+
}
|