polars-df 0.5.0 → 0.7.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 +26 -0
- data/Cargo.lock +595 -709
- data/Cargo.toml +1 -0
- data/README.md +11 -9
- data/ext/polars/Cargo.toml +18 -10
- data/ext/polars/src/batched_csv.rs +26 -26
- data/ext/polars/src/conversion.rs +272 -136
- data/ext/polars/src/dataframe.rs +135 -94
- data/ext/polars/src/error.rs +8 -5
- data/ext/polars/src/expr/array.rs +15 -0
- data/ext/polars/src/expr/binary.rs +18 -6
- data/ext/polars/src/expr/datetime.rs +10 -12
- data/ext/polars/src/expr/general.rs +78 -264
- data/ext/polars/src/expr/list.rs +41 -28
- data/ext/polars/src/{expr.rs → expr/mod.rs} +5 -2
- data/ext/polars/src/expr/name.rs +44 -0
- data/ext/polars/src/expr/rolling.rs +196 -0
- data/ext/polars/src/expr/string.rs +94 -66
- data/ext/polars/src/file.rs +3 -3
- data/ext/polars/src/functions/aggregation.rs +35 -0
- data/ext/polars/src/functions/eager.rs +7 -31
- data/ext/polars/src/functions/io.rs +10 -10
- data/ext/polars/src/functions/lazy.rs +119 -54
- data/ext/polars/src/functions/meta.rs +30 -0
- data/ext/polars/src/functions/misc.rs +8 -0
- data/ext/polars/src/functions/mod.rs +5 -0
- data/ext/polars/src/functions/random.rs +6 -0
- data/ext/polars/src/functions/range.rs +46 -0
- data/ext/polars/src/functions/string_cache.rs +11 -0
- data/ext/polars/src/functions/whenthen.rs +7 -7
- data/ext/polars/src/lazyframe.rs +61 -44
- data/ext/polars/src/lib.rs +173 -84
- data/ext/polars/src/{apply → map}/dataframe.rs +28 -33
- data/ext/polars/src/{apply → map}/mod.rs +10 -6
- data/ext/polars/src/{apply → map}/series.rs +12 -16
- data/ext/polars/src/object.rs +2 -2
- data/ext/polars/src/rb_modules.rs +25 -6
- data/ext/polars/src/series/construction.rs +32 -6
- data/ext/polars/src/series/export.rs +2 -2
- data/ext/polars/src/series/set_at_idx.rs +33 -17
- data/ext/polars/src/series.rs +62 -42
- data/ext/polars/src/sql.rs +46 -0
- data/lib/polars/array_expr.rb +84 -0
- data/lib/polars/array_name_space.rb +77 -0
- data/lib/polars/batched_csv_reader.rb +1 -1
- data/lib/polars/config.rb +530 -0
- data/lib/polars/data_frame.rb +206 -131
- data/lib/polars/data_types.rb +163 -29
- data/lib/polars/date_time_expr.rb +13 -18
- data/lib/polars/date_time_name_space.rb +22 -28
- data/lib/polars/dynamic_group_by.rb +2 -2
- data/lib/polars/expr.rb +241 -151
- data/lib/polars/functions.rb +29 -38
- data/lib/polars/group_by.rb +38 -76
- data/lib/polars/io.rb +37 -2
- data/lib/polars/lazy_frame.rb +174 -95
- data/lib/polars/lazy_functions.rb +87 -63
- data/lib/polars/lazy_group_by.rb +7 -8
- data/lib/polars/list_expr.rb +40 -36
- data/lib/polars/list_name_space.rb +15 -15
- data/lib/polars/name_expr.rb +198 -0
- data/lib/polars/rolling_group_by.rb +6 -4
- data/lib/polars/series.rb +95 -28
- data/lib/polars/sql_context.rb +194 -0
- data/lib/polars/string_expr.rb +249 -69
- data/lib/polars/string_name_space.rb +155 -25
- data/lib/polars/utils.rb +119 -57
- data/lib/polars/version.rb +1 -1
- data/lib/polars.rb +6 -0
- metadata +21 -7
- /data/ext/polars/src/{apply → map}/lazy.rs +0 -0
@@ -1,10 +1,11 @@
|
|
1
|
-
use magnus::{
|
1
|
+
use magnus::{prelude::*, value::Opaque, IntoValue, RArray, Ruby, Value};
|
2
2
|
use polars::lazy::dsl;
|
3
3
|
use polars::prelude::*;
|
4
4
|
use polars::series::ops::NullBehavior;
|
5
|
+
use polars_core::series::IsSorted;
|
5
6
|
|
6
|
-
use crate::apply::lazy::map_single;
|
7
7
|
use crate::conversion::{parse_fill_null_strategy, Wrap};
|
8
|
+
use crate::map::lazy::map_single;
|
8
9
|
use crate::rb_exprs_to_exprs;
|
9
10
|
use crate::utils::reinterpret;
|
10
11
|
use crate::{RbExpr, RbResult};
|
@@ -201,6 +202,7 @@ impl RbExpr {
|
|
201
202
|
descending,
|
202
203
|
nulls_last,
|
203
204
|
multithreaded: true,
|
205
|
+
maintain_order: false,
|
204
206
|
})
|
205
207
|
.into()
|
206
208
|
}
|
@@ -212,16 +214,25 @@ impl RbExpr {
|
|
212
214
|
descending: reverse,
|
213
215
|
nulls_last,
|
214
216
|
multithreaded: true,
|
217
|
+
maintain_order: false,
|
215
218
|
})
|
216
219
|
.into()
|
217
220
|
}
|
218
221
|
|
219
|
-
pub fn top_k(&self, k:
|
220
|
-
self.inner.clone().top_k(k).into()
|
222
|
+
pub fn top_k(&self, k: &Self) -> Self {
|
223
|
+
self.inner.clone().top_k(k.inner.clone()).into()
|
221
224
|
}
|
222
225
|
|
223
|
-
pub fn bottom_k(&self, k:
|
224
|
-
self.inner.clone().bottom_k(k).into()
|
226
|
+
pub fn bottom_k(&self, k: &Self) -> Self {
|
227
|
+
self.inner.clone().bottom_k(k.inner.clone()).into()
|
228
|
+
}
|
229
|
+
|
230
|
+
pub fn peak_min(&self) -> Self {
|
231
|
+
self.inner.clone().peak_min().into()
|
232
|
+
}
|
233
|
+
|
234
|
+
pub fn peak_max(&self) -> Self {
|
235
|
+
self.inner.clone().peak_max().into()
|
225
236
|
}
|
226
237
|
|
227
238
|
pub fn arg_max(&self) -> Self {
|
@@ -239,8 +250,8 @@ impl RbExpr {
|
|
239
250
|
.into()
|
240
251
|
}
|
241
252
|
|
242
|
-
pub fn
|
243
|
-
self.clone().inner.
|
253
|
+
pub fn gather(&self, idx: &RbExpr) -> Self {
|
254
|
+
self.clone().inner.gather(idx.inner.clone()).into()
|
244
255
|
}
|
245
256
|
|
246
257
|
pub fn sort_by(&self, by: RArray, reverse: Vec<bool>) -> RbResult<Self> {
|
@@ -256,14 +267,13 @@ impl RbExpr {
|
|
256
267
|
self.clone().inner.forward_fill(limit).into()
|
257
268
|
}
|
258
269
|
|
259
|
-
pub fn shift(&self,
|
260
|
-
self.
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
.into()
|
270
|
+
pub fn shift(&self, n: &Self, fill_value: Option<&Self>) -> Self {
|
271
|
+
let expr = self.inner.clone();
|
272
|
+
let out = match fill_value {
|
273
|
+
Some(v) => expr.shift_and_fill(n.inner.clone(), v.inner.clone()),
|
274
|
+
None => expr.shift(n.inner.clone()),
|
275
|
+
};
|
276
|
+
out.into()
|
267
277
|
}
|
268
278
|
|
269
279
|
pub fn fill_null(&self, expr: &RbExpr) -> Self {
|
@@ -319,26 +329,30 @@ impl RbExpr {
|
|
319
329
|
self.clone().inner.is_unique().into()
|
320
330
|
}
|
321
331
|
|
322
|
-
pub fn
|
323
|
-
self.clone().inner.
|
332
|
+
pub fn approx_n_unique(&self) -> Self {
|
333
|
+
self.clone().inner.approx_n_unique().into()
|
334
|
+
}
|
335
|
+
|
336
|
+
pub fn is_first_distinct(&self) -> Self {
|
337
|
+
self.clone().inner.is_first_distinct().into()
|
324
338
|
}
|
325
339
|
|
326
|
-
pub fn
|
327
|
-
self.clone().inner.
|
340
|
+
pub fn is_last_distinct(&self) -> Self {
|
341
|
+
self.clone().inner.is_last_distinct().into()
|
328
342
|
}
|
329
343
|
|
330
344
|
pub fn explode(&self) -> Self {
|
331
345
|
self.clone().inner.explode().into()
|
332
346
|
}
|
333
347
|
|
334
|
-
pub fn
|
348
|
+
pub fn gather_every(&self, n: usize) -> Self {
|
335
349
|
self.clone()
|
336
350
|
.inner
|
337
351
|
.map(
|
338
|
-
move |s: Series| Ok(Some(s.
|
352
|
+
move |s: Series| Ok(Some(s.gather_every(n))),
|
339
353
|
GetOutput::same_type(),
|
340
354
|
)
|
341
|
-
.with_fmt("
|
355
|
+
.with_fmt("gather_every")
|
342
356
|
.into()
|
343
357
|
}
|
344
358
|
|
@@ -383,20 +397,15 @@ impl RbExpr {
|
|
383
397
|
self.clone().inner.ceil().into()
|
384
398
|
}
|
385
399
|
|
386
|
-
pub fn clip(&self, min:
|
387
|
-
let
|
388
|
-
let
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
}
|
396
|
-
|
397
|
-
pub fn clip_max(&self, max: Value) -> Self {
|
398
|
-
let max = max.try_convert::<Wrap<AnyValue>>().unwrap().0;
|
399
|
-
self.clone().inner.clip_max(max).into()
|
400
|
+
pub fn clip(&self, min: Option<&Self>, max: Option<&Self>) -> Self {
|
401
|
+
let expr = self.inner.clone();
|
402
|
+
let out = match (min, max) {
|
403
|
+
(Some(min), Some(max)) => expr.clip(min.inner.clone(), max.inner.clone()),
|
404
|
+
(Some(min), None) => expr.clip_min(min.inner.clone()),
|
405
|
+
(None, Some(max)) => expr.clip_max(max.inner.clone()),
|
406
|
+
(None, None) => expr,
|
407
|
+
};
|
408
|
+
out.into()
|
400
409
|
}
|
401
410
|
|
402
411
|
pub fn abs(&self) -> Self {
|
@@ -488,20 +497,20 @@ impl RbExpr {
|
|
488
497
|
self.clone().inner.pow(exponent.inner.clone()).into()
|
489
498
|
}
|
490
499
|
|
491
|
-
pub fn
|
492
|
-
self.clone().inner.
|
500
|
+
pub fn cum_sum(&self, reverse: bool) -> Self {
|
501
|
+
self.clone().inner.cum_sum(reverse).into()
|
493
502
|
}
|
494
503
|
|
495
|
-
pub fn
|
496
|
-
self.clone().inner.
|
504
|
+
pub fn cum_max(&self, reverse: bool) -> Self {
|
505
|
+
self.clone().inner.cum_max(reverse).into()
|
497
506
|
}
|
498
507
|
|
499
|
-
pub fn
|
500
|
-
self.clone().inner.
|
508
|
+
pub fn cum_min(&self, reverse: bool) -> Self {
|
509
|
+
self.clone().inner.cum_min(reverse).into()
|
501
510
|
}
|
502
511
|
|
503
|
-
pub fn
|
504
|
-
self.clone().inner.
|
512
|
+
pub fn cum_prod(&self, reverse: bool) -> Self {
|
513
|
+
self.clone().inner.cum_prod(reverse).into()
|
505
514
|
}
|
506
515
|
|
507
516
|
pub fn product(&self) -> Self {
|
@@ -537,33 +546,6 @@ impl RbExpr {
|
|
537
546
|
self.inner.clone().mode().into()
|
538
547
|
}
|
539
548
|
|
540
|
-
pub fn keep_name(&self) -> Self {
|
541
|
-
self.inner.clone().keep_name().into()
|
542
|
-
}
|
543
|
-
|
544
|
-
pub fn prefix(&self, prefix: String) -> Self {
|
545
|
-
self.inner.clone().prefix(&prefix).into()
|
546
|
-
}
|
547
|
-
|
548
|
-
pub fn suffix(&self, suffix: String) -> Self {
|
549
|
-
self.inner.clone().suffix(&suffix).into()
|
550
|
-
}
|
551
|
-
|
552
|
-
pub fn map_alias(&self, lambda: Proc) -> Self {
|
553
|
-
self.inner
|
554
|
-
.clone()
|
555
|
-
.map_alias(move |name| {
|
556
|
-
let out = lambda.call::<_, String>((name,));
|
557
|
-
match out {
|
558
|
-
Ok(out) => Ok(out),
|
559
|
-
Err(e) => Err(PolarsError::ComputeError(
|
560
|
-
format!("Ruby function in 'map_alias' produced an error: {}.", e).into(),
|
561
|
-
)),
|
562
|
-
}
|
563
|
-
})
|
564
|
-
.into()
|
565
|
-
}
|
566
|
-
|
567
549
|
pub fn exclude(&self, columns: Vec<String>) -> Self {
|
568
550
|
self.inner.clone().exclude(columns).into()
|
569
551
|
}
|
@@ -572,185 +554,6 @@ impl RbExpr {
|
|
572
554
|
self.inner.clone().interpolate(method.0).into()
|
573
555
|
}
|
574
556
|
|
575
|
-
pub fn rolling_sum(
|
576
|
-
&self,
|
577
|
-
window_size: String,
|
578
|
-
weights: Option<Vec<f64>>,
|
579
|
-
min_periods: usize,
|
580
|
-
center: bool,
|
581
|
-
by: Option<String>,
|
582
|
-
closed: Option<Wrap<ClosedWindow>>,
|
583
|
-
) -> Self {
|
584
|
-
let options = RollingOptions {
|
585
|
-
window_size: Duration::parse(&window_size),
|
586
|
-
weights,
|
587
|
-
min_periods,
|
588
|
-
center,
|
589
|
-
by,
|
590
|
-
closed_window: closed.map(|c| c.0),
|
591
|
-
};
|
592
|
-
self.inner.clone().rolling_sum(options).into()
|
593
|
-
}
|
594
|
-
|
595
|
-
pub fn rolling_min(
|
596
|
-
&self,
|
597
|
-
window_size: String,
|
598
|
-
weights: Option<Vec<f64>>,
|
599
|
-
min_periods: usize,
|
600
|
-
center: bool,
|
601
|
-
by: Option<String>,
|
602
|
-
closed: Option<Wrap<ClosedWindow>>,
|
603
|
-
) -> Self {
|
604
|
-
let options = RollingOptions {
|
605
|
-
window_size: Duration::parse(&window_size),
|
606
|
-
weights,
|
607
|
-
min_periods,
|
608
|
-
center,
|
609
|
-
by,
|
610
|
-
closed_window: closed.map(|c| c.0),
|
611
|
-
};
|
612
|
-
self.inner.clone().rolling_min(options).into()
|
613
|
-
}
|
614
|
-
|
615
|
-
pub fn rolling_max(
|
616
|
-
&self,
|
617
|
-
window_size: String,
|
618
|
-
weights: Option<Vec<f64>>,
|
619
|
-
min_periods: usize,
|
620
|
-
center: bool,
|
621
|
-
by: Option<String>,
|
622
|
-
closed: Option<Wrap<ClosedWindow>>,
|
623
|
-
) -> Self {
|
624
|
-
let options = RollingOptions {
|
625
|
-
window_size: Duration::parse(&window_size),
|
626
|
-
weights,
|
627
|
-
min_periods,
|
628
|
-
center,
|
629
|
-
by,
|
630
|
-
closed_window: closed.map(|c| c.0),
|
631
|
-
};
|
632
|
-
self.inner.clone().rolling_max(options).into()
|
633
|
-
}
|
634
|
-
|
635
|
-
pub fn rolling_mean(
|
636
|
-
&self,
|
637
|
-
window_size: String,
|
638
|
-
weights: Option<Vec<f64>>,
|
639
|
-
min_periods: usize,
|
640
|
-
center: bool,
|
641
|
-
by: Option<String>,
|
642
|
-
closed: Option<Wrap<ClosedWindow>>,
|
643
|
-
) -> Self {
|
644
|
-
let options = RollingOptions {
|
645
|
-
window_size: Duration::parse(&window_size),
|
646
|
-
weights,
|
647
|
-
min_periods,
|
648
|
-
center,
|
649
|
-
by,
|
650
|
-
closed_window: closed.map(|c| c.0),
|
651
|
-
};
|
652
|
-
|
653
|
-
self.inner.clone().rolling_mean(options).into()
|
654
|
-
}
|
655
|
-
|
656
|
-
pub fn rolling_std(
|
657
|
-
&self,
|
658
|
-
window_size: String,
|
659
|
-
weights: Option<Vec<f64>>,
|
660
|
-
min_periods: usize,
|
661
|
-
center: bool,
|
662
|
-
by: Option<String>,
|
663
|
-
closed: Option<Wrap<ClosedWindow>>,
|
664
|
-
) -> Self {
|
665
|
-
let options = RollingOptions {
|
666
|
-
window_size: Duration::parse(&window_size),
|
667
|
-
weights,
|
668
|
-
min_periods,
|
669
|
-
center,
|
670
|
-
by,
|
671
|
-
closed_window: closed.map(|c| c.0),
|
672
|
-
};
|
673
|
-
|
674
|
-
self.inner.clone().rolling_std(options).into()
|
675
|
-
}
|
676
|
-
|
677
|
-
pub fn rolling_var(
|
678
|
-
&self,
|
679
|
-
window_size: String,
|
680
|
-
weights: Option<Vec<f64>>,
|
681
|
-
min_periods: usize,
|
682
|
-
center: bool,
|
683
|
-
by: Option<String>,
|
684
|
-
closed: Option<Wrap<ClosedWindow>>,
|
685
|
-
) -> Self {
|
686
|
-
let options = RollingOptions {
|
687
|
-
window_size: Duration::parse(&window_size),
|
688
|
-
weights,
|
689
|
-
min_periods,
|
690
|
-
center,
|
691
|
-
by,
|
692
|
-
closed_window: closed.map(|c| c.0),
|
693
|
-
};
|
694
|
-
|
695
|
-
self.inner.clone().rolling_var(options).into()
|
696
|
-
}
|
697
|
-
|
698
|
-
pub fn rolling_median(
|
699
|
-
&self,
|
700
|
-
window_size: String,
|
701
|
-
weights: Option<Vec<f64>>,
|
702
|
-
min_periods: usize,
|
703
|
-
center: bool,
|
704
|
-
by: Option<String>,
|
705
|
-
closed: Option<Wrap<ClosedWindow>>,
|
706
|
-
) -> Self {
|
707
|
-
let options = RollingOptions {
|
708
|
-
window_size: Duration::parse(&window_size),
|
709
|
-
weights,
|
710
|
-
min_periods,
|
711
|
-
center,
|
712
|
-
by,
|
713
|
-
closed_window: closed.map(|c| c.0),
|
714
|
-
};
|
715
|
-
self.inner.clone().rolling_median(options).into()
|
716
|
-
}
|
717
|
-
|
718
|
-
#[allow(clippy::too_many_arguments)]
|
719
|
-
pub fn rolling_quantile(
|
720
|
-
&self,
|
721
|
-
quantile: f64,
|
722
|
-
interpolation: Wrap<QuantileInterpolOptions>,
|
723
|
-
window_size: String,
|
724
|
-
weights: Option<Vec<f64>>,
|
725
|
-
min_periods: usize,
|
726
|
-
center: bool,
|
727
|
-
by: Option<String>,
|
728
|
-
closed: Option<Wrap<ClosedWindow>>,
|
729
|
-
) -> Self {
|
730
|
-
let options = RollingOptions {
|
731
|
-
window_size: Duration::parse(&window_size),
|
732
|
-
weights,
|
733
|
-
min_periods,
|
734
|
-
center,
|
735
|
-
by,
|
736
|
-
closed_window: closed.map(|c| c.0),
|
737
|
-
};
|
738
|
-
|
739
|
-
self.inner
|
740
|
-
.clone()
|
741
|
-
.rolling_quantile(quantile, interpolation.0, options)
|
742
|
-
.into()
|
743
|
-
}
|
744
|
-
|
745
|
-
pub fn rolling_skew(&self, window_size: usize, bias: bool) -> Self {
|
746
|
-
self.inner
|
747
|
-
.clone()
|
748
|
-
.rolling_apply_float(window_size, move |ca| {
|
749
|
-
ca.clone().into_series().skew(bias).unwrap()
|
750
|
-
})
|
751
|
-
.into()
|
752
|
-
}
|
753
|
-
|
754
557
|
pub fn lower_bound(&self) -> Self {
|
755
558
|
self.inner.clone().lower_bound().into()
|
756
559
|
}
|
@@ -778,8 +581,8 @@ impl RbExpr {
|
|
778
581
|
self.inner.clone().diff(n, null_behavior.0).into()
|
779
582
|
}
|
780
583
|
|
781
|
-
pub fn pct_change(&self, n:
|
782
|
-
self.inner.clone().pct_change(n).into()
|
584
|
+
pub fn pct_change(&self, n: &Self) -> Self {
|
585
|
+
self.inner.clone().pct_change(n.inner.clone()).into()
|
783
586
|
}
|
784
587
|
|
785
588
|
pub fn skew(&self, bias: bool) -> Self {
|
@@ -794,8 +597,8 @@ impl RbExpr {
|
|
794
597
|
self.inner.clone().reshape(&dims).into()
|
795
598
|
}
|
796
599
|
|
797
|
-
pub fn
|
798
|
-
self.inner.clone().
|
600
|
+
pub fn cum_count(&self, reverse: bool) -> Self {
|
601
|
+
self.inner.clone().cum_count(reverse).into()
|
799
602
|
}
|
800
603
|
|
801
604
|
pub fn to_physical(&self) -> Self {
|
@@ -815,27 +618,27 @@ impl RbExpr {
|
|
815
618
|
|
816
619
|
pub fn sample_n(
|
817
620
|
&self,
|
818
|
-
n:
|
621
|
+
n: &Self,
|
819
622
|
with_replacement: bool,
|
820
623
|
shuffle: bool,
|
821
624
|
seed: Option<u64>,
|
822
625
|
) -> Self {
|
823
626
|
self.inner
|
824
627
|
.clone()
|
825
|
-
.sample_n(n, with_replacement, shuffle, seed)
|
628
|
+
.sample_n(n.inner.clone(), with_replacement, shuffle, seed)
|
826
629
|
.into()
|
827
630
|
}
|
828
631
|
|
829
632
|
pub fn sample_frac(
|
830
633
|
&self,
|
831
|
-
frac:
|
634
|
+
frac: &Self,
|
832
635
|
with_replacement: bool,
|
833
636
|
shuffle: bool,
|
834
637
|
seed: Option<u64>,
|
835
638
|
) -> Self {
|
836
639
|
self.inner
|
837
640
|
.clone()
|
838
|
-
.sample_frac(frac, with_replacement, shuffle, seed)
|
641
|
+
.sample_frac(frac.inner.clone(), with_replacement, shuffle, seed)
|
839
642
|
.into()
|
840
643
|
}
|
841
644
|
|
@@ -894,11 +697,13 @@ impl RbExpr {
|
|
894
697
|
|
895
698
|
pub fn extend_constant(&self, value: Wrap<AnyValue>, n: usize) -> Self {
|
896
699
|
let value = value.into_value();
|
700
|
+
let value = Opaque::from(value);
|
897
701
|
self.inner
|
898
702
|
.clone()
|
899
703
|
.apply(
|
900
704
|
move |s| {
|
901
|
-
let value =
|
705
|
+
let value = Ruby::get().unwrap().get_inner(value);
|
706
|
+
let value = Wrap::<AnyValue>::try_convert(value).unwrap().0;
|
902
707
|
s.extend_constant(value, n).map(Some)
|
903
708
|
},
|
904
709
|
GetOutput::same_type(),
|
@@ -907,12 +712,12 @@ impl RbExpr {
|
|
907
712
|
.into()
|
908
713
|
}
|
909
714
|
|
910
|
-
pub fn any(&self) -> Self {
|
911
|
-
self.inner.clone().any().into()
|
715
|
+
pub fn any(&self, drop_nulls: bool) -> Self {
|
716
|
+
self.inner.clone().any(drop_nulls).into()
|
912
717
|
}
|
913
718
|
|
914
|
-
pub fn all(&self) -> Self {
|
915
|
-
self.inner.clone().all().into()
|
719
|
+
pub fn all(&self, drop_nulls: bool) -> Self {
|
720
|
+
self.inner.clone().all(drop_nulls).into()
|
916
721
|
}
|
917
722
|
|
918
723
|
pub fn log(&self, base: f64) -> Self {
|
@@ -930,4 +735,13 @@ impl RbExpr {
|
|
930
735
|
pub fn hash(&self, seed: u64, seed_1: u64, seed_2: u64, seed_3: u64) -> Self {
|
931
736
|
self.inner.clone().hash(seed, seed_1, seed_2, seed_3).into()
|
932
737
|
}
|
738
|
+
|
739
|
+
pub fn set_sorted_flag(&self, descending: bool) -> Self {
|
740
|
+
let is_sorted = if descending {
|
741
|
+
IsSorted::Descending
|
742
|
+
} else {
|
743
|
+
IsSorted::Ascending
|
744
|
+
};
|
745
|
+
self.inner.clone().set_sorted_flag(is_sorted).into()
|
746
|
+
}
|
933
747
|
}
|
data/ext/polars/src/expr/list.rs
CHANGED
@@ -8,71 +8,84 @@ use crate::{RbExpr, RbResult};
|
|
8
8
|
|
9
9
|
impl RbExpr {
|
10
10
|
pub fn list_arg_max(&self) -> Self {
|
11
|
-
self.inner.clone().
|
11
|
+
self.inner.clone().list().arg_max().into()
|
12
12
|
}
|
13
13
|
|
14
14
|
pub fn list_arg_min(&self) -> Self {
|
15
|
-
self.inner.clone().
|
15
|
+
self.inner.clone().list().arg_min().into()
|
16
16
|
}
|
17
17
|
|
18
18
|
pub fn list_contains(&self, other: &RbExpr) -> Self {
|
19
19
|
self.inner
|
20
20
|
.clone()
|
21
|
-
.
|
21
|
+
.list()
|
22
22
|
.contains(other.inner.clone())
|
23
23
|
.into()
|
24
24
|
}
|
25
25
|
|
26
|
-
pub fn
|
26
|
+
pub fn list_count_matches(&self, expr: &RbExpr) -> Self {
|
27
27
|
self.inner
|
28
28
|
.clone()
|
29
|
-
.
|
30
|
-
.
|
29
|
+
.list()
|
30
|
+
.count_matches(expr.inner.clone())
|
31
31
|
.into()
|
32
32
|
}
|
33
33
|
|
34
34
|
pub fn list_diff(&self, n: i64, null_behavior: Wrap<NullBehavior>) -> RbResult<Self> {
|
35
|
-
Ok(self.inner.clone().
|
35
|
+
Ok(self.inner.clone().list().diff(n, null_behavior.0).into())
|
36
36
|
}
|
37
37
|
|
38
38
|
pub fn list_eval(&self, expr: &RbExpr, parallel: bool) -> Self {
|
39
39
|
self.inner
|
40
40
|
.clone()
|
41
|
-
.
|
41
|
+
.list()
|
42
42
|
.eval(expr.inner.clone(), parallel)
|
43
43
|
.into()
|
44
44
|
}
|
45
45
|
|
46
46
|
pub fn list_get(&self, index: &RbExpr) -> Self {
|
47
|
-
self.inner.clone().
|
47
|
+
self.inner.clone().list().get(index.inner.clone()).into()
|
48
48
|
}
|
49
49
|
|
50
|
-
pub fn list_join(&self, separator:
|
51
|
-
self.inner
|
50
|
+
pub fn list_join(&self, separator: &RbExpr) -> Self {
|
51
|
+
self.inner
|
52
|
+
.clone()
|
53
|
+
.list()
|
54
|
+
.join(separator.inner.clone())
|
55
|
+
.into()
|
52
56
|
}
|
53
57
|
|
54
|
-
pub fn
|
55
|
-
self.inner.clone().
|
58
|
+
pub fn list_len(&self) -> Self {
|
59
|
+
self.inner.clone().list().len().into()
|
56
60
|
}
|
57
61
|
|
58
62
|
pub fn list_max(&self) -> Self {
|
59
|
-
self.inner.clone().
|
63
|
+
self.inner.clone().list().max().into()
|
60
64
|
}
|
61
65
|
|
62
66
|
pub fn list_mean(&self) -> Self {
|
63
|
-
self.inner
|
67
|
+
self.inner
|
68
|
+
.clone()
|
69
|
+
.list()
|
70
|
+
.mean()
|
71
|
+
.with_fmt("list.mean")
|
72
|
+
.into()
|
64
73
|
}
|
65
74
|
|
66
75
|
pub fn list_min(&self) -> Self {
|
67
|
-
self.inner.clone().
|
76
|
+
self.inner.clone().list().min().into()
|
68
77
|
}
|
69
78
|
|
70
79
|
pub fn list_reverse(&self) -> Self {
|
71
|
-
self.inner.clone().
|
80
|
+
self.inner.clone().list().reverse().into()
|
72
81
|
}
|
73
82
|
|
74
|
-
pub fn list_shift(&self, periods:
|
75
|
-
self.inner
|
83
|
+
pub fn list_shift(&self, periods: &RbExpr) -> Self {
|
84
|
+
self.inner
|
85
|
+
.clone()
|
86
|
+
.list()
|
87
|
+
.shift(periods.inner.clone())
|
88
|
+
.into()
|
76
89
|
}
|
77
90
|
|
78
91
|
pub fn list_slice(&self, offset: &RbExpr, length: Option<&RbExpr>) -> Self {
|
@@ -82,7 +95,7 @@ impl RbExpr {
|
|
82
95
|
};
|
83
96
|
self.inner
|
84
97
|
.clone()
|
85
|
-
.
|
98
|
+
.list()
|
86
99
|
.slice(offset.inner.clone(), length)
|
87
100
|
.into()
|
88
101
|
}
|
@@ -90,23 +103,23 @@ impl RbExpr {
|
|
90
103
|
pub fn list_sort(&self, reverse: bool) -> Self {
|
91
104
|
self.inner
|
92
105
|
.clone()
|
93
|
-
.
|
106
|
+
.list()
|
94
107
|
.sort(SortOptions {
|
95
108
|
descending: reverse,
|
96
109
|
..Default::default()
|
97
110
|
})
|
98
|
-
.with_fmt("
|
111
|
+
.with_fmt("list.sort")
|
99
112
|
.into()
|
100
113
|
}
|
101
114
|
|
102
115
|
pub fn list_sum(&self) -> Self {
|
103
|
-
self.inner.clone().
|
116
|
+
self.inner.clone().list().sum().with_fmt("list.sum").into()
|
104
117
|
}
|
105
118
|
|
106
119
|
pub fn list_take(&self, index: &RbExpr, null_on_oob: bool) -> Self {
|
107
120
|
self.inner
|
108
121
|
.clone()
|
109
|
-
.
|
122
|
+
.list()
|
110
123
|
.take(index.inner.clone(), null_on_oob)
|
111
124
|
.into()
|
112
125
|
}
|
@@ -122,14 +135,14 @@ impl RbExpr {
|
|
122
135
|
// let name_gen = name_gen.map(|lambda| {
|
123
136
|
// Arc::new(move |idx: usize| {
|
124
137
|
// let out: Value = lambda.funcall("call", (idx,)).unwrap();
|
125
|
-
//
|
138
|
+
// String::try_convert(out).unwrap()
|
126
139
|
// }) as NameGenerator
|
127
140
|
// });
|
128
141
|
|
129
142
|
Ok(self
|
130
143
|
.inner
|
131
144
|
.clone()
|
132
|
-
.
|
145
|
+
.list()
|
133
146
|
.to_struct(width_strat.0, name_gen, upper_bound)
|
134
147
|
.into())
|
135
148
|
}
|
@@ -138,9 +151,9 @@ impl RbExpr {
|
|
138
151
|
let e = self.inner.clone();
|
139
152
|
|
140
153
|
if maintain_order {
|
141
|
-
e.
|
154
|
+
e.list().unique_stable().into()
|
142
155
|
} else {
|
143
|
-
e.
|
156
|
+
e.list().unique().into()
|
144
157
|
}
|
145
158
|
}
|
146
159
|
}
|
@@ -1,13 +1,16 @@
|
|
1
|
+
mod array;
|
1
2
|
mod binary;
|
2
3
|
mod categorical;
|
3
4
|
mod datetime;
|
4
5
|
mod general;
|
5
6
|
mod list;
|
6
7
|
mod meta;
|
8
|
+
mod name;
|
9
|
+
mod rolling;
|
7
10
|
mod string;
|
8
11
|
mod r#struct;
|
9
12
|
|
10
|
-
use magnus::RArray;
|
13
|
+
use magnus::{prelude::*, RArray};
|
11
14
|
use polars::lazy::dsl::Expr;
|
12
15
|
|
13
16
|
use crate::RbResult;
|
@@ -27,7 +30,7 @@ impl From<Expr> for RbExpr {
|
|
27
30
|
pub fn rb_exprs_to_exprs(rb_exprs: RArray) -> RbResult<Vec<Expr>> {
|
28
31
|
let mut exprs = Vec::new();
|
29
32
|
for item in rb_exprs.each() {
|
30
|
-
exprs.push(
|
33
|
+
exprs.push(<&RbExpr>::try_convert(item?)?.inner.clone());
|
31
34
|
}
|
32
35
|
Ok(exprs)
|
33
36
|
}
|