polars-df 0.4.0 → 0.6.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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/Cargo.lock +447 -410
  4. data/Cargo.toml +0 -1
  5. data/README.md +6 -5
  6. data/ext/polars/Cargo.toml +10 -5
  7. data/ext/polars/src/apply/dataframe.rs +2 -2
  8. data/ext/polars/src/{lazy/apply.rs → apply/lazy.rs} +1 -2
  9. data/ext/polars/src/apply/mod.rs +8 -3
  10. data/ext/polars/src/batched_csv.rs +7 -5
  11. data/ext/polars/src/conversion.rs +269 -59
  12. data/ext/polars/src/dataframe.rs +38 -40
  13. data/ext/polars/src/error.rs +6 -2
  14. data/ext/polars/src/expr/array.rs +15 -0
  15. data/ext/polars/src/expr/binary.rs +69 -0
  16. data/ext/polars/src/expr/categorical.rs +10 -0
  17. data/ext/polars/src/expr/datetime.rs +223 -0
  18. data/ext/polars/src/expr/general.rs +963 -0
  19. data/ext/polars/src/expr/list.rs +151 -0
  20. data/ext/polars/src/{lazy → expr}/meta.rs +16 -6
  21. data/ext/polars/src/expr/string.rs +314 -0
  22. data/ext/polars/src/expr/struct.rs +15 -0
  23. data/ext/polars/src/expr.rs +34 -0
  24. data/ext/polars/src/functions/eager.rs +93 -0
  25. data/ext/polars/src/functions/io.rs +34 -0
  26. data/ext/polars/src/functions/lazy.rs +249 -0
  27. data/ext/polars/src/functions/meta.rs +8 -0
  28. data/ext/polars/src/functions/mod.rs +5 -0
  29. data/ext/polars/src/functions/whenthen.rs +43 -0
  30. data/ext/polars/src/{lazy/dataframe.rs → lazyframe.rs} +26 -35
  31. data/ext/polars/src/lazygroupby.rs +29 -0
  32. data/ext/polars/src/lib.rs +223 -316
  33. data/ext/polars/src/object.rs +1 -1
  34. data/ext/polars/src/rb_modules.rs +12 -0
  35. data/ext/polars/src/series/aggregation.rs +83 -0
  36. data/ext/polars/src/series/arithmetic.rs +88 -0
  37. data/ext/polars/src/series/comparison.rs +251 -0
  38. data/ext/polars/src/series/construction.rs +190 -0
  39. data/ext/polars/src/series.rs +151 -551
  40. data/lib/polars/array_expr.rb +84 -0
  41. data/lib/polars/array_name_space.rb +77 -0
  42. data/lib/polars/batched_csv_reader.rb +1 -1
  43. data/lib/polars/convert.rb +2 -2
  44. data/lib/polars/data_frame.rb +289 -96
  45. data/lib/polars/data_types.rb +169 -33
  46. data/lib/polars/date_time_expr.rb +142 -2
  47. data/lib/polars/date_time_name_space.rb +17 -3
  48. data/lib/polars/expr.rb +145 -78
  49. data/lib/polars/functions.rb +0 -1
  50. data/lib/polars/group_by.rb +1 -22
  51. data/lib/polars/lazy_frame.rb +84 -31
  52. data/lib/polars/lazy_functions.rb +71 -32
  53. data/lib/polars/list_expr.rb +94 -45
  54. data/lib/polars/list_name_space.rb +13 -13
  55. data/lib/polars/rolling_group_by.rb +4 -2
  56. data/lib/polars/series.rb +249 -87
  57. data/lib/polars/string_expr.rb +277 -45
  58. data/lib/polars/string_name_space.rb +137 -22
  59. data/lib/polars/struct_name_space.rb +32 -0
  60. data/lib/polars/utils.rb +138 -54
  61. data/lib/polars/version.rb +1 -1
  62. data/lib/polars.rb +5 -2
  63. metadata +29 -11
  64. data/ext/polars/src/lazy/dsl.rs +0 -1775
  65. data/ext/polars/src/lazy/mod.rs +0 -5
  66. data/ext/polars/src/lazy/utils.rs +0 -13
  67. data/ext/polars/src/list_construction.rs +0 -100
  68. /data/ext/polars/src/{numo.rs → series/export.rs} +0 -0
  69. /data/ext/polars/src/{set.rs → series/set_at_idx.rs} +0 -0
