polars-df 0.4.0 → 0.5.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 +12 -0
- data/Cargo.lock +272 -191
- data/Cargo.toml +0 -1
- data/README.md +2 -2
- data/ext/polars/Cargo.toml +8 -4
- data/ext/polars/src/apply/dataframe.rs +2 -2
- data/ext/polars/src/{lazy/apply.rs → apply/lazy.rs} +1 -2
- data/ext/polars/src/apply/mod.rs +1 -0
- data/ext/polars/src/batched_csv.rs +7 -5
- data/ext/polars/src/conversion.rs +106 -4
- data/ext/polars/src/dataframe.rs +19 -17
- data/ext/polars/src/error.rs +0 -4
- data/ext/polars/src/expr/binary.rs +69 -0
- data/ext/polars/src/expr/categorical.rs +10 -0
- data/ext/polars/src/expr/datetime.rs +223 -0
- data/ext/polars/src/expr/general.rs +933 -0
- data/ext/polars/src/expr/list.rs +146 -0
- data/ext/polars/src/{lazy → expr}/meta.rs +16 -6
- data/ext/polars/src/expr/string.rs +313 -0
- data/ext/polars/src/expr/struct.rs +15 -0
- data/ext/polars/src/expr.rs +33 -0
- data/ext/polars/src/functions/eager.rs +93 -0
- data/ext/polars/src/functions/io.rs +34 -0
- data/ext/polars/src/functions/lazy.rs +209 -0
- data/ext/polars/src/functions/meta.rs +8 -0
- data/ext/polars/src/functions/mod.rs +5 -0
- data/ext/polars/src/functions/whenthen.rs +43 -0
- data/ext/polars/src/{lazy/dataframe.rs → lazyframe.rs} +12 -33
- data/ext/polars/src/lazygroupby.rs +29 -0
- data/ext/polars/src/lib.rs +205 -303
- data/ext/polars/src/rb_modules.rs +8 -0
- data/ext/polars/src/series/aggregation.rs +83 -0
- data/ext/polars/src/series/arithmetic.rs +88 -0
- data/ext/polars/src/series/comparison.rs +251 -0
- data/ext/polars/src/series/construction.rs +164 -0
- data/ext/polars/src/series.rs +99 -539
- data/lib/polars/convert.rb +2 -2
- data/lib/polars/data_frame.rb +201 -50
- data/lib/polars/data_types.rb +6 -4
- data/lib/polars/date_time_expr.rb +142 -2
- data/lib/polars/expr.rb +70 -10
- data/lib/polars/lazy_frame.rb +4 -3
- data/lib/polars/lazy_functions.rb +4 -1
- data/lib/polars/list_expr.rb +68 -19
- data/lib/polars/series.rb +181 -73
- data/lib/polars/string_expr.rb +149 -43
- data/lib/polars/string_name_space.rb +4 -4
- data/lib/polars/struct_name_space.rb +32 -0
- data/lib/polars/utils.rb +41 -7
- data/lib/polars/version.rb +1 -1
- data/lib/polars.rb +2 -2
- metadata +26 -11
- data/ext/polars/src/lazy/dsl.rs +0 -1775
- data/ext/polars/src/lazy/mod.rs +0 -5
- data/ext/polars/src/lazy/utils.rs +0 -13
- data/ext/polars/src/list_construction.rs +0 -100
- /data/ext/polars/src/{numo.rs → series/export.rs} +0 -0
- /data/ext/polars/src/{set.rs → series/set_at_idx.rs} +0 -0
@@ -0,0 +1,933 @@
|
|
1
|
+
use magnus::{block::Proc, IntoValue, RArray, Value};
|
2
|
+
use polars::lazy::dsl;
|
3
|
+
use polars::prelude::*;
|
4
|
+
use polars::series::ops::NullBehavior;
|
5
|
+
|
6
|
+
use crate::apply::lazy::map_single;
|
7
|
+
use crate::conversion::{parse_fill_null_strategy, Wrap};
|
8
|
+
use crate::rb_exprs_to_exprs;
|
9
|
+
use crate::utils::reinterpret;
|
10
|
+
use crate::{RbExpr, RbResult};
|
11
|
+
|
12
|
+
impl RbExpr {
|
13
|
+
pub fn add(&self, rhs: &RbExpr) -> RbResult<Self> {
|
14
|
+
Ok(dsl::binary_expr(self.inner.clone(), Operator::Plus, rhs.inner.clone()).into())
|
15
|
+
}
|
16
|
+
|
17
|
+
pub fn sub(&self, rhs: &RbExpr) -> RbResult<Self> {
|
18
|
+
Ok(dsl::binary_expr(self.inner.clone(), Operator::Minus, rhs.inner.clone()).into())
|
19
|
+
}
|
20
|
+
|
21
|
+
pub fn mul(&self, rhs: &RbExpr) -> RbResult<Self> {
|
22
|
+
Ok(dsl::binary_expr(self.inner.clone(), Operator::Multiply, rhs.inner.clone()).into())
|
23
|
+
}
|
24
|
+
|
25
|
+
pub fn truediv(&self, rhs: &RbExpr) -> RbResult<Self> {
|
26
|
+
Ok(dsl::binary_expr(self.inner.clone(), Operator::TrueDivide, rhs.inner.clone()).into())
|
27
|
+
}
|
28
|
+
|
29
|
+
pub fn _mod(&self, rhs: &RbExpr) -> RbResult<Self> {
|
30
|
+
Ok(dsl::binary_expr(self.inner.clone(), Operator::Modulus, rhs.inner.clone()).into())
|
31
|
+
}
|
32
|
+
|
33
|
+
pub fn floordiv(&self, rhs: &RbExpr) -> RbResult<Self> {
|
34
|
+
Ok(dsl::binary_expr(self.inner.clone(), Operator::FloorDivide, rhs.inner.clone()).into())
|
35
|
+
}
|
36
|
+
|
37
|
+
pub fn to_str(&self) -> String {
|
38
|
+
format!("{:?}", self.inner)
|
39
|
+
}
|
40
|
+
|
41
|
+
pub fn eq(&self, other: &RbExpr) -> Self {
|
42
|
+
self.clone().inner.eq(other.inner.clone()).into()
|
43
|
+
}
|
44
|
+
|
45
|
+
pub fn neq(&self, other: &RbExpr) -> Self {
|
46
|
+
self.clone().inner.neq(other.inner.clone()).into()
|
47
|
+
}
|
48
|
+
|
49
|
+
pub fn gt(&self, other: &RbExpr) -> Self {
|
50
|
+
self.clone().inner.gt(other.inner.clone()).into()
|
51
|
+
}
|
52
|
+
|
53
|
+
pub fn gt_eq(&self, other: &RbExpr) -> Self {
|
54
|
+
self.clone().inner.gt_eq(other.inner.clone()).into()
|
55
|
+
}
|
56
|
+
|
57
|
+
pub fn lt_eq(&self, other: &RbExpr) -> Self {
|
58
|
+
self.clone().inner.lt_eq(other.inner.clone()).into()
|
59
|
+
}
|
60
|
+
|
61
|
+
pub fn lt(&self, other: &RbExpr) -> Self {
|
62
|
+
self.clone().inner.lt(other.inner.clone()).into()
|
63
|
+
}
|
64
|
+
|
65
|
+
pub fn alias(&self, name: String) -> Self {
|
66
|
+
self.clone().inner.alias(&name).into()
|
67
|
+
}
|
68
|
+
|
69
|
+
pub fn is_not(&self) -> Self {
|
70
|
+
self.clone().inner.not().into()
|
71
|
+
}
|
72
|
+
|
73
|
+
pub fn is_null(&self) -> Self {
|
74
|
+
self.clone().inner.is_null().into()
|
75
|
+
}
|
76
|
+
|
77
|
+
pub fn is_not_null(&self) -> Self {
|
78
|
+
self.clone().inner.is_not_null().into()
|
79
|
+
}
|
80
|
+
|
81
|
+
pub fn is_infinite(&self) -> Self {
|
82
|
+
self.clone().inner.is_infinite().into()
|
83
|
+
}
|
84
|
+
|
85
|
+
pub fn is_finite(&self) -> Self {
|
86
|
+
self.clone().inner.is_finite().into()
|
87
|
+
}
|
88
|
+
|
89
|
+
pub fn is_nan(&self) -> Self {
|
90
|
+
self.clone().inner.is_nan().into()
|
91
|
+
}
|
92
|
+
|
93
|
+
pub fn is_not_nan(&self) -> Self {
|
94
|
+
self.clone().inner.is_not_nan().into()
|
95
|
+
}
|
96
|
+
|
97
|
+
pub fn min(&self) -> Self {
|
98
|
+
self.clone().inner.min().into()
|
99
|
+
}
|
100
|
+
|
101
|
+
pub fn max(&self) -> Self {
|
102
|
+
self.clone().inner.max().into()
|
103
|
+
}
|
104
|
+
|
105
|
+
pub fn nan_max(&self) -> Self {
|
106
|
+
self.clone().inner.nan_max().into()
|
107
|
+
}
|
108
|
+
|
109
|
+
pub fn nan_min(&self) -> Self {
|
110
|
+
self.clone().inner.nan_min().into()
|
111
|
+
}
|
112
|
+
|
113
|
+
pub fn mean(&self) -> Self {
|
114
|
+
self.clone().inner.mean().into()
|
115
|
+
}
|
116
|
+
|
117
|
+
pub fn median(&self) -> Self {
|
118
|
+
self.clone().inner.median().into()
|
119
|
+
}
|
120
|
+
|
121
|
+
pub fn sum(&self) -> Self {
|
122
|
+
self.clone().inner.sum().into()
|
123
|
+
}
|
124
|
+
|
125
|
+
pub fn n_unique(&self) -> Self {
|
126
|
+
self.clone().inner.n_unique().into()
|
127
|
+
}
|
128
|
+
|
129
|
+
pub fn arg_unique(&self) -> Self {
|
130
|
+
self.clone().inner.arg_unique().into()
|
131
|
+
}
|
132
|
+
|
133
|
+
pub fn unique(&self) -> Self {
|
134
|
+
self.clone().inner.unique().into()
|
135
|
+
}
|
136
|
+
|
137
|
+
pub fn unique_stable(&self) -> Self {
|
138
|
+
self.clone().inner.unique_stable().into()
|
139
|
+
}
|
140
|
+
|
141
|
+
pub fn first(&self) -> Self {
|
142
|
+
self.clone().inner.first().into()
|
143
|
+
}
|
144
|
+
|
145
|
+
pub fn last(&self) -> Self {
|
146
|
+
self.clone().inner.last().into()
|
147
|
+
}
|
148
|
+
|
149
|
+
pub fn implode(&self) -> Self {
|
150
|
+
self.clone().inner.implode().into()
|
151
|
+
}
|
152
|
+
|
153
|
+
pub fn quantile(
|
154
|
+
&self,
|
155
|
+
quantile: &RbExpr,
|
156
|
+
interpolation: Wrap<QuantileInterpolOptions>,
|
157
|
+
) -> Self {
|
158
|
+
self.clone()
|
159
|
+
.inner
|
160
|
+
.quantile(quantile.inner.clone(), interpolation.0)
|
161
|
+
.into()
|
162
|
+
}
|
163
|
+
|
164
|
+
pub fn agg_groups(&self) -> Self {
|
165
|
+
self.clone().inner.agg_groups().into()
|
166
|
+
}
|
167
|
+
|
168
|
+
pub fn count(&self) -> Self {
|
169
|
+
self.clone().inner.count().into()
|
170
|
+
}
|
171
|
+
|
172
|
+
pub fn value_counts(&self, multithreaded: bool, sorted: bool) -> Self {
|
173
|
+
self.inner
|
174
|
+
.clone()
|
175
|
+
.value_counts(multithreaded, sorted)
|
176
|
+
.into()
|
177
|
+
}
|
178
|
+
|
179
|
+
pub fn unique_counts(&self) -> Self {
|
180
|
+
self.inner.clone().unique_counts().into()
|
181
|
+
}
|
182
|
+
|
183
|
+
pub fn null_count(&self) -> Self {
|
184
|
+
self.inner.clone().null_count().into()
|
185
|
+
}
|
186
|
+
|
187
|
+
pub fn cast(&self, data_type: Wrap<DataType>, strict: bool) -> RbResult<Self> {
|
188
|
+
let dt = data_type.0;
|
189
|
+
let expr = if strict {
|
190
|
+
self.inner.clone().strict_cast(dt)
|
191
|
+
} else {
|
192
|
+
self.inner.clone().cast(dt)
|
193
|
+
};
|
194
|
+
Ok(expr.into())
|
195
|
+
}
|
196
|
+
|
197
|
+
pub fn sort_with(&self, descending: bool, nulls_last: bool) -> Self {
|
198
|
+
self.clone()
|
199
|
+
.inner
|
200
|
+
.sort_with(SortOptions {
|
201
|
+
descending,
|
202
|
+
nulls_last,
|
203
|
+
multithreaded: true,
|
204
|
+
})
|
205
|
+
.into()
|
206
|
+
}
|
207
|
+
|
208
|
+
pub fn arg_sort(&self, reverse: bool, nulls_last: bool) -> Self {
|
209
|
+
self.clone()
|
210
|
+
.inner
|
211
|
+
.arg_sort(SortOptions {
|
212
|
+
descending: reverse,
|
213
|
+
nulls_last,
|
214
|
+
multithreaded: true,
|
215
|
+
})
|
216
|
+
.into()
|
217
|
+
}
|
218
|
+
|
219
|
+
pub fn top_k(&self, k: usize) -> Self {
|
220
|
+
self.inner.clone().top_k(k).into()
|
221
|
+
}
|
222
|
+
|
223
|
+
pub fn bottom_k(&self, k: usize) -> Self {
|
224
|
+
self.inner.clone().bottom_k(k).into()
|
225
|
+
}
|
226
|
+
|
227
|
+
pub fn arg_max(&self) -> Self {
|
228
|
+
self.clone().inner.arg_max().into()
|
229
|
+
}
|
230
|
+
|
231
|
+
pub fn arg_min(&self) -> Self {
|
232
|
+
self.clone().inner.arg_min().into()
|
233
|
+
}
|
234
|
+
|
235
|
+
pub fn search_sorted(&self, element: &RbExpr, side: Wrap<SearchSortedSide>) -> Self {
|
236
|
+
self.inner
|
237
|
+
.clone()
|
238
|
+
.search_sorted(element.inner.clone(), side.0)
|
239
|
+
.into()
|
240
|
+
}
|
241
|
+
|
242
|
+
pub fn take(&self, idx: &RbExpr) -> Self {
|
243
|
+
self.clone().inner.take(idx.inner.clone()).into()
|
244
|
+
}
|
245
|
+
|
246
|
+
pub fn sort_by(&self, by: RArray, reverse: Vec<bool>) -> RbResult<Self> {
|
247
|
+
let by = rb_exprs_to_exprs(by)?;
|
248
|
+
Ok(self.clone().inner.sort_by(by, reverse).into())
|
249
|
+
}
|
250
|
+
|
251
|
+
pub fn backward_fill(&self, limit: FillNullLimit) -> Self {
|
252
|
+
self.clone().inner.backward_fill(limit).into()
|
253
|
+
}
|
254
|
+
|
255
|
+
pub fn forward_fill(&self, limit: FillNullLimit) -> Self {
|
256
|
+
self.clone().inner.forward_fill(limit).into()
|
257
|
+
}
|
258
|
+
|
259
|
+
pub fn shift(&self, periods: i64) -> Self {
|
260
|
+
self.clone().inner.shift(periods).into()
|
261
|
+
}
|
262
|
+
pub fn shift_and_fill(&self, periods: i64, fill_value: &RbExpr) -> Self {
|
263
|
+
self.clone()
|
264
|
+
.inner
|
265
|
+
.shift_and_fill(periods, fill_value.inner.clone())
|
266
|
+
.into()
|
267
|
+
}
|
268
|
+
|
269
|
+
pub fn fill_null(&self, expr: &RbExpr) -> Self {
|
270
|
+
self.clone().inner.fill_null(expr.inner.clone()).into()
|
271
|
+
}
|
272
|
+
|
273
|
+
pub fn fill_null_with_strategy(
|
274
|
+
&self,
|
275
|
+
strategy: String,
|
276
|
+
limit: FillNullLimit,
|
277
|
+
) -> RbResult<Self> {
|
278
|
+
let strat = parse_fill_null_strategy(&strategy, limit)?;
|
279
|
+
Ok(self
|
280
|
+
.inner
|
281
|
+
.clone()
|
282
|
+
.apply(
|
283
|
+
move |s| s.fill_null(strat).map(Some),
|
284
|
+
GetOutput::same_type(),
|
285
|
+
)
|
286
|
+
.with_fmt("fill_null_with_strategy")
|
287
|
+
.into())
|
288
|
+
}
|
289
|
+
|
290
|
+
pub fn fill_nan(&self, expr: &RbExpr) -> Self {
|
291
|
+
self.inner.clone().fill_nan(expr.inner.clone()).into()
|
292
|
+
}
|
293
|
+
|
294
|
+
pub fn drop_nulls(&self) -> Self {
|
295
|
+
self.inner.clone().drop_nulls().into()
|
296
|
+
}
|
297
|
+
|
298
|
+
pub fn drop_nans(&self) -> Self {
|
299
|
+
self.inner.clone().drop_nans().into()
|
300
|
+
}
|
301
|
+
|
302
|
+
pub fn filter(&self, predicate: &RbExpr) -> Self {
|
303
|
+
self.clone().inner.filter(predicate.inner.clone()).into()
|
304
|
+
}
|
305
|
+
|
306
|
+
pub fn reverse(&self) -> Self {
|
307
|
+
self.clone().inner.reverse().into()
|
308
|
+
}
|
309
|
+
|
310
|
+
pub fn std(&self, ddof: u8) -> Self {
|
311
|
+
self.clone().inner.std(ddof).into()
|
312
|
+
}
|
313
|
+
|
314
|
+
pub fn var(&self, ddof: u8) -> Self {
|
315
|
+
self.clone().inner.var(ddof).into()
|
316
|
+
}
|
317
|
+
|
318
|
+
pub fn is_unique(&self) -> Self {
|
319
|
+
self.clone().inner.is_unique().into()
|
320
|
+
}
|
321
|
+
|
322
|
+
pub fn approx_unique(&self) -> Self {
|
323
|
+
self.clone().inner.approx_unique().into()
|
324
|
+
}
|
325
|
+
|
326
|
+
pub fn is_first(&self) -> Self {
|
327
|
+
self.clone().inner.is_first().into()
|
328
|
+
}
|
329
|
+
|
330
|
+
pub fn explode(&self) -> Self {
|
331
|
+
self.clone().inner.explode().into()
|
332
|
+
}
|
333
|
+
|
334
|
+
pub fn take_every(&self, n: usize) -> Self {
|
335
|
+
self.clone()
|
336
|
+
.inner
|
337
|
+
.map(
|
338
|
+
move |s: Series| Ok(Some(s.take_every(n))),
|
339
|
+
GetOutput::same_type(),
|
340
|
+
)
|
341
|
+
.with_fmt("take_every")
|
342
|
+
.into()
|
343
|
+
}
|
344
|
+
|
345
|
+
pub fn tail(&self, n: Option<usize>) -> Self {
|
346
|
+
self.clone().inner.tail(n).into()
|
347
|
+
}
|
348
|
+
|
349
|
+
pub fn head(&self, n: Option<usize>) -> Self {
|
350
|
+
self.clone().inner.head(n).into()
|
351
|
+
}
|
352
|
+
|
353
|
+
pub fn slice(&self, offset: &RbExpr, length: &RbExpr) -> Self {
|
354
|
+
self.inner
|
355
|
+
.clone()
|
356
|
+
.slice(offset.inner.clone(), length.inner.clone())
|
357
|
+
.into()
|
358
|
+
}
|
359
|
+
|
360
|
+
pub fn append(&self, other: &RbExpr, upcast: bool) -> Self {
|
361
|
+
self.inner
|
362
|
+
.clone()
|
363
|
+
.append(other.inner.clone(), upcast)
|
364
|
+
.into()
|
365
|
+
}
|
366
|
+
|
367
|
+
pub fn rechunk(&self) -> Self {
|
368
|
+
self.inner
|
369
|
+
.clone()
|
370
|
+
.map(|s| Ok(Some(s.rechunk())), GetOutput::same_type())
|
371
|
+
.into()
|
372
|
+
}
|
373
|
+
|
374
|
+
pub fn round(&self, decimals: u32) -> Self {
|
375
|
+
self.clone().inner.round(decimals).into()
|
376
|
+
}
|
377
|
+
|
378
|
+
pub fn floor(&self) -> Self {
|
379
|
+
self.clone().inner.floor().into()
|
380
|
+
}
|
381
|
+
|
382
|
+
pub fn ceil(&self) -> Self {
|
383
|
+
self.clone().inner.ceil().into()
|
384
|
+
}
|
385
|
+
|
386
|
+
pub fn clip(&self, min: Value, max: Value) -> Self {
|
387
|
+
let min = min.try_convert::<Wrap<AnyValue>>().unwrap().0;
|
388
|
+
let max = max.try_convert::<Wrap<AnyValue>>().unwrap().0;
|
389
|
+
self.clone().inner.clip(min, max).into()
|
390
|
+
}
|
391
|
+
|
392
|
+
pub fn clip_min(&self, min: Value) -> Self {
|
393
|
+
let min = min.try_convert::<Wrap<AnyValue>>().unwrap().0;
|
394
|
+
self.clone().inner.clip_min(min).into()
|
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
|
+
}
|
401
|
+
|
402
|
+
pub fn abs(&self) -> Self {
|
403
|
+
self.clone().inner.abs().into()
|
404
|
+
}
|
405
|
+
|
406
|
+
pub fn sin(&self) -> Self {
|
407
|
+
self.clone().inner.sin().into()
|
408
|
+
}
|
409
|
+
|
410
|
+
pub fn cos(&self) -> Self {
|
411
|
+
self.clone().inner.cos().into()
|
412
|
+
}
|
413
|
+
|
414
|
+
pub fn tan(&self) -> Self {
|
415
|
+
self.clone().inner.tan().into()
|
416
|
+
}
|
417
|
+
|
418
|
+
pub fn arcsin(&self) -> Self {
|
419
|
+
self.clone().inner.arcsin().into()
|
420
|
+
}
|
421
|
+
|
422
|
+
pub fn arccos(&self) -> Self {
|
423
|
+
self.clone().inner.arccos().into()
|
424
|
+
}
|
425
|
+
|
426
|
+
pub fn arctan(&self) -> Self {
|
427
|
+
self.clone().inner.arctan().into()
|
428
|
+
}
|
429
|
+
|
430
|
+
pub fn sinh(&self) -> Self {
|
431
|
+
self.clone().inner.sinh().into()
|
432
|
+
}
|
433
|
+
|
434
|
+
pub fn cosh(&self) -> Self {
|
435
|
+
self.clone().inner.cosh().into()
|
436
|
+
}
|
437
|
+
|
438
|
+
pub fn tanh(&self) -> Self {
|
439
|
+
self.clone().inner.tanh().into()
|
440
|
+
}
|
441
|
+
|
442
|
+
pub fn arcsinh(&self) -> Self {
|
443
|
+
self.clone().inner.arcsinh().into()
|
444
|
+
}
|
445
|
+
|
446
|
+
pub fn arccosh(&self) -> Self {
|
447
|
+
self.clone().inner.arccosh().into()
|
448
|
+
}
|
449
|
+
|
450
|
+
pub fn arctanh(&self) -> Self {
|
451
|
+
self.clone().inner.arctanh().into()
|
452
|
+
}
|
453
|
+
|
454
|
+
pub fn sign(&self) -> Self {
|
455
|
+
self.clone().inner.sign().into()
|
456
|
+
}
|
457
|
+
|
458
|
+
pub fn is_duplicated(&self) -> Self {
|
459
|
+
self.clone().inner.is_duplicated().into()
|
460
|
+
}
|
461
|
+
|
462
|
+
pub fn over(&self, partition_by: RArray) -> RbResult<Self> {
|
463
|
+
let partition_by = rb_exprs_to_exprs(partition_by)?;
|
464
|
+
Ok(self.clone().inner.over(partition_by).into())
|
465
|
+
}
|
466
|
+
|
467
|
+
pub fn _and(&self, expr: &RbExpr) -> Self {
|
468
|
+
self.clone().inner.and(expr.inner.clone()).into()
|
469
|
+
}
|
470
|
+
|
471
|
+
pub fn _xor(&self, expr: &RbExpr) -> Self {
|
472
|
+
self.clone().inner.xor(expr.inner.clone()).into()
|
473
|
+
}
|
474
|
+
|
475
|
+
pub fn _or(&self, expr: &RbExpr) -> Self {
|
476
|
+
self.clone().inner.or(expr.inner.clone()).into()
|
477
|
+
}
|
478
|
+
|
479
|
+
pub fn is_in(&self, expr: &RbExpr) -> Self {
|
480
|
+
self.clone().inner.is_in(expr.inner.clone()).into()
|
481
|
+
}
|
482
|
+
|
483
|
+
pub fn repeat_by(&self, by: &RbExpr) -> Self {
|
484
|
+
self.clone().inner.repeat_by(by.inner.clone()).into()
|
485
|
+
}
|
486
|
+
|
487
|
+
pub fn pow(&self, exponent: &RbExpr) -> Self {
|
488
|
+
self.clone().inner.pow(exponent.inner.clone()).into()
|
489
|
+
}
|
490
|
+
|
491
|
+
pub fn cumsum(&self, reverse: bool) -> Self {
|
492
|
+
self.clone().inner.cumsum(reverse).into()
|
493
|
+
}
|
494
|
+
|
495
|
+
pub fn cummax(&self, reverse: bool) -> Self {
|
496
|
+
self.clone().inner.cummax(reverse).into()
|
497
|
+
}
|
498
|
+
|
499
|
+
pub fn cummin(&self, reverse: bool) -> Self {
|
500
|
+
self.clone().inner.cummin(reverse).into()
|
501
|
+
}
|
502
|
+
|
503
|
+
pub fn cumprod(&self, reverse: bool) -> Self {
|
504
|
+
self.clone().inner.cumprod(reverse).into()
|
505
|
+
}
|
506
|
+
|
507
|
+
pub fn product(&self) -> Self {
|
508
|
+
self.clone().inner.product().into()
|
509
|
+
}
|
510
|
+
|
511
|
+
pub fn shrink_dtype(&self) -> Self {
|
512
|
+
self.inner.clone().shrink_dtype().into()
|
513
|
+
}
|
514
|
+
|
515
|
+
pub fn map(&self, lambda: Value, output_type: Option<Wrap<DataType>>, agg_list: bool) -> Self {
|
516
|
+
map_single(self, lambda, output_type, agg_list)
|
517
|
+
}
|
518
|
+
|
519
|
+
pub fn dot(&self, other: &RbExpr) -> Self {
|
520
|
+
self.inner.clone().dot(other.inner.clone()).into()
|
521
|
+
}
|
522
|
+
|
523
|
+
pub fn reinterpret(&self, signed: bool) -> Self {
|
524
|
+
let function = move |s: Series| reinterpret(&s, signed).map(Some);
|
525
|
+
let dt = if signed {
|
526
|
+
DataType::Int64
|
527
|
+
} else {
|
528
|
+
DataType::UInt64
|
529
|
+
};
|
530
|
+
self.clone()
|
531
|
+
.inner
|
532
|
+
.map(function, GetOutput::from_type(dt))
|
533
|
+
.into()
|
534
|
+
}
|
535
|
+
|
536
|
+
pub fn mode(&self) -> Self {
|
537
|
+
self.inner.clone().mode().into()
|
538
|
+
}
|
539
|
+
|
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
|
+
pub fn exclude(&self, columns: Vec<String>) -> Self {
|
568
|
+
self.inner.clone().exclude(columns).into()
|
569
|
+
}
|
570
|
+
|
571
|
+
pub fn interpolate(&self, method: Wrap<InterpolationMethod>) -> Self {
|
572
|
+
self.inner.clone().interpolate(method.0).into()
|
573
|
+
}
|
574
|
+
|
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
|
+
pub fn lower_bound(&self) -> Self {
|
755
|
+
self.inner.clone().lower_bound().into()
|
756
|
+
}
|
757
|
+
|
758
|
+
pub fn upper_bound(&self) -> Self {
|
759
|
+
self.inner.clone().upper_bound().into()
|
760
|
+
}
|
761
|
+
|
762
|
+
pub fn cumulative_eval(&self, expr: &RbExpr, min_periods: usize, parallel: bool) -> Self {
|
763
|
+
self.inner
|
764
|
+
.clone()
|
765
|
+
.cumulative_eval(expr.inner.clone(), min_periods, parallel)
|
766
|
+
.into()
|
767
|
+
}
|
768
|
+
|
769
|
+
pub fn rank(&self, method: Wrap<RankMethod>, reverse: bool, seed: Option<u64>) -> Self {
|
770
|
+
let options = RankOptions {
|
771
|
+
method: method.0,
|
772
|
+
descending: reverse,
|
773
|
+
};
|
774
|
+
self.inner.clone().rank(options, seed).into()
|
775
|
+
}
|
776
|
+
|
777
|
+
pub fn diff(&self, n: i64, null_behavior: Wrap<NullBehavior>) -> Self {
|
778
|
+
self.inner.clone().diff(n, null_behavior.0).into()
|
779
|
+
}
|
780
|
+
|
781
|
+
pub fn pct_change(&self, n: i64) -> Self {
|
782
|
+
self.inner.clone().pct_change(n).into()
|
783
|
+
}
|
784
|
+
|
785
|
+
pub fn skew(&self, bias: bool) -> Self {
|
786
|
+
self.inner.clone().skew(bias).into()
|
787
|
+
}
|
788
|
+
|
789
|
+
pub fn kurtosis(&self, fisher: bool, bias: bool) -> Self {
|
790
|
+
self.inner.clone().kurtosis(fisher, bias).into()
|
791
|
+
}
|
792
|
+
|
793
|
+
pub fn reshape(&self, dims: Vec<i64>) -> Self {
|
794
|
+
self.inner.clone().reshape(&dims).into()
|
795
|
+
}
|
796
|
+
|
797
|
+
pub fn cumcount(&self, reverse: bool) -> Self {
|
798
|
+
self.inner.clone().cumcount(reverse).into()
|
799
|
+
}
|
800
|
+
|
801
|
+
pub fn to_physical(&self) -> Self {
|
802
|
+
self.inner
|
803
|
+
.clone()
|
804
|
+
.map(
|
805
|
+
|s| Ok(Some(s.to_physical_repr().into_owned())),
|
806
|
+
GetOutput::map_dtype(|dt| dt.to_physical()),
|
807
|
+
)
|
808
|
+
.with_fmt("to_physical")
|
809
|
+
.into()
|
810
|
+
}
|
811
|
+
|
812
|
+
pub fn shuffle(&self, seed: Option<u64>) -> Self {
|
813
|
+
self.inner.clone().shuffle(seed).into()
|
814
|
+
}
|
815
|
+
|
816
|
+
pub fn sample_n(
|
817
|
+
&self,
|
818
|
+
n: usize,
|
819
|
+
with_replacement: bool,
|
820
|
+
shuffle: bool,
|
821
|
+
seed: Option<u64>,
|
822
|
+
) -> Self {
|
823
|
+
self.inner
|
824
|
+
.clone()
|
825
|
+
.sample_n(n, with_replacement, shuffle, seed)
|
826
|
+
.into()
|
827
|
+
}
|
828
|
+
|
829
|
+
pub fn sample_frac(
|
830
|
+
&self,
|
831
|
+
frac: f64,
|
832
|
+
with_replacement: bool,
|
833
|
+
shuffle: bool,
|
834
|
+
seed: Option<u64>,
|
835
|
+
) -> Self {
|
836
|
+
self.inner
|
837
|
+
.clone()
|
838
|
+
.sample_frac(frac, with_replacement, shuffle, seed)
|
839
|
+
.into()
|
840
|
+
}
|
841
|
+
|
842
|
+
pub fn ewm_mean(
|
843
|
+
&self,
|
844
|
+
alpha: f64,
|
845
|
+
adjust: bool,
|
846
|
+
min_periods: usize,
|
847
|
+
ignore_nulls: bool,
|
848
|
+
) -> Self {
|
849
|
+
let options = EWMOptions {
|
850
|
+
alpha,
|
851
|
+
adjust,
|
852
|
+
bias: false,
|
853
|
+
min_periods,
|
854
|
+
ignore_nulls,
|
855
|
+
};
|
856
|
+
self.inner.clone().ewm_mean(options).into()
|
857
|
+
}
|
858
|
+
|
859
|
+
pub fn ewm_std(
|
860
|
+
&self,
|
861
|
+
alpha: f64,
|
862
|
+
adjust: bool,
|
863
|
+
bias: bool,
|
864
|
+
min_periods: usize,
|
865
|
+
ignore_nulls: bool,
|
866
|
+
) -> Self {
|
867
|
+
let options = EWMOptions {
|
868
|
+
alpha,
|
869
|
+
adjust,
|
870
|
+
bias,
|
871
|
+
min_periods,
|
872
|
+
ignore_nulls,
|
873
|
+
};
|
874
|
+
self.inner.clone().ewm_std(options).into()
|
875
|
+
}
|
876
|
+
|
877
|
+
pub fn ewm_var(
|
878
|
+
&self,
|
879
|
+
alpha: f64,
|
880
|
+
adjust: bool,
|
881
|
+
bias: bool,
|
882
|
+
min_periods: usize,
|
883
|
+
ignore_nulls: bool,
|
884
|
+
) -> Self {
|
885
|
+
let options = EWMOptions {
|
886
|
+
alpha,
|
887
|
+
adjust,
|
888
|
+
bias,
|
889
|
+
min_periods,
|
890
|
+
ignore_nulls,
|
891
|
+
};
|
892
|
+
self.inner.clone().ewm_var(options).into()
|
893
|
+
}
|
894
|
+
|
895
|
+
pub fn extend_constant(&self, value: Wrap<AnyValue>, n: usize) -> Self {
|
896
|
+
let value = value.into_value();
|
897
|
+
self.inner
|
898
|
+
.clone()
|
899
|
+
.apply(
|
900
|
+
move |s| {
|
901
|
+
let value = value.try_convert::<Wrap<AnyValue>>().unwrap().0;
|
902
|
+
s.extend_constant(value, n).map(Some)
|
903
|
+
},
|
904
|
+
GetOutput::same_type(),
|
905
|
+
)
|
906
|
+
.with_fmt("extend")
|
907
|
+
.into()
|
908
|
+
}
|
909
|
+
|
910
|
+
pub fn any(&self) -> Self {
|
911
|
+
self.inner.clone().any().into()
|
912
|
+
}
|
913
|
+
|
914
|
+
pub fn all(&self) -> Self {
|
915
|
+
self.inner.clone().all().into()
|
916
|
+
}
|
917
|
+
|
918
|
+
pub fn log(&self, base: f64) -> Self {
|
919
|
+
self.inner.clone().log(base).into()
|
920
|
+
}
|
921
|
+
|
922
|
+
pub fn exp(&self) -> Self {
|
923
|
+
self.inner.clone().exp().into()
|
924
|
+
}
|
925
|
+
|
926
|
+
pub fn entropy(&self, base: f64, normalize: bool) -> Self {
|
927
|
+
self.inner.clone().entropy(base, normalize).into()
|
928
|
+
}
|
929
|
+
|
930
|
+
pub fn hash(&self, seed: u64, seed_1: u64, seed_2: u64, seed_3: u64) -> Self {
|
931
|
+
self.inner.clone().hash(seed, seed_1, seed_2, seed_3).into()
|
932
|
+
}
|
933
|
+
}
|