polars-df 0.1.0 → 0.1.1

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.
@@ -3,8 +3,9 @@ use polars::chunked_array::ops::SortOptions;
3
3
  use polars::lazy::dsl;
4
4
  use polars::lazy::dsl::Operator;
5
5
  use polars::prelude::*;
6
+ use polars::series::ops::NullBehavior;
6
7
 
7
- use crate::conversion::parse_fill_null_strategy;
8
+ use crate::conversion::*;
8
9
  use crate::lazy::utils::rb_exprs_to_exprs;
9
10
  use crate::RbResult;
10
11
 
@@ -21,10 +22,30 @@ impl From<dsl::Expr> for RbExpr {
21
22
  }
22
23
 
23
24
  impl RbExpr {
25
+ pub fn add(&self, rhs: &RbExpr) -> RbResult<Self> {
26
+ Ok(dsl::binary_expr(self.inner.clone(), Operator::Plus, rhs.inner.clone()).into())
27
+ }
28
+
29
+ pub fn sub(&self, rhs: &RbExpr) -> RbResult<Self> {
30
+ Ok(dsl::binary_expr(self.inner.clone(), Operator::Minus, rhs.inner.clone()).into())
31
+ }
32
+
24
33
  pub fn mul(&self, rhs: &RbExpr) -> RbResult<Self> {
25
34
  Ok(dsl::binary_expr(self.inner.clone(), Operator::Multiply, rhs.inner.clone()).into())
26
35
  }
27
36
 
37
+ pub fn truediv(&self, rhs: &RbExpr) -> RbResult<Self> {
38
+ Ok(dsl::binary_expr(self.inner.clone(), Operator::TrueDivide, rhs.inner.clone()).into())
39
+ }
40
+
41
+ pub fn _mod(&self, rhs: &RbExpr) -> RbResult<Self> {
42
+ Ok(dsl::binary_expr(self.inner.clone(), Operator::Modulus, rhs.inner.clone()).into())
43
+ }
44
+
45
+ pub fn floordiv(&self, rhs: &RbExpr) -> RbResult<Self> {
46
+ Ok(dsl::binary_expr(self.inner.clone(), Operator::FloorDivide, rhs.inner.clone()).into())
47
+ }
48
+
28
49
  pub fn to_str(&self) -> String {
29
50
  format!("{:?}", self.inner)
30
51
  }
@@ -69,6 +90,22 @@ impl RbExpr {
69
90
  self.clone().inner.is_not_null().into()
70
91
  }
71
92
 
93
+ pub fn is_infinite(&self) -> Self {
94
+ self.clone().inner.is_infinite().into()
95
+ }
96
+
97
+ pub fn is_finite(&self) -> Self {
98
+ self.clone().inner.is_finite().into()
99
+ }
100
+
101
+ pub fn is_nan(&self) -> Self {
102
+ self.clone().inner.is_nan().into()
103
+ }
104
+
105
+ pub fn is_not_nan(&self) -> Self {
106
+ self.clone().inner.is_not_nan().into()
107
+ }
108
+
72
109
  pub fn min(&self) -> Self {
73
110
  self.clone().inner.min().into()
74
111
  }
@@ -77,6 +114,14 @@ impl RbExpr {
77
114
  self.clone().inner.max().into()
78
115
  }
79
116
 
117
+ pub fn nan_max(&self) -> Self {
118
+ self.clone().inner.nan_max().into()
119
+ }
120
+
121
+ pub fn nan_min(&self) -> Self {
122
+ self.clone().inner.nan_min().into()
123
+ }
124
+
80
125
  pub fn mean(&self) -> Self {
81
126
  self.clone().inner.mean().into()
82
127
  }
@@ -93,6 +138,10 @@ impl RbExpr {
93
138
  self.clone().inner.n_unique().into()
94
139
  }
95
140
 
141
+ pub fn arg_unique(&self) -> Self {
142
+ self.clone().inner.arg_unique().into()
143
+ }
144
+
96
145
  pub fn unique(&self) -> Self {
97
146
  self.clone().inner.unique().into()
98
147
  }
@@ -112,10 +161,46 @@ impl RbExpr {
112
161
  self.clone().inner.list().into()
113
162
  }
114
163
 
164
+ pub fn quantile(&self, quantile: f64, interpolation: Wrap<QuantileInterpolOptions>) -> Self {
165
+ self.clone()
166
+ .inner
167
+ .quantile(quantile, interpolation.0)
168
+ .into()
169
+ }
170
+
171
+ pub fn agg_groups(&self) -> Self {
172
+ self.clone().inner.agg_groups().into()
173
+ }
174
+
115
175
  pub fn count(&self) -> Self {
116
176
  self.clone().inner.count().into()
117
177
  }
118
178
 
179
+ pub fn value_counts(&self, multithreaded: bool, sorted: bool) -> Self {
180
+ self.inner
181
+ .clone()
182
+ .value_counts(multithreaded, sorted)
183
+ .into()
184
+ }
185
+
186
+ pub fn unique_counts(&self) -> Self {
187
+ self.inner.clone().unique_counts().into()
188
+ }
189
+
190
+ pub fn null_count(&self) -> Self {
191
+ self.inner.clone().null_count().into()
192
+ }
193
+
194
+ pub fn cast(&self, data_type: Wrap<DataType>, strict: bool) -> RbResult<Self> {
195
+ let dt = data_type.0;
196
+ let expr = if strict {
197
+ self.inner.clone().strict_cast(dt)
198
+ } else {
199
+ self.inner.clone().cast(dt)
200
+ };
201
+ Ok(expr.into())
202
+ }
203
+
119
204
  pub fn sort_with(&self, descending: bool, nulls_last: bool) -> Self {
120
205
  self.clone()
121
206
  .inner
@@ -126,11 +211,62 @@ impl RbExpr {
126
211
  .into()
127
212
  }
128
213
 
214
+ pub fn arg_sort(&self, reverse: bool, nulls_last: bool) -> Self {
215
+ self.clone()
216
+ .inner
217
+ .arg_sort(SortOptions {
218
+ descending: reverse,
219
+ nulls_last,
220
+ })
221
+ .into()
222
+ }
223
+
224
+ pub fn top_k(&self, k: usize, reverse: bool) -> Self {
225
+ self.inner.clone().top_k(k, reverse).into()
226
+ }
227
+
228
+ pub fn arg_max(&self) -> Self {
229
+ self.clone().inner.arg_max().into()
230
+ }
231
+
232
+ pub fn arg_min(&self) -> Self {
233
+ self.clone().inner.arg_min().into()
234
+ }
235
+
236
+ pub fn search_sorted(&self, element: &RbExpr) -> Self {
237
+ self.inner
238
+ .clone()
239
+ .search_sorted(element.inner.clone())
240
+ .into()
241
+ }
242
+
243
+ pub fn take(&self, idx: &RbExpr) -> Self {
244
+ self.clone().inner.take(idx.inner.clone()).into()
245
+ }
246
+
129
247
  pub fn sort_by(&self, by: RArray, reverse: Vec<bool>) -> RbResult<Self> {
130
248
  let by = rb_exprs_to_exprs(by)?;
131
249
  Ok(self.clone().inner.sort_by(by, reverse).into())
132
250
  }
133
251
 
252
+ pub fn backward_fill(&self, limit: FillNullLimit) -> Self {
253
+ self.clone().inner.backward_fill(limit).into()
254
+ }
255
+
256
+ pub fn forward_fill(&self, limit: FillNullLimit) -> Self {
257
+ self.clone().inner.forward_fill(limit).into()
258
+ }
259
+
260
+ pub fn shift(&self, periods: i64) -> Self {
261
+ self.clone().inner.shift(periods).into()
262
+ }
263
+ pub fn shift_and_fill(&self, periods: i64, fill_value: &RbExpr) -> Self {
264
+ self.clone()
265
+ .inner
266
+ .shift_and_fill(periods, fill_value.inner.clone())
267
+ .into()
268
+ }
269
+
134
270
  pub fn fill_null(&self, expr: &RbExpr) -> Self {
135
271
  self.clone().inner.fill_null(expr.inner.clone()).into()
136
272
  }
@@ -177,6 +313,26 @@ impl RbExpr {
177
313
  self.clone().inner.var(ddof).into()
178
314
  }
179
315
 
316
+ pub fn is_unique(&self) -> Self {
317
+ self.clone().inner.is_unique().into()
318
+ }
319
+
320
+ pub fn is_first(&self) -> Self {
321
+ self.clone().inner.is_first().into()
322
+ }
323
+
324
+ pub fn explode(&self) -> Self {
325
+ self.clone().inner.explode().into()
326
+ }
327
+
328
+ pub fn take_every(&self, n: usize) -> Self {
329
+ self.clone()
330
+ .inner
331
+ .map(move |s: Series| Ok(s.take_every(n)), GetOutput::same_type())
332
+ .with_fmt("take_every")
333
+ .into()
334
+ }
335
+
180
336
  pub fn tail(&self, n: Option<usize>) -> Self {
181
337
  self.clone().inner.tail(n).into()
182
338
  }
@@ -185,6 +341,115 @@ impl RbExpr {
185
341
  self.clone().inner.head(n).into()
186
342
  }
187
343
 
344
+ pub fn slice(&self, offset: &RbExpr, length: &RbExpr) -> Self {
345
+ self.inner
346
+ .clone()
347
+ .slice(offset.inner.clone(), length.inner.clone())
348
+ .into()
349
+ }
350
+
351
+ pub fn append(&self, other: &RbExpr, upcast: bool) -> Self {
352
+ self.inner
353
+ .clone()
354
+ .append(other.inner.clone(), upcast)
355
+ .into()
356
+ }
357
+
358
+ pub fn rechunk(&self) -> Self {
359
+ self.inner
360
+ .clone()
361
+ .map(|s| Ok(s.rechunk()), GetOutput::same_type())
362
+ .into()
363
+ }
364
+
365
+ pub fn round(&self, decimals: u32) -> Self {
366
+ self.clone().inner.round(decimals).into()
367
+ }
368
+
369
+ pub fn floor(&self) -> Self {
370
+ self.clone().inner.floor().into()
371
+ }
372
+
373
+ pub fn ceil(&self) -> Self {
374
+ self.clone().inner.ceil().into()
375
+ }
376
+
377
+ pub fn clip(&self, min: Value, max: Value) -> Self {
378
+ let min = min.try_convert::<Wrap<AnyValue>>().unwrap().0;
379
+ let max = max.try_convert::<Wrap<AnyValue>>().unwrap().0;
380
+ self.clone().inner.clip(min, max).into()
381
+ }
382
+
383
+ pub fn clip_min(&self, min: Value) -> Self {
384
+ let min = min.try_convert::<Wrap<AnyValue>>().unwrap().0;
385
+ self.clone().inner.clip_min(min).into()
386
+ }
387
+
388
+ pub fn clip_max(&self, max: Value) -> Self {
389
+ let max = max.try_convert::<Wrap<AnyValue>>().unwrap().0;
390
+ self.clone().inner.clip_max(max).into()
391
+ }
392
+
393
+ pub fn abs(&self) -> Self {
394
+ self.clone().inner.abs().into()
395
+ }
396
+
397
+ pub fn sin(&self) -> Self {
398
+ self.clone().inner.sin().into()
399
+ }
400
+
401
+ pub fn cos(&self) -> Self {
402
+ self.clone().inner.cos().into()
403
+ }
404
+
405
+ pub fn tan(&self) -> Self {
406
+ self.clone().inner.tan().into()
407
+ }
408
+
409
+ pub fn arcsin(&self) -> Self {
410
+ self.clone().inner.arcsin().into()
411
+ }
412
+
413
+ pub fn arccos(&self) -> Self {
414
+ self.clone().inner.arccos().into()
415
+ }
416
+
417
+ pub fn arctan(&self) -> Self {
418
+ self.clone().inner.arctan().into()
419
+ }
420
+
421
+ pub fn sinh(&self) -> Self {
422
+ self.clone().inner.sinh().into()
423
+ }
424
+
425
+ pub fn cosh(&self) -> Self {
426
+ self.clone().inner.cosh().into()
427
+ }
428
+
429
+ pub fn tanh(&self) -> Self {
430
+ self.clone().inner.tanh().into()
431
+ }
432
+
433
+ pub fn arcsinh(&self) -> Self {
434
+ self.clone().inner.arcsinh().into()
435
+ }
436
+
437
+ pub fn arccosh(&self) -> Self {
438
+ self.clone().inner.arccosh().into()
439
+ }
440
+
441
+ pub fn arctanh(&self) -> Self {
442
+ self.clone().inner.arctanh().into()
443
+ }
444
+
445
+ pub fn sign(&self) -> Self {
446
+ self.clone().inner.sign().into()
447
+ }
448
+
449
+ pub fn is_duplicated(&self) -> Self {
450
+ self.clone().inner.is_duplicated().into()
451
+ }
452
+
188
453
  pub fn over(&self, partition_by: RArray) -> RbResult<Self> {
189
454
  let partition_by = rb_exprs_to_exprs(partition_by)?;
190
455
  Ok(self.clone().inner.over(partition_by).into())
@@ -202,11 +467,130 @@ impl RbExpr {
202
467
  self.clone().inner.or(expr.inner.clone()).into()
203
468
  }
204
469
 
470
+ pub fn is_in(&self, expr: &RbExpr) -> Self {
471
+ self.clone().inner.is_in(expr.inner.clone()).into()
472
+ }
473
+
474
+ pub fn repeat_by(&self, by: &RbExpr) -> Self {
475
+ self.clone().inner.repeat_by(by.inner.clone()).into()
476
+ }
477
+
478
+ pub fn pow(&self, exponent: &RbExpr) -> Self {
479
+ self.clone().inner.pow(exponent.inner.clone()).into()
480
+ }
481
+
482
+ pub fn cumsum(&self, reverse: bool) -> Self {
483
+ self.clone().inner.cumsum(reverse).into()
484
+ }
485
+
486
+ pub fn cummax(&self, reverse: bool) -> Self {
487
+ self.clone().inner.cummax(reverse).into()
488
+ }
489
+
490
+ pub fn cummin(&self, reverse: bool) -> Self {
491
+ self.clone().inner.cummin(reverse).into()
492
+ }
493
+
494
+ pub fn cumprod(&self, reverse: bool) -> Self {
495
+ self.clone().inner.cumprod(reverse).into()
496
+ }
497
+
205
498
  pub fn product(&self) -> Self {
206
499
  self.clone().inner.product().into()
207
500
  }
208
501
 
209
- pub fn str_lengths(&self) -> RbExpr {
502
+ pub fn shrink_dtype(&self) -> Self {
503
+ self.inner.clone().shrink_dtype().into()
504
+ }
505
+
506
+ pub fn str_parse_date(&self, fmt: Option<String>, strict: bool, exact: bool) -> Self {
507
+ self.inner
508
+ .clone()
509
+ .str()
510
+ .strptime(StrpTimeOptions {
511
+ date_dtype: DataType::Date,
512
+ fmt,
513
+ strict,
514
+ exact,
515
+ })
516
+ .into()
517
+ }
518
+
519
+ pub fn str_parse_datetime(&self, fmt: Option<String>, strict: bool, exact: bool) -> Self {
520
+ let tu = match fmt {
521
+ Some(ref fmt) => {
522
+ if fmt.contains("%.9f")
523
+ || fmt.contains("%9f")
524
+ || fmt.contains("%f")
525
+ || fmt.contains("%.f")
526
+ {
527
+ TimeUnit::Nanoseconds
528
+ } else if fmt.contains("%.3f") || fmt.contains("%3f") {
529
+ TimeUnit::Milliseconds
530
+ } else {
531
+ TimeUnit::Microseconds
532
+ }
533
+ }
534
+ None => TimeUnit::Microseconds,
535
+ };
536
+ self.inner
537
+ .clone()
538
+ .str()
539
+ .strptime(StrpTimeOptions {
540
+ date_dtype: DataType::Datetime(tu, None),
541
+ fmt,
542
+ strict,
543
+ exact,
544
+ })
545
+ .into()
546
+ }
547
+
548
+ pub fn str_parse_time(&self, fmt: Option<String>, strict: bool, exact: bool) -> Self {
549
+ self.inner
550
+ .clone()
551
+ .str()
552
+ .strptime(StrpTimeOptions {
553
+ date_dtype: DataType::Time,
554
+ fmt,
555
+ strict,
556
+ exact,
557
+ })
558
+ .into()
559
+ }
560
+
561
+ pub fn str_strip(&self, matches: Option<char>) -> Self {
562
+ self.inner.clone().str().strip(matches).into()
563
+ }
564
+
565
+ pub fn str_rstrip(&self, matches: Option<char>) -> Self {
566
+ self.inner.clone().str().rstrip(matches).into()
567
+ }
568
+
569
+ pub fn str_lstrip(&self, matches: Option<char>) -> Self {
570
+ self.inner.clone().str().lstrip(matches).into()
571
+ }
572
+
573
+ pub fn str_slice(&self, start: i64, length: Option<u64>) -> Self {
574
+ let function = move |s: Series| {
575
+ let ca = s.utf8()?;
576
+ Ok(ca.str_slice(start, length)?.into_series())
577
+ };
578
+ self.clone()
579
+ .inner
580
+ .map(function, GetOutput::from_type(DataType::Utf8))
581
+ .with_fmt("str.slice")
582
+ .into()
583
+ }
584
+
585
+ pub fn str_to_uppercase(&self) -> Self {
586
+ self.inner.clone().str().to_uppercase().into()
587
+ }
588
+
589
+ pub fn str_to_lowercase(&self) -> Self {
590
+ self.inner.clone().str().to_lowercase().into()
591
+ }
592
+
593
+ pub fn str_lengths(&self) -> Self {
210
594
  let function = |s: Series| {
211
595
  let ca = s.utf8()?;
212
596
  Ok(ca.str_lengths().into_series())
@@ -218,6 +602,46 @@ impl RbExpr {
218
602
  .into()
219
603
  }
220
604
 
605
+ pub fn str_n_chars(&self) -> Self {
606
+ let function = |s: Series| {
607
+ let ca = s.utf8()?;
608
+ Ok(ca.str_n_chars().into_series())
609
+ };
610
+ self.clone()
611
+ .inner
612
+ .map(function, GetOutput::from_type(DataType::UInt32))
613
+ .with_fmt("str.n_chars")
614
+ .into()
615
+ }
616
+
617
+ pub fn str_replace(&self, pat: &RbExpr, val: &RbExpr, literal: bool) -> Self {
618
+ self.inner
619
+ .clone()
620
+ .str()
621
+ .replace(pat.inner.clone(), val.inner.clone(), literal)
622
+ .into()
623
+ }
624
+
625
+ pub fn str_replace_all(&self, pat: &RbExpr, val: &RbExpr, literal: bool) -> Self {
626
+ self.inner
627
+ .clone()
628
+ .str()
629
+ .replace_all(pat.inner.clone(), val.inner.clone(), literal)
630
+ .into()
631
+ }
632
+
633
+ pub fn str_zfill(&self, alignment: usize) -> Self {
634
+ self.clone().inner.str().zfill(alignment).into()
635
+ }
636
+
637
+ pub fn str_ljust(&self, width: usize, fillchar: char) -> Self {
638
+ self.clone().inner.str().ljust(width, fillchar).into()
639
+ }
640
+
641
+ pub fn str_rjust(&self, width: usize, fillchar: char) -> Self {
642
+ self.clone().inner.str().rjust(width, fillchar).into()
643
+ }
644
+
221
645
  pub fn str_contains(&self, pat: String, literal: Option<bool>) -> Self {
222
646
  match literal {
223
647
  Some(true) => self.inner.clone().str().contains_literal(pat).into(),
@@ -225,17 +649,684 @@ impl RbExpr {
225
649
  }
226
650
  }
227
651
 
228
- pub fn prefix(&self, prefix: String) -> RbExpr {
652
+ pub fn str_ends_with(&self, sub: String) -> Self {
653
+ self.inner.clone().str().ends_with(sub).into()
654
+ }
655
+
656
+ pub fn str_starts_with(&self, sub: String) -> Self {
657
+ self.inner.clone().str().starts_with(sub).into()
658
+ }
659
+
660
+ pub fn str_extract(&self, pat: String, group_index: usize) -> Self {
661
+ self.inner.clone().str().extract(&pat, group_index).into()
662
+ }
663
+
664
+ pub fn str_extract_all(&self, pat: String) -> Self {
665
+ self.inner.clone().str().extract_all(&pat).into()
666
+ }
667
+
668
+ pub fn count_match(&self, pat: String) -> Self {
669
+ self.inner.clone().str().count_match(&pat).into()
670
+ }
671
+
672
+ pub fn strftime(&self, fmt: String) -> Self {
673
+ self.inner.clone().dt().strftime(&fmt).into()
674
+ }
675
+
676
+ pub fn str_split(&self, by: String) -> Self {
677
+ self.inner.clone().str().split(&by).into()
678
+ }
679
+
680
+ pub fn str_split_inclusive(&self, by: String) -> Self {
681
+ self.inner.clone().str().split_inclusive(&by).into()
682
+ }
683
+
684
+ pub fn str_split_exact(&self, by: String, n: usize) -> Self {
685
+ self.inner.clone().str().split_exact(&by, n).into()
686
+ }
687
+
688
+ pub fn str_split_exact_inclusive(&self, by: String, n: usize) -> Self {
689
+ self.inner
690
+ .clone()
691
+ .str()
692
+ .split_exact_inclusive(&by, n)
693
+ .into()
694
+ }
695
+
696
+ pub fn str_splitn(&self, by: String, n: usize) -> Self {
697
+ self.inner.clone().str().splitn(&by, n).into()
698
+ }
699
+
700
+ pub fn arr_lengths(&self) -> Self {
701
+ self.inner.clone().arr().lengths().into()
702
+ }
703
+
704
+ pub fn arr_contains(&self, other: &RbExpr) -> Self {
705
+ self.inner
706
+ .clone()
707
+ .arr()
708
+ .contains(other.inner.clone())
709
+ .into()
710
+ }
711
+
712
+ pub fn year(&self) -> Self {
713
+ self.clone().inner.dt().year().into()
714
+ }
715
+
716
+ pub fn iso_year(&self) -> Self {
717
+ self.clone().inner.dt().iso_year().into()
718
+ }
719
+
720
+ pub fn quarter(&self) -> Self {
721
+ self.clone().inner.dt().quarter().into()
722
+ }
723
+
724
+ pub fn month(&self) -> Self {
725
+ self.clone().inner.dt().month().into()
726
+ }
727
+
728
+ pub fn week(&self) -> Self {
729
+ self.clone().inner.dt().week().into()
730
+ }
731
+
732
+ pub fn weekday(&self) -> Self {
733
+ self.clone().inner.dt().weekday().into()
734
+ }
735
+
736
+ pub fn day(&self) -> Self {
737
+ self.clone().inner.dt().day().into()
738
+ }
739
+
740
+ pub fn ordinal_day(&self) -> Self {
741
+ self.clone().inner.dt().ordinal_day().into()
742
+ }
743
+
744
+ pub fn hour(&self) -> Self {
745
+ self.clone().inner.dt().hour().into()
746
+ }
747
+
748
+ pub fn minute(&self) -> Self {
749
+ self.clone().inner.dt().minute().into()
750
+ }
751
+
752
+ pub fn second(&self) -> Self {
753
+ self.clone().inner.dt().second().into()
754
+ }
755
+
756
+ pub fn millisecond(&self) -> Self {
757
+ self.clone().inner.dt().millisecond().into()
758
+ }
759
+
760
+ pub fn microsecond(&self) -> Self {
761
+ self.clone().inner.dt().microsecond().into()
762
+ }
763
+
764
+ pub fn nanosecond(&self) -> Self {
765
+ self.clone().inner.dt().nanosecond().into()
766
+ }
767
+
768
+ pub fn duration_days(&self) -> Self {
769
+ self.inner
770
+ .clone()
771
+ .map(
772
+ |s| Ok(s.duration()?.days().into_series()),
773
+ GetOutput::from_type(DataType::Int64),
774
+ )
775
+ .into()
776
+ }
777
+
778
+ pub fn duration_hours(&self) -> Self {
779
+ self.inner
780
+ .clone()
781
+ .map(
782
+ |s| Ok(s.duration()?.hours().into_series()),
783
+ GetOutput::from_type(DataType::Int64),
784
+ )
785
+ .into()
786
+ }
787
+
788
+ pub fn duration_minutes(&self) -> Self {
789
+ self.inner
790
+ .clone()
791
+ .map(
792
+ |s| Ok(s.duration()?.minutes().into_series()),
793
+ GetOutput::from_type(DataType::Int64),
794
+ )
795
+ .into()
796
+ }
797
+
798
+ pub fn duration_seconds(&self) -> Self {
799
+ self.inner
800
+ .clone()
801
+ .map(
802
+ |s| Ok(s.duration()?.seconds().into_series()),
803
+ GetOutput::from_type(DataType::Int64),
804
+ )
805
+ .into()
806
+ }
807
+
808
+ pub fn duration_nanoseconds(&self) -> Self {
809
+ self.inner
810
+ .clone()
811
+ .map(
812
+ |s| Ok(s.duration()?.nanoseconds().into_series()),
813
+ GetOutput::from_type(DataType::Int64),
814
+ )
815
+ .into()
816
+ }
817
+
818
+ pub fn duration_microseconds(&self) -> Self {
819
+ self.inner
820
+ .clone()
821
+ .map(
822
+ |s| Ok(s.duration()?.microseconds().into_series()),
823
+ GetOutput::from_type(DataType::Int64),
824
+ )
825
+ .into()
826
+ }
827
+
828
+ pub fn duration_milliseconds(&self) -> Self {
829
+ self.inner
830
+ .clone()
831
+ .map(
832
+ |s| Ok(s.duration()?.milliseconds().into_series()),
833
+ GetOutput::from_type(DataType::Int64),
834
+ )
835
+ .into()
836
+ }
837
+
838
+ pub fn timestamp(&self, tu: Wrap<TimeUnit>) -> Self {
839
+ self.inner.clone().dt().timestamp(tu.0).into()
840
+ }
841
+
842
+ pub fn dt_offset_by(&self, by: String) -> Self {
843
+ let by = Duration::parse(&by);
844
+ self.inner.clone().dt().offset_by(by).into()
845
+ }
846
+
847
+ pub fn dt_epoch_seconds(&self) -> Self {
848
+ self.clone()
849
+ .inner
850
+ .map(
851
+ |s| {
852
+ s.timestamp(TimeUnit::Milliseconds)
853
+ .map(|ca| (ca / 1000).into_series())
854
+ },
855
+ GetOutput::from_type(DataType::Int64),
856
+ )
857
+ .into()
858
+ }
859
+
860
+ pub fn dt_with_time_unit(&self, tu: Wrap<TimeUnit>) -> Self {
861
+ self.inner.clone().dt().with_time_unit(tu.0).into()
862
+ }
863
+
864
+ pub fn dt_with_time_zone(&self, tz: Option<TimeZone>) -> Self {
865
+ self.inner.clone().dt().with_time_zone(tz).into()
866
+ }
867
+
868
+ pub fn dt_cast_time_unit(&self, tu: Wrap<TimeUnit>) -> Self {
869
+ self.inner.clone().dt().cast_time_unit(tu.0).into()
870
+ }
871
+
872
+ pub fn dt_cast_time_zone(&self, tz: String) -> Self {
873
+ self.inner.clone().dt().cast_time_zone(tz).into()
874
+ }
875
+
876
+ pub fn dt_tz_localize(&self, tz: String) -> Self {
877
+ self.inner.clone().dt().tz_localize(tz).into()
878
+ }
879
+
880
+ pub fn dt_truncate(&self, every: String, offset: String) -> Self {
881
+ self.inner.clone().dt().truncate(&every, &offset).into()
882
+ }
883
+
884
+ pub fn dt_round(&self, every: String, offset: String) -> Self {
885
+ self.inner.clone().dt().round(&every, &offset).into()
886
+ }
887
+
888
+ pub fn mode(&self) -> Self {
889
+ self.inner.clone().mode().into()
890
+ }
891
+
892
+ pub fn keep_name(&self) -> Self {
893
+ self.inner.clone().keep_name().into()
894
+ }
895
+
896
+ pub fn prefix(&self, prefix: String) -> Self {
229
897
  self.inner.clone().prefix(&prefix).into()
230
898
  }
231
899
 
232
- pub fn suffix(&self, suffix: String) -> RbExpr {
900
+ pub fn suffix(&self, suffix: String) -> Self {
233
901
  self.inner.clone().suffix(&suffix).into()
234
902
  }
235
903
 
236
- pub fn interpolate(&self) -> RbExpr {
904
+ pub fn interpolate(&self) -> Self {
237
905
  self.inner.clone().interpolate().into()
238
906
  }
907
+
908
+ pub fn rolling_sum(
909
+ &self,
910
+ window_size: String,
911
+ weights: Option<Vec<f64>>,
912
+ min_periods: usize,
913
+ center: bool,
914
+ by: Option<String>,
915
+ closed: Option<Wrap<ClosedWindow>>,
916
+ ) -> Self {
917
+ let options = RollingOptions {
918
+ window_size: Duration::parse(&window_size),
919
+ weights,
920
+ min_periods,
921
+ center,
922
+ by,
923
+ closed_window: closed.map(|c| c.0),
924
+ };
925
+ self.inner.clone().rolling_sum(options).into()
926
+ }
927
+
928
+ pub fn rolling_min(
929
+ &self,
930
+ window_size: String,
931
+ weights: Option<Vec<f64>>,
932
+ min_periods: usize,
933
+ center: bool,
934
+ by: Option<String>,
935
+ closed: Option<Wrap<ClosedWindow>>,
936
+ ) -> Self {
937
+ let options = RollingOptions {
938
+ window_size: Duration::parse(&window_size),
939
+ weights,
940
+ min_periods,
941
+ center,
942
+ by,
943
+ closed_window: closed.map(|c| c.0),
944
+ };
945
+ self.inner.clone().rolling_min(options).into()
946
+ }
947
+
948
+ pub fn rolling_max(
949
+ &self,
950
+ window_size: String,
951
+ weights: Option<Vec<f64>>,
952
+ min_periods: usize,
953
+ center: bool,
954
+ by: Option<String>,
955
+ closed: Option<Wrap<ClosedWindow>>,
956
+ ) -> Self {
957
+ let options = RollingOptions {
958
+ window_size: Duration::parse(&window_size),
959
+ weights,
960
+ min_periods,
961
+ center,
962
+ by,
963
+ closed_window: closed.map(|c| c.0),
964
+ };
965
+ self.inner.clone().rolling_max(options).into()
966
+ }
967
+
968
+ pub fn rolling_mean(
969
+ &self,
970
+ window_size: String,
971
+ weights: Option<Vec<f64>>,
972
+ min_periods: usize,
973
+ center: bool,
974
+ by: Option<String>,
975
+ closed: Option<Wrap<ClosedWindow>>,
976
+ ) -> Self {
977
+ let options = RollingOptions {
978
+ window_size: Duration::parse(&window_size),
979
+ weights,
980
+ min_periods,
981
+ center,
982
+ by,
983
+ closed_window: closed.map(|c| c.0),
984
+ };
985
+
986
+ self.inner.clone().rolling_mean(options).into()
987
+ }
988
+
989
+ pub fn rolling_std(
990
+ &self,
991
+ window_size: String,
992
+ weights: Option<Vec<f64>>,
993
+ min_periods: usize,
994
+ center: bool,
995
+ by: Option<String>,
996
+ closed: Option<Wrap<ClosedWindow>>,
997
+ ) -> Self {
998
+ let options = RollingOptions {
999
+ window_size: Duration::parse(&window_size),
1000
+ weights,
1001
+ min_periods,
1002
+ center,
1003
+ by,
1004
+ closed_window: closed.map(|c| c.0),
1005
+ };
1006
+
1007
+ self.inner.clone().rolling_std(options).into()
1008
+ }
1009
+
1010
+ pub fn rolling_var(
1011
+ &self,
1012
+ window_size: String,
1013
+ weights: Option<Vec<f64>>,
1014
+ min_periods: usize,
1015
+ center: bool,
1016
+ by: Option<String>,
1017
+ closed: Option<Wrap<ClosedWindow>>,
1018
+ ) -> Self {
1019
+ let options = RollingOptions {
1020
+ window_size: Duration::parse(&window_size),
1021
+ weights,
1022
+ min_periods,
1023
+ center,
1024
+ by,
1025
+ closed_window: closed.map(|c| c.0),
1026
+ };
1027
+
1028
+ self.inner.clone().rolling_var(options).into()
1029
+ }
1030
+
1031
+ pub fn rolling_median(
1032
+ &self,
1033
+ window_size: String,
1034
+ weights: Option<Vec<f64>>,
1035
+ min_periods: usize,
1036
+ center: bool,
1037
+ by: Option<String>,
1038
+ closed: Option<Wrap<ClosedWindow>>,
1039
+ ) -> Self {
1040
+ let options = RollingOptions {
1041
+ window_size: Duration::parse(&window_size),
1042
+ weights,
1043
+ min_periods,
1044
+ center,
1045
+ by,
1046
+ closed_window: closed.map(|c| c.0),
1047
+ };
1048
+ self.inner.clone().rolling_median(options).into()
1049
+ }
1050
+
1051
+ #[allow(clippy::too_many_arguments)]
1052
+ pub fn rolling_quantile(
1053
+ &self,
1054
+ quantile: f64,
1055
+ interpolation: Wrap<QuantileInterpolOptions>,
1056
+ window_size: String,
1057
+ weights: Option<Vec<f64>>,
1058
+ min_periods: usize,
1059
+ center: bool,
1060
+ by: Option<String>,
1061
+ closed: Option<Wrap<ClosedWindow>>,
1062
+ ) -> Self {
1063
+ let options = RollingOptions {
1064
+ window_size: Duration::parse(&window_size),
1065
+ weights,
1066
+ min_periods,
1067
+ center,
1068
+ by,
1069
+ closed_window: closed.map(|c| c.0),
1070
+ };
1071
+
1072
+ self.inner
1073
+ .clone()
1074
+ .rolling_quantile(quantile, interpolation.0, options)
1075
+ .into()
1076
+ }
1077
+
1078
+ pub fn rolling_skew(&self, window_size: usize, bias: bool) -> Self {
1079
+ self.inner
1080
+ .clone()
1081
+ .rolling_apply_float(window_size, move |ca| {
1082
+ ca.clone().into_series().skew(bias).unwrap()
1083
+ })
1084
+ .into()
1085
+ }
1086
+
1087
+ pub fn lower_bound(&self) -> Self {
1088
+ self.inner.clone().lower_bound().into()
1089
+ }
1090
+
1091
+ pub fn upper_bound(&self) -> Self {
1092
+ self.inner.clone().upper_bound().into()
1093
+ }
1094
+
1095
+ pub fn lst_max(&self) -> Self {
1096
+ self.inner.clone().arr().max().into()
1097
+ }
1098
+
1099
+ pub fn lst_min(&self) -> Self {
1100
+ self.inner.clone().arr().min().into()
1101
+ }
1102
+
1103
+ pub fn lst_sum(&self) -> Self {
1104
+ self.inner.clone().arr().sum().with_fmt("arr.sum").into()
1105
+ }
1106
+
1107
+ pub fn lst_mean(&self) -> Self {
1108
+ self.inner.clone().arr().mean().with_fmt("arr.mean").into()
1109
+ }
1110
+
1111
+ pub fn lst_sort(&self, reverse: bool) -> Self {
1112
+ self.inner
1113
+ .clone()
1114
+ .arr()
1115
+ .sort(SortOptions {
1116
+ descending: reverse,
1117
+ ..Default::default()
1118
+ })
1119
+ .with_fmt("arr.sort")
1120
+ .into()
1121
+ }
1122
+
1123
+ pub fn lst_reverse(&self) -> Self {
1124
+ self.inner
1125
+ .clone()
1126
+ .arr()
1127
+ .reverse()
1128
+ .with_fmt("arr.reverse")
1129
+ .into()
1130
+ }
1131
+
1132
+ pub fn lst_unique(&self) -> Self {
1133
+ self.inner
1134
+ .clone()
1135
+ .arr()
1136
+ .unique()
1137
+ .with_fmt("arr.unique")
1138
+ .into()
1139
+ }
1140
+
1141
+ pub fn lst_get(&self, index: &RbExpr) -> Self {
1142
+ self.inner.clone().arr().get(index.inner.clone()).into()
1143
+ }
1144
+
1145
+ pub fn lst_join(&self, separator: String) -> Self {
1146
+ self.inner.clone().arr().join(&separator).into()
1147
+ }
1148
+
1149
+ pub fn lst_arg_min(&self) -> Self {
1150
+ self.inner.clone().arr().arg_min().into()
1151
+ }
1152
+
1153
+ pub fn lst_arg_max(&self) -> Self {
1154
+ self.inner.clone().arr().arg_max().into()
1155
+ }
1156
+
1157
+ pub fn lst_diff(&self, n: usize, null_behavior: Wrap<NullBehavior>) -> RbResult<Self> {
1158
+ Ok(self.inner.clone().arr().diff(n, null_behavior.0).into())
1159
+ }
1160
+
1161
+ pub fn lst_shift(&self, periods: i64) -> Self {
1162
+ self.inner.clone().arr().shift(periods).into()
1163
+ }
1164
+
1165
+ pub fn lst_slice(&self, offset: &RbExpr, length: Option<&RbExpr>) -> Self {
1166
+ let length = match length {
1167
+ Some(i) => i.inner.clone(),
1168
+ None => dsl::lit(i64::MAX),
1169
+ };
1170
+ self.inner
1171
+ .clone()
1172
+ .arr()
1173
+ .slice(offset.inner.clone(), length)
1174
+ .into()
1175
+ }
1176
+
1177
+ pub fn lst_eval(&self, expr: &RbExpr, parallel: bool) -> Self {
1178
+ self.inner
1179
+ .clone()
1180
+ .arr()
1181
+ .eval(expr.inner.clone(), parallel)
1182
+ .into()
1183
+ }
1184
+
1185
+ pub fn cumulative_eval(&self, expr: &RbExpr, min_periods: usize, parallel: bool) -> Self {
1186
+ self.inner
1187
+ .clone()
1188
+ .cumulative_eval(expr.inner.clone(), min_periods, parallel)
1189
+ .into()
1190
+ }
1191
+
1192
+ pub fn rank(&self, method: Wrap<RankMethod>, reverse: bool) -> Self {
1193
+ let options = RankOptions {
1194
+ method: method.0,
1195
+ descending: reverse,
1196
+ };
1197
+ self.inner.clone().rank(options).into()
1198
+ }
1199
+
1200
+ pub fn diff(&self, n: usize, null_behavior: Wrap<NullBehavior>) -> Self {
1201
+ self.inner.clone().diff(n, null_behavior.0).into()
1202
+ }
1203
+
1204
+ pub fn pct_change(&self, n: usize) -> Self {
1205
+ self.inner.clone().pct_change(n).into()
1206
+ }
1207
+
1208
+ pub fn skew(&self, bias: bool) -> Self {
1209
+ self.inner.clone().skew(bias).into()
1210
+ }
1211
+
1212
+ pub fn kurtosis(&self, fisher: bool, bias: bool) -> Self {
1213
+ self.inner.clone().kurtosis(fisher, bias).into()
1214
+ }
1215
+
1216
+ pub fn str_concat(&self, delimiter: String) -> Self {
1217
+ self.inner.clone().str().concat(&delimiter).into()
1218
+ }
1219
+
1220
+ pub fn cat_set_ordering(&self, ordering: Wrap<CategoricalOrdering>) -> Self {
1221
+ self.inner.clone().cat().set_ordering(ordering.0).into()
1222
+ }
1223
+
1224
+ pub fn reshape(&self, dims: Vec<i64>) -> Self {
1225
+ self.inner.clone().reshape(&dims).into()
1226
+ }
1227
+
1228
+ pub fn cumcount(&self, reverse: bool) -> Self {
1229
+ self.inner.clone().cumcount(reverse).into()
1230
+ }
1231
+
1232
+ pub fn to_physical(&self) -> Self {
1233
+ self.inner
1234
+ .clone()
1235
+ .map(
1236
+ |s| Ok(s.to_physical_repr().into_owned()),
1237
+ GetOutput::map_dtype(|dt| dt.to_physical()),
1238
+ )
1239
+ .with_fmt("to_physical")
1240
+ .into()
1241
+ }
1242
+
1243
+ pub fn shuffle(&self, seed: Option<u64>) -> Self {
1244
+ self.inner.clone().shuffle(seed).into()
1245
+ }
1246
+
1247
+ pub fn sample_n(
1248
+ &self,
1249
+ n: usize,
1250
+ with_replacement: bool,
1251
+ shuffle: bool,
1252
+ seed: Option<u64>,
1253
+ ) -> Self {
1254
+ self.inner
1255
+ .clone()
1256
+ .sample_n(n, with_replacement, shuffle, seed)
1257
+ .into()
1258
+ }
1259
+
1260
+ pub fn sample_frac(
1261
+ &self,
1262
+ frac: f64,
1263
+ with_replacement: bool,
1264
+ shuffle: bool,
1265
+ seed: Option<u64>,
1266
+ ) -> Self {
1267
+ self.inner
1268
+ .clone()
1269
+ .sample_frac(frac, with_replacement, shuffle, seed)
1270
+ .into()
1271
+ }
1272
+
1273
+ pub fn ewm_mean(&self, alpha: f64, adjust: bool, min_periods: usize) -> Self {
1274
+ let options = EWMOptions {
1275
+ alpha,
1276
+ adjust,
1277
+ bias: false,
1278
+ min_periods,
1279
+ };
1280
+ self.inner.clone().ewm_mean(options).into()
1281
+ }
1282
+
1283
+ pub fn ewm_std(&self, alpha: f64, adjust: bool, bias: bool, min_periods: usize) -> Self {
1284
+ let options = EWMOptions {
1285
+ alpha,
1286
+ adjust,
1287
+ bias,
1288
+ min_periods,
1289
+ };
1290
+ self.inner.clone().ewm_std(options).into()
1291
+ }
1292
+
1293
+ pub fn ewm_var(&self, alpha: f64, adjust: bool, bias: bool, min_periods: usize) -> Self {
1294
+ let options = EWMOptions {
1295
+ alpha,
1296
+ adjust,
1297
+ bias,
1298
+ min_periods,
1299
+ };
1300
+ self.inner.clone().ewm_var(options).into()
1301
+ }
1302
+
1303
+ pub fn any(&self) -> Self {
1304
+ self.inner.clone().any().into()
1305
+ }
1306
+
1307
+ pub fn all(&self) -> Self {
1308
+ self.inner.clone().all().into()
1309
+ }
1310
+
1311
+ pub fn struct_field_by_name(&self, name: String) -> Self {
1312
+ self.inner.clone().struct_().field_by_name(&name).into()
1313
+ }
1314
+
1315
+ pub fn struct_field_by_index(&self, index: i64) -> Self {
1316
+ self.inner.clone().struct_().field_by_index(index).into()
1317
+ }
1318
+
1319
+ pub fn struct_rename_fields(&self, names: Vec<String>) -> Self {
1320
+ self.inner.clone().struct_().rename_fields(names).into()
1321
+ }
1322
+
1323
+ pub fn log(&self, base: f64) -> Self {
1324
+ self.inner.clone().log(base).into()
1325
+ }
1326
+
1327
+ pub fn exp(&self) -> Self {
1328
+ self.inner.clone().exp().into()
1329
+ }
239
1330
  }
240
1331
 
241
1332
  pub fn col(name: String) -> RbExpr {