@@ -0,0 +1,963 @@
1
+ use magnus::{block::Proc, IntoValue, RArray, Value};
2
+ use polars::lazy::dsl;
3
+ use polars::prelude::*;
4
+ use polars::series::ops::NullBehavior;
5
+ use polars_core::series::IsSorted;
6
+ use std::any::Any;
7
+
8
+ use crate::apply::lazy::map_single;
9
+ use crate::conversion::{parse_fill_null_strategy, Wrap};
10
+ use crate::rb_exprs_to_exprs;
11
+ use crate::utils::reinterpret;
12
+ use crate::{RbExpr, RbResult};
13
+
14
+ impl RbExpr {
15
+ pub fn add(&self, rhs: &RbExpr) -> RbResult<Self> {
16
+ Ok(dsl::binary_expr(self.inner.clone(), Operator::Plus, rhs.inner.clone()).into())
17
+ }
18
+
19
+ pub fn sub(&self, rhs: &RbExpr) -> RbResult<Self> {
20
+ Ok(dsl::binary_expr(self.inner.clone(), Operator::Minus, rhs.inner.clone()).into())
21
+ }
22
+
23
+ pub fn mul(&self, rhs: &RbExpr) -> RbResult<Self> {
24
+ Ok(dsl::binary_expr(self.inner.clone(), Operator::Multiply, rhs.inner.clone()).into())
25
+ }
26
+
27
+ pub fn truediv(&self, rhs: &RbExpr) -> RbResult<Self> {
28
+ Ok(dsl::binary_expr(self.inner.clone(), Operator::TrueDivide, rhs.inner.clone()).into())
29
+ }
30
+
31
+ pub fn _mod(&self, rhs: &RbExpr) -> RbResult<Self> {
32
+ Ok(dsl::binary_expr(self.inner.clone(), Operator::Modulus, rhs.inner.clone()).into())
33
+ }
34
+
35
+ pub fn floordiv(&self, rhs: &RbExpr) -> RbResult<Self> {
36
+ Ok(dsl::binary_expr(self.inner.clone(), Operator::FloorDivide, rhs.inner.clone()).into())
37
+ }
38
+
39
+ pub fn to_str(&self) -> String {
40
+ format!("{:?}", self.inner)
41
+ }
42
+
43
+ pub fn eq(&self, other: &RbExpr) -> Self {
44
+ self.clone().inner.eq(other.inner.clone()).into()
45
+ }
46
+
47
+ pub fn neq(&self, other: &RbExpr) -> Self {
48
+ self.clone().inner.neq(other.inner.clone()).into()
49
+ }
50
+
51
+ pub fn gt(&self, other: &RbExpr) -> Self {
52
+ self.clone().inner.gt(other.inner.clone()).into()
53
+ }
54
+
55
+ pub fn gt_eq(&self, other: &RbExpr) -> Self {
56
+ self.clone().inner.gt_eq(other.inner.clone()).into()
57
+ }
58
+
59
+ pub fn lt_eq(&self, other: &RbExpr) -> Self {
60
+ self.clone().inner.lt_eq(other.inner.clone()).into()
61
+ }
62
+
63
+ pub fn lt(&self, other: &RbExpr) -> Self {
64
+ self.clone().inner.lt(other.inner.clone()).into()
65
+ }
66
+
67
+ pub fn alias(&self, name: String) -> Self {
68
+ self.clone().inner.alias(&name).into()
69
+ }
70
+
71
+ pub fn is_not(&self) -> Self {
72
+ self.clone().inner.not().into()
73
+ }
74
+
75
+ pub fn is_null(&self) -> Self {
76
+ self.clone().inner.is_null().into()
77
+ }
78
+
79
+ pub fn is_not_null(&self) -> Self {
80
+ self.clone().inner.is_not_null().into()
81
+ }
82
+
83
+ pub fn is_infinite(&self) -> Self {
84
+ self.clone().inner.is_infinite().into()
85
+ }
86
+
87
+ pub fn is_finite(&self) -> Self {
88
+ self.clone().inner.is_finite().into()
89
+ }
90
+
91
+ pub fn is_nan(&self) -> Self {
92
+ self.clone().inner.is_nan().into()
93
+ }
94
+
95
+ pub fn is_not_nan(&self) -> Self {
96
+ self.clone().inner.is_not_nan().into()
97
+ }
98
+
99
+ pub fn min(&self) -> Self {
100
+ self.clone().inner.min().into()
101
+ }
102
+
103
+ pub fn max(&self) -> Self {
104
+ self.clone().inner.max().into()
105
+ }
106
+
107
+ pub fn nan_max(&self) -> Self {
108
+ self.clone().inner.nan_max().into()
109
+ }
110
+
111
+ pub fn nan_min(&self) -> Self {
112
+ self.clone().inner.nan_min().into()
113
+ }
114
+
115
+ pub fn mean(&self) -> Self {
116
+ self.clone().inner.mean().into()
117
+ }
118
+
119
+ pub fn median(&self) -> Self {
120
+ self.clone().inner.median().into()
121
+ }
122
+
123
+ pub fn sum(&self) -> Self {
124
+ self.clone().inner.sum().into()
125
+ }
126
+
127
+ pub fn n_unique(&self) -> Self {
128
+ self.clone().inner.n_unique().into()
129
+ }
130
+
131
+ pub fn arg_unique(&self) -> Self {
132
+ self.clone().inner.arg_unique().into()
133
+ }
134
+
135
+ pub fn unique(&self) -> Self {
136
+ self.clone().inner.unique().into()
137
+ }
138
+
139
+ pub fn unique_stable(&self) -> Self {
140
+ self.clone().inner.unique_stable().into()
141
+ }
142
+
143
+ pub fn first(&self) -> Self {
144
+ self.clone().inner.first().into()
145
+ }
146
+
147
+ pub fn last(&self) -> Self {
148
+ self.clone().inner.last().into()
149
+ }
150
+
151
+ pub fn implode(&self) -> Self {
152
+ self.clone().inner.implode().into()
153
+ }
154
+
155
+ pub fn quantile(
156
+ &self,
157
+ quantile: &RbExpr,
158
+ interpolation: Wrap<QuantileInterpolOptions>,
159
+ ) -> Self {
160
+ self.clone()
161
+ .inner
162
+ .quantile(quantile.inner.clone(), interpolation.0)
163
+ .into()
164
+ }
165
+
166
+ pub fn agg_groups(&self) -> Self {
167
+ self.clone().inner.agg_groups().into()
168
+ }
169
+
170
+ pub fn count(&self) -> Self {
171
+ self.clone().inner.count().into()
172
+ }
173
+
174
+ pub fn value_counts(&self, multithreaded: bool, sorted: bool) -> Self {
175
+ self.inner
176
+ .clone()
177
+ .value_counts(multithreaded, sorted)
178
+ .into()
179
+ }
180
+
181
+ pub fn unique_counts(&self) -> Self {
182
+ self.inner.clone().unique_counts().into()
183
+ }
184
+
185
+ pub fn null_count(&self) -> Self {
186
+ self.inner.clone().null_count().into()
187
+ }
188
+
189
+ pub fn cast(&self, data_type: Wrap<DataType>, strict: bool) -> RbResult<Self> {
190
+ let dt = data_type.0;
191
+ let expr = if strict {
192
+ self.inner.clone().strict_cast(dt)
193
+ } else {
194
+ self.inner.clone().cast(dt)
195
+ };
196
+ Ok(expr.into())
197
+ }
198
+
199
+ pub fn sort_with(&self, descending: bool, nulls_last: bool) -> Self {
200
+ self.clone()
201
+ .inner
202
+ .sort_with(SortOptions {
203
+ descending,
204
+ nulls_last,
205
+ multithreaded: true,
206
+ maintain_order: false,
207
+ })
208
+ .into()
209
+ }
210
+
211
+ pub fn arg_sort(&self, reverse: bool, nulls_last: bool) -> Self {
212
+ self.clone()
213
+ .inner
214
+ .arg_sort(SortOptions {
215
+ descending: reverse,
216
+ nulls_last,
217
+ multithreaded: true,
218
+ maintain_order: false,
219
+ })
220
+ .into()
221
+ }
222
+
223
+ pub fn top_k(&self, k: usize) -> Self {
224
+ self.inner.clone().top_k(k).into()
225
+ }
226
+
227
+ pub fn bottom_k(&self, k: usize) -> Self {
228
+ self.inner.clone().bottom_k(k).into()
229
+ }
230
+
231
+ pub fn arg_max(&self) -> Self {
232
+ self.clone().inner.arg_max().into()
233
+ }
234
+
235
+ pub fn arg_min(&self) -> Self {
236
+ self.clone().inner.arg_min().into()
237
+ }
238
+
239
+ pub fn search_sorted(&self, element: &RbExpr, side: Wrap<SearchSortedSide>) -> Self {
240
+ self.inner
241
+ .clone()
242
+ .search_sorted(element.inner.clone(), side.0)
243
+ .into()
244
+ }
245
+
246
+ pub fn take(&self, idx: &RbExpr) -> Self {
247
+ self.clone().inner.take(idx.inner.clone()).into()
248
+ }
249
+
250
+ pub fn sort_by(&self, by: RArray, reverse: Vec<bool>) -> RbResult<Self> {
251
+ let by = rb_exprs_to_exprs(by)?;
252
+ Ok(self.clone().inner.sort_by(by, reverse).into())
253
+ }
254
+
255
+ pub fn backward_fill(&self, limit: FillNullLimit) -> Self {
256
+ self.clone().inner.backward_fill(limit).into()
257
+ }
258
+
259
+ pub fn forward_fill(&self, limit: FillNullLimit) -> Self {
260
+ self.clone().inner.forward_fill(limit).into()
261
+ }
262
+
263
+ pub fn shift(&self, periods: i64) -> Self {
264
+ self.clone().inner.shift(periods).into()
265
+ }
266
+ pub fn shift_and_fill(&self, periods: i64, fill_value: &RbExpr) -> Self {
267
+ self.clone()
268
+ .inner
269
+ .shift_and_fill(periods, fill_value.inner.clone())
270
+ .into()
271
+ }
272
+
273
+ pub fn fill_null(&self, expr: &RbExpr) -> Self {
274
+ self.clone().inner.fill_null(expr.inner.clone()).into()
275
+ }
276
+
277
+ pub fn fill_null_with_strategy(
278
+ &self,
279
+ strategy: String,
280
+ limit: FillNullLimit,
281
+ ) -> RbResult<Self> {
282
+ let strat = parse_fill_null_strategy(&strategy, limit)?;
283
+ Ok(self
284
+ .inner
285
+ .clone()
286
+ .apply(
287
+ move |s| s.fill_null(strat).map(Some),
288
+ GetOutput::same_type(),
289
+ )
290
+ .with_fmt("fill_null_with_strategy")
291
+ .into())
292
+ }
293
+
294
+ pub fn fill_nan(&self, expr: &RbExpr) -> Self {
295
+ self.inner.clone().fill_nan(expr.inner.clone()).into()
296
+ }
297
+
298
+ pub fn drop_nulls(&self) -> Self {
299
+ self.inner.clone().drop_nulls().into()
300
+ }
301
+
302
+ pub fn drop_nans(&self) -> Self {
303
+ self.inner.clone().drop_nans().into()
304
+ }
305
+
306
+ pub fn filter(&self, predicate: &RbExpr) -> Self {
307
+ self.clone().inner.filter(predicate.inner.clone()).into()
308
+ }
309
+
310
+ pub fn reverse(&self) -> Self {
311
+ self.clone().inner.reverse().into()
312
+ }
313
+
314
+ pub fn std(&self, ddof: u8) -> Self {
315
+ self.clone().inner.std(ddof).into()
316
+ }
317
+
318
+ pub fn var(&self, ddof: u8) -> Self {
319
+ self.clone().inner.var(ddof).into()
320
+ }
321
+
322
+ pub fn is_unique(&self) -> Self {
323
+ self.clone().inner.is_unique().into()
324
+ }
325
+
326
+ pub fn approx_unique(&self) -> Self {
327
+ self.clone().inner.approx_unique().into()
328
+ }
329
+
330
+ pub fn is_first(&self) -> Self {
331
+ self.clone().inner.is_first().into()
332
+ }
333
+
334
+ pub fn explode(&self) -> Self {
335
+ self.clone().inner.explode().into()
336
+ }
337
+
338
+ pub fn take_every(&self, n: usize) -> Self {
339
+ self.clone()
340
+ .inner
341
+ .map(
342
+ move |s: Series| Ok(Some(s.take_every(n))),
343
+ GetOutput::same_type(),
344
+ )
345
+ .with_fmt("take_every")
346
+ .into()
347
+ }
348
+
349
+ pub fn tail(&self, n: Option<usize>) -> Self {
350
+ self.clone().inner.tail(n).into()
351
+ }
352
+
353
+ pub fn head(&self, n: Option<usize>) -> Self {
354
+ self.clone().inner.head(n).into()
355
+ }
356
+
357
+ pub fn slice(&self, offset: &RbExpr, length: &RbExpr) -> Self {
358
+ self.inner
359
+ .clone()
360
+ .slice(offset.inner.clone(), length.inner.clone())
361
+ .into()
362
+ }
363
+
364
+ pub fn append(&self, other: &RbExpr, upcast: bool) -> Self {
365
+ self.inner
366
+ .clone()
367
+ .append(other.inner.clone(), upcast)
368
+ .into()
369
+ }
370
+
371
+ pub fn rechunk(&self) -> Self {
372
+ self.inner
373
+ .clone()
374
+ .map(|s| Ok(Some(s.rechunk())), GetOutput::same_type())
375
+ .into()
376
+ }
377
+
378
+ pub fn round(&self, decimals: u32) -> Self {
379
+ self.clone().inner.round(decimals).into()
380
+ }
381
+
382
+ pub fn floor(&self) -> Self {
383
+ self.clone().inner.floor().into()
384
+ }
385
+
386
+ pub fn ceil(&self) -> Self {
387
+ self.clone().inner.ceil().into()
388
+ }
389
+
390
+ pub fn clip(&self, min: Value, max: Value) -> Self {
391
+ let min = min.try_convert::<Wrap<AnyValue>>().unwrap().0;
392
+ let max = max.try_convert::<Wrap<AnyValue>>().unwrap().0;
393
+ self.clone().inner.clip(min, max).into()
394
+ }
395
+
396
+ pub fn clip_min(&self, min: Value) -> Self {
397
+ let min = min.try_convert::<Wrap<AnyValue>>().unwrap().0;
398
+ self.clone().inner.clip_min(min).into()
399
+ }
400
+
401
+ pub fn clip_max(&self, max: Value) -> Self {
402
+ let max = max.try_convert::<Wrap<AnyValue>>().unwrap().0;
403
+ self.clone().inner.clip_max(max).into()
404
+ }
405
+
406
+ pub fn abs(&self) -> Self {
407
+ self.clone().inner.abs().into()
408
+ }
409
+
410
+ pub fn sin(&self) -> Self {
411
+ self.clone().inner.sin().into()
412
+ }
413
+
414
+ pub fn cos(&self) -> Self {
415
+ self.clone().inner.cos().into()
416
+ }
417
+
418
+ pub fn tan(&self) -> Self {
419
+ self.clone().inner.tan().into()
420
+ }
421
+
422
+ pub fn arcsin(&self) -> Self {
423
+ self.clone().inner.arcsin().into()
424
+ }
425
+
426
+ pub fn arccos(&self) -> Self {
427
+ self.clone().inner.arccos().into()
428
+ }
429
+
430
+ pub fn arctan(&self) -> Self {
431
+ self.clone().inner.arctan().into()
432
+ }
433
+
434
+ pub fn sinh(&self) -> Self {
435
+ self.clone().inner.sinh().into()
436
+ }
437
+
438
+ pub fn cosh(&self) -> Self {
439
+ self.clone().inner.cosh().into()
440
+ }
441
+
442
+ pub fn tanh(&self) -> Self {
443
+ self.clone().inner.tanh().into()
444
+ }
445
+
446
+ pub fn arcsinh(&self) -> Self {
447
+ self.clone().inner.arcsinh().into()
448
+ }
449
+
450
+ pub fn arccosh(&self) -> Self {
451
+ self.clone().inner.arccosh().into()
452
+ }
453
+
454
+ pub fn arctanh(&self) -> Self {
455
+ self.clone().inner.arctanh().into()
456
+ }
457
+
458
+ pub fn sign(&self) -> Self {
459
+ self.clone().inner.sign().into()
460
+ }
461
+
462
+ pub fn is_duplicated(&self) -> Self {
463
+ self.clone().inner.is_duplicated().into()
464
+ }
465
+
466
+ pub fn over(&self, partition_by: RArray) -> RbResult<Self> {
467
+ let partition_by = rb_exprs_to_exprs(partition_by)?;
468
+ Ok(self.clone().inner.over(partition_by).into())
469
+ }
470
+
471
+ pub fn _and(&self, expr: &RbExpr) -> Self {
472
+ self.clone().inner.and(expr.inner.clone()).into()
473
+ }
474
+
475
+ pub fn _xor(&self, expr: &RbExpr) -> Self {
476
+ self.clone().inner.xor(expr.inner.clone()).into()
477
+ }
478
+
479
+ pub fn _or(&self, expr: &RbExpr) -> Self {
480
+ self.clone().inner.or(expr.inner.clone()).into()
481
+ }
482
+
483
+ pub fn is_in(&self, expr: &RbExpr) -> Self {
484
+ self.clone().inner.is_in(expr.inner.clone()).into()
485
+ }
486
+
487
+ pub fn repeat_by(&self, by: &RbExpr) -> Self {
488
+ self.clone().inner.repeat_by(by.inner.clone()).into()
489
+ }
490
+
491
+ pub fn pow(&self, exponent: &RbExpr) -> Self {
492
+ self.clone().inner.pow(exponent.inner.clone()).into()
493
+ }
494
+
495
+ pub fn cumsum(&self, reverse: bool) -> Self {
496
+ self.clone().inner.cumsum(reverse).into()
497
+ }
498
+
499
+ pub fn cummax(&self, reverse: bool) -> Self {
500
+ self.clone().inner.cummax(reverse).into()
501
+ }
502
+
503
+ pub fn cummin(&self, reverse: bool) -> Self {
504
+ self.clone().inner.cummin(reverse).into()
505
+ }
506
+
507
+ pub fn cumprod(&self, reverse: bool) -> Self {
508
+ self.clone().inner.cumprod(reverse).into()
509
+ }
510
+
511
+ pub fn product(&self) -> Self {
512
+ self.clone().inner.product().into()
513
+ }
514
+
515
+ pub fn shrink_dtype(&self) -> Self {
516
+ self.inner.clone().shrink_dtype().into()
517
+ }
518
+
519
+ pub fn map(&self, lambda: Value, output_type: Option<Wrap<DataType>>, agg_list: bool) -> Self {
520
+ map_single(self, lambda, output_type, agg_list)
521
+ }
522
+
523
+ pub fn dot(&self, other: &RbExpr) -> Self {
524
+ self.inner.clone().dot(other.inner.clone()).into()
525
+ }
526
+
527
+ pub fn reinterpret(&self, signed: bool) -> Self {
528
+ let function = move |s: Series| reinterpret(&s, signed).map(Some);
529
+ let dt = if signed {
530
+ DataType::Int64
531
+ } else {
532
+ DataType::UInt64
533
+ };
534
+ self.clone()
535
+ .inner
536
+ .map(function, GetOutput::from_type(dt))
537
+ .into()
538
+ }
539
+
540
+ pub fn mode(&self) -> Self {
541
+ self.inner.clone().mode().into()
542
+ }
543
+
544
+ pub fn keep_name(&self) -> Self {
545
+ self.inner.clone().keep_name().into()
546
+ }
547
+
548
+ pub fn prefix(&self, prefix: String) -> Self {
549
+ self.inner.clone().prefix(&prefix).into()
550
+ }
551
+
552
+ pub fn suffix(&self, suffix: String) -> Self {
553
+ self.inner.clone().suffix(&suffix).into()
554
+ }
555
+
556
+ pub fn map_alias(&self, lambda: Proc) -> Self {
557
+ self.inner
558
+ .clone()
559
+ .map_alias(move |name| {
560
+ let out = lambda.call::<_, String>((name,));
561
+ match out {
562
+ Ok(out) => Ok(out),
563
+ Err(e) => Err(PolarsError::ComputeError(
564
+ format!("Ruby function in 'map_alias' produced an error: {}.", e).into(),
565
+ )),
566
+ }
567
+ })
568
+ .into()
569
+ }
570
+
571
+ pub fn exclude(&self, columns: Vec<String>) -> Self {
572
+ self.inner.clone().exclude(columns).into()
573
+ }
574
+
575
+ pub fn interpolate(&self, method: Wrap<InterpolationMethod>) -> Self {
576
+ self.inner.clone().interpolate(method.0).into()
577
+ }
578
+
579
+ pub fn rolling_sum(
580
+ &self,
581
+ window_size: String,
582
+ weights: Option<Vec<f64>>,
583
+ min_periods: usize,
584
+ center: bool,
585
+ by: Option<String>,
586
+ closed: Option<Wrap<ClosedWindow>>,
587
+ ) -> Self {
588
+ let options = RollingOptions {
589
+ window_size: Duration::parse(&window_size),
590
+ weights,
591
+ min_periods,
592
+ center,
593
+ by,
594
+ closed_window: closed.map(|c| c.0),
595
+ ..Default::default()
596
+ };
597
+ self.inner.clone().rolling_sum(options).into()
598
+ }
599
+
600
+ pub fn rolling_min(
601
+ &self,
602
+ window_size: String,
603
+ weights: Option<Vec<f64>>,
604
+ min_periods: usize,
605
+ center: bool,
606
+ by: Option<String>,
607
+ closed: Option<Wrap<ClosedWindow>>,
608
+ ) -> Self {
609
+ let options = RollingOptions {
610
+ window_size: Duration::parse(&window_size),
611
+ weights,
612
+ min_periods,
613
+ center,
614
+ by,
615
+ closed_window: closed.map(|c| c.0),
616
+ ..Default::default()
617
+ };
618
+ self.inner.clone().rolling_min(options).into()
619
+ }
620
+
621
+ pub fn rolling_max(
622
+ &self,
623
+ window_size: String,
624
+ weights: Option<Vec<f64>>,
625
+ min_periods: usize,
626
+ center: bool,
627
+ by: Option<String>,
628
+ closed: Option<Wrap<ClosedWindow>>,
629
+ ) -> Self {
630
+ let options = RollingOptions {
631
+ window_size: Duration::parse(&window_size),
632
+ weights,
633
+ min_periods,
634
+ center,
635
+ by,
636
+ closed_window: closed.map(|c| c.0),
637
+ ..Default::default()
638
+ };
639
+ self.inner.clone().rolling_max(options).into()
640
+ }
641
+
642
+ pub fn rolling_mean(
643
+ &self,
644
+ window_size: String,
645
+ weights: Option<Vec<f64>>,
646
+ min_periods: usize,
647
+ center: bool,
648
+ by: Option<String>,
649
+ closed: Option<Wrap<ClosedWindow>>,
650
+ ) -> Self {
651
+ let options = RollingOptions {
652
+ window_size: Duration::parse(&window_size),
653
+ weights,
654
+ min_periods,
655
+ center,
656
+ by,
657
+ closed_window: closed.map(|c| c.0),
658
+ ..Default::default()
659
+ };
660
+
661
+ self.inner.clone().rolling_mean(options).into()
662
+ }
663
+
664
+ #[allow(clippy::too_many_arguments)]
665
+ pub fn rolling_std(
666
+ &self,
667
+ window_size: String,
668
+ weights: Option<Vec<f64>>,
669
+ min_periods: usize,
670
+ center: bool,
671
+ by: Option<String>,
672
+ closed: Option<Wrap<ClosedWindow>>,
673
+ ddof: u8,
674
+ ) -> Self {
675
+ let options = RollingOptions {
676
+ window_size: Duration::parse(&window_size),
677
+ weights,
678
+ min_periods,
679
+ center,
680
+ by,
681
+ closed_window: closed.map(|c| c.0),
682
+ fn_params: Some(Arc::new(RollingVarParams { ddof }) as Arc<dyn Any + Send + Sync>),
683
+ };
684
+
685
+ self.inner.clone().rolling_std(options).into()
686
+ }
687
+
688
+ #[allow(clippy::too_many_arguments)]
689
+ pub fn rolling_var(
690
+ &self,
691
+ window_size: String,
692
+ weights: Option<Vec<f64>>,
693
+ min_periods: usize,
694
+ center: bool,
695
+ by: Option<String>,
696
+ closed: Option<Wrap<ClosedWindow>>,
697
+ ddof: u8,
698
+ ) -> Self {
699
+ let options = RollingOptions {
700
+ window_size: Duration::parse(&window_size),
701
+ weights,
702
+ min_periods,
703
+ center,
704
+ by,
705
+ closed_window: closed.map(|c| c.0),
706
+ fn_params: Some(Arc::new(RollingVarParams { ddof }) as Arc<dyn Any + Send + Sync>),
707
+ };
708
+
709
+ self.inner.clone().rolling_var(options).into()
710
+ }
711
+
712
+ pub fn rolling_median(
713
+ &self,
714
+ window_size: String,
715
+ weights: Option<Vec<f64>>,
716
+ min_periods: usize,
717
+ center: bool,
718
+ by: Option<String>,
719
+ closed: Option<Wrap<ClosedWindow>>,
720
+ ) -> Self {
721
+ let options = RollingOptions {
722
+ window_size: Duration::parse(&window_size),
723
+ weights,
724
+ min_periods,
725
+ center,
726
+ by,
727
+ closed_window: closed.map(|c| c.0),
728
+ fn_params: Some(Arc::new(RollingQuantileParams {
729
+ prob: 0.5,
730
+ interpol: QuantileInterpolOptions::Linear,
731
+ }) as Arc<dyn Any + Send + Sync>),
732
+ };
733
+ self.inner.clone().rolling_quantile(options).into()
734
+ }
735
+
736
+ #[allow(clippy::too_many_arguments)]
737
+ pub fn rolling_quantile(
738
+ &self,
739
+ quantile: f64,
740
+ interpolation: Wrap<QuantileInterpolOptions>,
741
+ window_size: String,
742
+ weights: Option<Vec<f64>>,
743
+ min_periods: usize,
744
+ center: bool,
745
+ by: Option<String>,
746
+ closed: Option<Wrap<ClosedWindow>>,
747
+ ) -> Self {
748
+ let options = RollingOptions {
749
+ window_size: Duration::parse(&window_size),
750
+ weights,
751
+ min_periods,
752
+ center,
753
+ by,
754
+ closed_window: closed.map(|c| c.0),
755
+ fn_params: Some(Arc::new(RollingQuantileParams {
756
+ prob: quantile,
757
+ interpol: interpolation.0,
758
+ }) as Arc<dyn Any + Send + Sync>),
759
+ };
760
+
761
+ self.inner.clone().rolling_quantile(options).into()
762
+ }
763
+
764
+ pub fn rolling_skew(&self, window_size: usize, bias: bool) -> Self {
765
+ self.inner
766
+ .clone()
767
+ .rolling_apply_float(window_size, move |ca| {
768
+ ca.clone().into_series().skew(bias).unwrap()
769
+ })
770
+ .into()
771
+ }
772
+
773
+ pub fn lower_bound(&self) -> Self {
774
+ self.inner.clone().lower_bound().into()
775
+ }
776
+
777
+ pub fn upper_bound(&self) -> Self {
778
+ self.inner.clone().upper_bound().into()
779
+ }
780
+
781
+ pub fn cumulative_eval(&self, expr: &RbExpr, min_periods: usize, parallel: bool) -> Self {
782
+ self.inner
783
+ .clone()
784
+ .cumulative_eval(expr.inner.clone(), min_periods, parallel)
785
+ .into()
786
+ }
787
+
788
+ pub fn rank(&self, method: Wrap<RankMethod>, reverse: bool, seed: Option<u64>) -> Self {
789
+ let options = RankOptions {
790
+ method: method.0,
791
+ descending: reverse,
792
+ };
793
+ self.inner.clone().rank(options, seed).into()
794
+ }
795
+
796
+ pub fn diff(&self, n: i64, null_behavior: Wrap<NullBehavior>) -> Self {
797
+ self.inner.clone().diff(n, null_behavior.0).into()
798
+ }
799
+
800
+ pub fn pct_change(&self, n: i64) -> Self {
801
+ self.inner.clone().pct_change(n).into()
802
+ }
803
+
804
+ pub fn skew(&self, bias: bool) -> Self {
805
+ self.inner.clone().skew(bias).into()
806
+ }
807
+
808
+ pub fn kurtosis(&self, fisher: bool, bias: bool) -> Self {
809
+ self.inner.clone().kurtosis(fisher, bias).into()
810
+ }
811
+
812
+ pub fn reshape(&self, dims: Vec<i64>) -> Self {
813
+ self.inner.clone().reshape(&dims).into()
814
+ }
815
+
816
+ pub fn cumcount(&self, reverse: bool) -> Self {
817
+ self.inner.clone().cumcount(reverse).into()
818
+ }
819
+
820
+ pub fn to_physical(&self) -> Self {
821
+ self.inner
822
+ .clone()
823
+ .map(
824
+ |s| Ok(Some(s.to_physical_repr().into_owned())),
825
+ GetOutput::map_dtype(|dt| dt.to_physical()),
826
+ )
827
+ .with_fmt("to_physical")
828
+ .into()
829
+ }
830
+
831
+ pub fn shuffle(&self, seed: Option<u64>, fixed_seed: bool) -> Self {
832
+ self.inner.clone().shuffle(seed, fixed_seed).into()
833
+ }
834
+
835
+ pub fn sample_n(
836
+ &self,
837
+ n: usize,
838
+ with_replacement: bool,
839
+ shuffle: bool,
840
+ seed: Option<u64>,
841
+ fixed_seed: bool,
842
+ ) -> Self {
843
+ self.inner
844
+ .clone()
845
+ .sample_n(n, with_replacement, shuffle, seed, fixed_seed)
846
+ .into()
847
+ }
848
+
849
+ pub fn sample_frac(
850
+ &self,
851
+ frac: f64,
852
+ with_replacement: bool,
853
+ shuffle: bool,
854
+ seed: Option<u64>,
855
+ fixed_seed: bool,
856
+ ) -> Self {
857
+ self.inner
858
+ .clone()
859
+ .sample_frac(frac, with_replacement, shuffle, seed, fixed_seed)
860
+ .into()
861
+ }
862
+
863
+ pub fn ewm_mean(
864
+ &self,
865
+ alpha: f64,
866
+ adjust: bool,
867
+ min_periods: usize,
868
+ ignore_nulls: bool,
869
+ ) -> Self {
870
+ let options = EWMOptions {
871
+ alpha,
872
+ adjust,
873
+ bias: false,
874
+ min_periods,
875
+ ignore_nulls,
876
+ };
877
+ self.inner.clone().ewm_mean(options).into()
878
+ }
879
+
880
+ pub fn ewm_std(
881
+ &self,
882
+ alpha: f64,
883
+ adjust: bool,
884
+ bias: bool,
885
+ min_periods: usize,
886
+ ignore_nulls: bool,
887
+ ) -> Self {
888
+ let options = EWMOptions {
889
+ alpha,
890
+ adjust,
891
+ bias,
892
+ min_periods,
893
+ ignore_nulls,
894
+ };
895
+ self.inner.clone().ewm_std(options).into()
896
+ }
897
+
898
+ pub fn ewm_var(
899
+ &self,
900
+ alpha: f64,
901
+ adjust: bool,
902
+ bias: bool,
903
+ min_periods: usize,
904
+ ignore_nulls: bool,
905
+ ) -> Self {
906
+ let options = EWMOptions {
907
+ alpha,
908
+ adjust,
909
+ bias,
910
+ min_periods,
911
+ ignore_nulls,
912
+ };
913
+ self.inner.clone().ewm_var(options).into()
914
+ }
915
+
916
+ pub fn extend_constant(&self, value: Wrap<AnyValue>, n: usize) -> Self {
917
+ let value = value.into_value();
918
+ self.inner
919
+ .clone()
920
+ .apply(
921
+ move |s| {
922
+ let value = value.try_convert::<Wrap<AnyValue>>().unwrap().0;
923
+ s.extend_constant(value, n).map(Some)
924
+ },
925
+ GetOutput::same_type(),
926
+ )
927
+ .with_fmt("extend")
928
+ .into()
929
+ }
930
+
931
+ pub fn any(&self) -> Self {
932
+ self.inner.clone().any().into()
933
+ }
934
+
935
+ pub fn all(&self) -> Self {
936
+ self.inner.clone().all().into()
937
+ }
938
+
939
+ pub fn log(&self, base: f64) -> Self {
940
+ self.inner.clone().log(base).into()
941
+ }
942
+
943
+ pub fn exp(&self) -> Self {
944
+ self.inner.clone().exp().into()
945
+ }
946
+
947
+ pub fn entropy(&self, base: f64, normalize: bool) -> Self {
948
+ self.inner.clone().entropy(base, normalize).into()
949
+ }
950
+
951
+ pub fn hash(&self, seed: u64, seed_1: u64, seed_2: u64, seed_3: u64) -> Self {
952
+ self.inner.clone().hash(seed, seed_1, seed_2, seed_3).into()
953
+ }
954
+
955
+ pub fn set_sorted_flag(&self, descending: bool) -> Self {
956
+ let is_sorted = if descending {
957
+ IsSorted::Descending
958
+ } else {
959
+ IsSorted::Ascending
960
+ };
961
+ self.inner.clone().set_sorted_flag(is_sorted).into()
962
+ }
963
+ }