@ohos-ports/nodejs-polars 0.23.4-beta.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 (71) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +217 -0
  3. package/bin/cfg.d.ts +156 -0
  4. package/bin/cfg.js +52 -0
  5. package/bin/dataframe.d.ts +2135 -0
  6. package/bin/dataframe.js +783 -0
  7. package/bin/datatypes/conversion.d.ts +2 -0
  8. package/bin/datatypes/conversion.js +2 -0
  9. package/bin/datatypes/datatype.d.ts +285 -0
  10. package/bin/datatypes/datatype.js +430 -0
  11. package/bin/datatypes/field.d.ts +26 -0
  12. package/bin/datatypes/field.js +36 -0
  13. package/bin/datatypes/index.d.ts +43 -0
  14. package/bin/datatypes/index.js +120 -0
  15. package/bin/error.d.ts +7 -0
  16. package/bin/error.js +17 -0
  17. package/bin/functions.d.ts +26 -0
  18. package/bin/functions.js +208 -0
  19. package/bin/groupby.d.ts +212 -0
  20. package/bin/groupby.js +156 -0
  21. package/bin/html.d.ts +4 -0
  22. package/bin/html.js +18 -0
  23. package/bin/index.d.ts +256 -0
  24. package/bin/index.js +267 -0
  25. package/bin/internals/construction.d.ts +7 -0
  26. package/bin/internals/construction.js +256 -0
  27. package/bin/internals/polars_internal.d.ts +2 -0
  28. package/bin/internals/polars_internal.js +7 -0
  29. package/bin/io.d.ts +433 -0
  30. package/bin/io.js +344 -0
  31. package/bin/lazy/dataframe.d.ts +785 -0
  32. package/bin/lazy/dataframe.js +427 -0
  33. package/bin/lazy/expr/datetime.d.ts +8 -0
  34. package/bin/lazy/expr/datetime.js +27 -0
  35. package/bin/lazy/expr/index.d.ts +1152 -0
  36. package/bin/lazy/expr/index.js +632 -0
  37. package/bin/lazy/expr/list.d.ts +8 -0
  38. package/bin/lazy/expr/list.js +115 -0
  39. package/bin/lazy/expr/string.d.ts +534 -0
  40. package/bin/lazy/expr/string.js +131 -0
  41. package/bin/lazy/expr/struct.d.ts +126 -0
  42. package/bin/lazy/expr/struct.js +26 -0
  43. package/bin/lazy/functions.d.ts +612 -0
  44. package/bin/lazy/functions.js +687 -0
  45. package/bin/lazy/groupby.d.ts +29 -0
  46. package/bin/lazy/groupby.js +30 -0
  47. package/bin/lazy/index.d.ts +4 -0
  48. package/bin/lazy/index.js +20 -0
  49. package/bin/lazy/whenthen.d.ts +67 -0
  50. package/bin/lazy/whenthen.js +81 -0
  51. package/bin/native-polars.d.ts +2 -0
  52. package/bin/native-polars.js +267 -0
  53. package/bin/series/datetime.d.ts +8 -0
  54. package/bin/series/datetime.js +34 -0
  55. package/bin/series/index.d.ts +1135 -0
  56. package/bin/series/index.js +700 -0
  57. package/bin/series/list.d.ts +8 -0
  58. package/bin/series/list.js +87 -0
  59. package/bin/series/string.d.ts +300 -0
  60. package/bin/series/string.js +125 -0
  61. package/bin/series/struct.d.ts +36 -0
  62. package/bin/series/struct.js +35 -0
  63. package/bin/shared_traits.d.ts +1458 -0
  64. package/bin/shared_traits.js +2 -0
  65. package/bin/sql.d.ts +244 -0
  66. package/bin/sql.js +63 -0
  67. package/bin/types.d.ts +287 -0
  68. package/bin/types.js +2 -0
  69. package/bin/utils.d.ts +38 -0
  70. package/bin/utils.js +69 -0
  71. package/package.json +45 -0
@@ -0,0 +1,1458 @@
1
+ import type { DataType } from "./datatypes";
2
+ import type { Expr } from "./lazy/expr";
3
+ import type { ClosedWindow, InterpolationMethod, RollingOptions, RollingQuantileOptions, RollingSkewOptions, RoundMode } from "./types";
4
+ import type { ColumnsOrExpr, StartBy } from "./utils";
5
+ /**
6
+ * Arithmetic operations
7
+ */
8
+ export interface Arithmetic<T> {
9
+ /**
10
+ * Add self to other
11
+ * @category Arithmetic
12
+ */
13
+ add(other: any): T;
14
+ /**
15
+ * Subtract other from self
16
+ * @category Arithmetic
17
+ */
18
+ sub(other: any): T;
19
+ /**
20
+ * Divide self by other
21
+ * @category Arithmetic
22
+ */
23
+ div(other: any): T;
24
+ /**
25
+ * Multiply self by other
26
+ * @category Arithmetic
27
+ */
28
+ mul(other: any): T;
29
+ /**
30
+ * Get the remainder of self divided by other
31
+ * @category Arithmetic
32
+ */
33
+ rem(other: any): T;
34
+ /**
35
+ * Add self to other
36
+ * @category Arithmetic
37
+ */
38
+ plus(other: any): T;
39
+ /**
40
+ * Subtract other from self
41
+ * @category Arithmetic
42
+ */
43
+ minus(other: any): T;
44
+ /**
45
+ * Divide self by other
46
+ * @category Arithmetic
47
+ */
48
+ divideBy(other: any): T;
49
+ /**
50
+ * Multiply self by other
51
+ * @category Arithmetic
52
+ */
53
+ multiplyBy(other: any): T;
54
+ /**
55
+ * Get the remainder of self divided by other
56
+ * @category Arithmetic
57
+ */
58
+ modulo(other: any): T;
59
+ }
60
+ export interface Comparison<T> {
61
+ /**
62
+ * Compare self to other: `self == other`
63
+ * @category Comparison
64
+ */
65
+ eq(other: any): T;
66
+ /**
67
+ * Compare self to other: `self == other`
68
+ * @category Comparison
69
+ */
70
+ equals(other: any): T;
71
+ /**
72
+ * Compare self to other: `self >= other`
73
+ * @category Comparison
74
+ */
75
+ gtEq(other: any): T;
76
+ /**
77
+ * Compare self to other: `self >= other`
78
+ * @category Comparison
79
+ */
80
+ greaterThanEquals(other: any): T;
81
+ /**
82
+ * Compare self to other: `self > other`
83
+ * @category Comparison
84
+ */
85
+ gt(other: any): T;
86
+ /**
87
+ * Compare self to other: `self > other`
88
+ * @category Comparison
89
+ */
90
+ greaterThan(other: any): T;
91
+ /**
92
+ * Compare self to other: `self <= other`
93
+ * @category Comparison
94
+ */
95
+ ltEq(other: any): T;
96
+ /**
97
+ * Compare self to other: `self =< other`
98
+ * @category Comparison
99
+ */
100
+ lessThanEquals(other: any): T;
101
+ /**
102
+ * Compare self to other: `self < other`
103
+ * @category Comparison
104
+ */
105
+ lt(other: any): T;
106
+ /**
107
+ * Compare self to other: `self < other`
108
+ * @category Comparison
109
+ */
110
+ lessThan(other: any): T;
111
+ /**
112
+ * Compare self to other: `self !== other`
113
+ * @category Comparison
114
+ */
115
+ neq(other: any): T;
116
+ /**
117
+ * Compare self to other: `self !== other`
118
+ * @category Comparison
119
+ */
120
+ notEquals(other: any): T;
121
+ }
122
+ /**
123
+ * A trait for cumulative operations.
124
+ */
125
+ export interface Cumulative<T> {
126
+ /**
127
+ * Get an array with the cumulative count computed at every element.
128
+ * @category Cumulative
129
+ */
130
+ cumCount(reverse?: boolean): T;
131
+ cumCount({ reverse }: {
132
+ reverse: boolean;
133
+ }): T;
134
+ /**
135
+ * __Get an array with the cumulative max computes at every element.__
136
+ * ___
137
+ * @param reverse - reverse the operation
138
+ * @example
139
+ * ```
140
+ * > const s = pl.Series("a", [1, 2, 3])
141
+ * > s.cumMax()
142
+ * shape: (3,)
143
+ * Series: 'b' [i64]
144
+ * [
145
+ * 1
146
+ * 2
147
+ * 3
148
+ * ]
149
+ * ```
150
+ * @category Cumulative
151
+ */
152
+ cumMax(reverse?: boolean): T;
153
+ cumMax({ reverse }: {
154
+ reverse: boolean;
155
+ }): T;
156
+ /**
157
+ * __Get an array with the cumulative min computed at every element.__
158
+ * ___
159
+ * @param reverse - reverse the operation
160
+ * @example
161
+ * ```
162
+ * > const s = pl.Series("a", [1, 2, 3])
163
+ * > s.cumMin()
164
+ * shape: (3,)
165
+ * Series: 'b' [i64]
166
+ * [
167
+ * 1
168
+ * 1
169
+ * 1
170
+ * ]
171
+ * ```
172
+ * @category Cumulative
173
+ */
174
+ cumMin(reverse?: boolean): T;
175
+ cumMin({ reverse }: {
176
+ reverse: boolean;
177
+ }): T;
178
+ /**
179
+ * __Get an array with the cumulative product computed at every element.__
180
+ * ___
181
+ * @param reverse - reverse the operation
182
+ * @example
183
+ * ```
184
+ * > const s = pl.Series("a", [1, 2, 3])
185
+ * > s.cumProd()
186
+ * shape: (3,)
187
+ * Series: 'b' [i64]
188
+ * [
189
+ * 1
190
+ * 2
191
+ * 6
192
+ * ]
193
+ * ```
194
+ * @category Cumulative
195
+ */
196
+ cumProd(reverse?: boolean): T;
197
+ cumProd({ reverse }: {
198
+ reverse: boolean;
199
+ }): T;
200
+ /**
201
+ * __Get an array with the cumulative sum computed at every element.__
202
+ * ___
203
+ * @param reverse - reverse the operation
204
+ * @example
205
+ * ```
206
+ * > const s = pl.Series("a", [1, 2, 3])
207
+ * > s.cumSum()
208
+ * shape: (3,)
209
+ * Series: 'b' [i64]
210
+ * [
211
+ * 1
212
+ * 3
213
+ * 6
214
+ * ]
215
+ * ```
216
+ * @category Cumulative
217
+ */
218
+ cumSum(reverse?: boolean): T;
219
+ cumSum({ reverse }: {
220
+ reverse: boolean;
221
+ }): T;
222
+ }
223
+ /**
224
+ * __A trait for DataFrame and Series that allows for the application of a rolling window.__
225
+ */
226
+ export interface Rolling<T> {
227
+ /**
228
+ * __Apply a rolling max (moving max) over the values in this Series.__
229
+ *
230
+ * A window of length `window_size` will traverse the series. The values that fill this window
231
+ * will (optionally) be multiplied with the weights given by the `weight` vector.
232
+ *
233
+ * The resulting parameters' values will be aggregated into their sum.
234
+ * ___
235
+ * @param windowSize - The length of the window.
236
+ * @param weights - An optional slice with the same length as the window that will be multiplied
237
+ * elementwise with the values in the window.
238
+ * @param minPeriods The number of values in the window that should be non-null before computing a result.
239
+ * If undefined, it will be set equal to window size.
240
+ * @param center - Set the labels at the center of the window
241
+ * @category Rolling
242
+ */
243
+ rollingMax(windowSize: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean): T;
244
+ rollingMax(options: RollingOptions): T;
245
+ /**
246
+ * __Apply a rolling mean (moving mean) over the values in this Series.__
247
+ *
248
+ * A window of length `window_size` will traverse the series. The values that fill this window
249
+ * will (optionally) be multiplied with the weights given by the `weight` vector.
250
+ *
251
+ * The resulting parameters' values will be aggregated into their sum.
252
+ * ___
253
+ * @param windowSize - The length of the window.
254
+ * @param weights - An optional slice with the same length as the window that will be multiplied
255
+ * elementwise with the values in the window.
256
+ * @param minPeriods The number of values in the window that should be non-null before computing a result.
257
+ * If undefined, it will be set equal to window size.
258
+ * @param center - Set the labels at the center of the window
259
+ * @category Rolling
260
+ */
261
+ rollingMean(windowSize: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean): T;
262
+ rollingMean(options: RollingOptions): T;
263
+ /**
264
+ * __Apply a rolling min (moving min) over the values in this Series.__
265
+ *
266
+ * A window of length `window_size` will traverse the series. The values that fill this window
267
+ * will (optionally) be multiplied with the weights given by the `weight` vector.
268
+ *
269
+ * The resulting parameters' values will be aggregated into their sum.
270
+ * ___
271
+ * @param windowSize - The length of the window.
272
+ * @param weights - An optional slice with the same length as the window that will be multiplied
273
+ * elementwise with the values in the window.
274
+ * @param minPeriods The number of values in the window that should be non-null before computing a result.
275
+ * If undefined, it will be set equal to window size.
276
+ * @param center - Set the labels at the center of the window
277
+ * @category Rolling
278
+ */
279
+ rollingMin(windowSize: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean): T;
280
+ rollingMin(options: RollingOptions): T;
281
+ /**
282
+ * Compute a rolling std dev
283
+ *
284
+ * A window of length `window_size` will traverse the array. The values that fill this window
285
+ * will (optionally) be multiplied with the weights given by the `weight` vector. The resulting
286
+ * values will be aggregated to their sum.
287
+ * ___
288
+ * @param windowSize - The length of the window.
289
+ * @param weights - An optional slice with the same length as the window that will be multiplied
290
+ * elementwise with the values in the window.
291
+ * @param minPeriods The number of values in the window that should be non-null before computing a result.
292
+ * If undefined, it will be set equal to window size.
293
+ * @param center - Set the labels at the center of the window
294
+ * @param ddof
295
+ * "Delta Degrees of Freedom”: the divisor used in the calculation is N - ddof, where N represents the number of elements.
296
+ * By default ddof is 1.
297
+ * @category Rolling
298
+ */
299
+ rollingStd(windowSize: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean, ddof?: number): T;
300
+ rollingStd(options: RollingOptions): T;
301
+ /**
302
+ * __Apply a rolling sum (moving sum) over the values in this Series.__
303
+ *
304
+ * A window of length `window_size` will traverse the series. The values that fill this window
305
+ * will (optionally) be multiplied with the weights given by the `weight` vector.
306
+ *
307
+ * The resulting parameters' values will be aggregated into their sum.
308
+ * ___
309
+ * @param windowSize - The length of the window.
310
+ * @param weights - An optional slice with the same length as the window that will be multiplied
311
+ * elementwise with the values in the window.
312
+ * @param minPeriods The number of values in the window that should be non-null before computing a result.
313
+ * If undefined, it will be set equal to window size.
314
+ * @param center - Set the labels at the center of the window
315
+ * @category Rolling
316
+ */
317
+ rollingSum(windowSize: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean): T;
318
+ rollingSum(options: RollingOptions): T;
319
+ /**
320
+ * __Compute a rolling variance.__
321
+ *
322
+ * A window of length `window_size` will traverse the series. The values that fill this window
323
+ * will (optionally) be multiplied with the weights given by the `weight` vector.
324
+ *
325
+ * The resulting parameters' values will be aggregated into their sum.
326
+ * ___
327
+ * @param windowSize - The length of the window.
328
+ * @param weights - An optional slice with the same length as the window that will be multiplied
329
+ * elementwise with the values in the window.
330
+ * @param minPeriods The number of values in the window that should be non-null before computing a result.
331
+ * If undefined, it will be set equal to window size.
332
+ * @param center - Set the labels at the center of the window
333
+ * @param ddof
334
+ * "Delta Degrees of Freedom”: the divisor used in the calculation is N - ddof, where N represents the number of elements.
335
+ * By default ddof is 1.
336
+ * @category Rolling
337
+ */
338
+ rollingVar(windowSize: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean, ddof?: number): T;
339
+ rollingVar(options: RollingOptions): T;
340
+ /**
341
+ * Compute a rolling median
342
+ * @category Rolling
343
+ */
344
+ rollingMedian(windowSize: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean): T;
345
+ rollingMedian(options: RollingOptions): T;
346
+ /**
347
+ * Compute a rolling quantile
348
+ * @param quantile quantile to compute
349
+ * @param interpolation interpolation type
350
+ * @param windowSize Size of the rolling window
351
+ * @param weights - An optional slice with the same length as the window that will be multiplied
352
+ * elementwise with the values in the window.
353
+ * @param minPeriods The number of values in the window that should be non-null before computing a result.
354
+ * If undefined, it will be set equal to window size.
355
+ * @param center - Set the labels at the center of the window
356
+ * @category Rolling
357
+ */
358
+ rollingQuantile(quantile: number, interpolation?: InterpolationMethod, windowSize?: number, weights?: Array<number>, minPeriods?: Array<number>, center?: boolean, by?: string, closed?: ClosedWindow): T;
359
+ rollingQuantile(options: RollingQuantileOptions): T;
360
+ /**
361
+ * Compute a rolling skew
362
+ * @param windowSize Size of the rolling window
363
+ * @param bias If false, then the calculations are corrected for statistical bias.
364
+ * @category Rolling
365
+ */
366
+ rollingSkew(windowSize: number, bias?: boolean): T;
367
+ /**
368
+ * Compute a rolling skew
369
+ * @param options
370
+ * @param options.windowSize Size of the rolling window
371
+ * @param options.bias If false, then the calculations are corrected for statistical bias.
372
+ * @category Rolling
373
+ */
374
+ rollingSkew(options: RollingSkewOptions): T;
375
+ }
376
+ export interface Round<T> {
377
+ /**
378
+ * Round underlying floating point data by `decimals` digits.
379
+ *
380
+ * Similar functionality to javascript `toFixed`
381
+ * @param decimals number of decimals to round by.
382
+ * @param mode Rounding mode, the default is "half to even" (also known as "bankers' rounding").
383
+ RoundMode.
384
+ * *halftoeven*
385
+ round to the nearest even number
386
+ * *halfawayfromzero*
387
+ round to the nearest number away from zero
388
+ * @category Math
389
+ */
390
+ round(decimals: number, mode?: RoundMode): T;
391
+ round(options: {
392
+ decimals: number;
393
+ mode?: RoundMode;
394
+ }): T;
395
+ /**
396
+ * Floor underlying floating point array to the lowest integers smaller or equal to the float value.
397
+ * Only works on floating point Series
398
+ * @category Math
399
+ */
400
+ floor(): T;
401
+ /**
402
+ * Ceil underlying floating point array to the highest integers smaller or equal to the float value.
403
+ * Only works on floating point Series
404
+ * @category Math
405
+ */
406
+ ceil(): T;
407
+ /**
408
+ * Clip (limit) the values in an array to any value that fits in 64 floating point range.
409
+ * Only works for the following dtypes: {Int32, Int64, Float32, Float64, UInt32}.
410
+ * If you want to clip other dtypes, consider writing a when -> then -> otherwise expression
411
+ * @param min Minimum value
412
+ * @param max Maximum value
413
+ * @category Math
414
+ */
415
+ clip(min: number, max: number): T;
416
+ clip(options: {
417
+ min: number;
418
+ max: number;
419
+ }): any;
420
+ }
421
+ export interface Sample<T> {
422
+ /**
423
+ * Sample from this DataFrame by setting either `n` or `frac`.
424
+ * @param n - Number of samples < self.len() .
425
+ * @param frac - Fraction between 0.0 and 1.0 .
426
+ * @param withReplacement - Sample with replacement.
427
+ * @param seed - Seed initialization. If not provided, a random seed will be used
428
+ * @example
429
+ * ```
430
+ * > df = pl.DataFrame({
431
+ * > "foo": [1, 2, 3],
432
+ * > "bar": [6, 7, 8],
433
+ * > "ham": ['a', 'b', 'c']
434
+ * > })
435
+ * > df.sample({n: 2})
436
+ * shape: (2, 3)
437
+ * ╭─────┬─────┬─────╮
438
+ * │ foo ┆ bar ┆ ham │
439
+ * │ --- ┆ --- ┆ --- │
440
+ * │ i64 ┆ i64 ┆ str │
441
+ * ╞═════╪═════╪═════╡
442
+ * │ 1 ┆ 6 ┆ "a" │
443
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
444
+ * │ 3 ┆ 8 ┆ "c" │
445
+ * ╰─────┴─────┴─────╯
446
+ * ```
447
+ * @category Math
448
+ */
449
+ sample(n?: number, frac?: number, withReplacement?: boolean, seed?: number | bigint): T;
450
+ sample(opts?: {
451
+ n: number;
452
+ withReplacement?: boolean;
453
+ seed?: number | bigint;
454
+ }): T;
455
+ sample(opts?: {
456
+ frac: number;
457
+ withReplacement?: boolean;
458
+ seed?: number | bigint;
459
+ }): T;
460
+ }
461
+ export interface Bincode<T> {
462
+ (bincode: Uint8Array): T;
463
+ getState(T2: any): Uint8Array;
464
+ }
465
+ /**
466
+ * Functions that can be applied to dtype List
467
+ */
468
+ export interface ListFunctions<T> {
469
+ /**
470
+ * Retrieve the index of the minimal value in every sublist.
471
+ * @returns Expression of data type :class:`UInt32` or :class:`UInt64`
472
+ * @example
473
+ * --------
474
+ * ```
475
+ * const s0 = pl.Series("a", [[1, 2], [2, 1]]);
476
+ * s0.list.argMax();
477
+ * Series: 'a' [u32]
478
+ * [
479
+ * 0
480
+ * 1
481
+ * ]
482
+ * ```
483
+ */
484
+ argMin(): T;
485
+ /**
486
+ * Retrieve the index of the maximum value in every sublist.
487
+ * @returns Expression of data type :class:`UInt32` or :class:`UInt64`
488
+ * @example
489
+ * --------
490
+ * ```
491
+ * const s0 = pl.Series("a", [[1, 2], [2, 1]]);
492
+ * s0.list.argMax();
493
+ * Series: 'a' [u32]
494
+ * [
495
+ * 1
496
+ * 0
497
+ * ]
498
+ * ```
499
+ */
500
+ argMax(): T;
501
+ /**
502
+ * Concat the arrays in a Series dtype List in linear time.
503
+ * @param other Column(s) to concat into a List Series
504
+ * @example
505
+ * -------
506
+ * ```
507
+ * df = pl.DataFrame({
508
+ * "a": [["a"], ["x"]],
509
+ * "b": [["b", "c"], ["y", "z"]],
510
+ * })
511
+ * df.select(pl.col("a").list.concat("b"))
512
+ * shape: (2, 1)
513
+ * ┌─────────────────┐
514
+ * │ a │
515
+ * │ --- │
516
+ * │ list[str] │
517
+ * ╞═════════════════╡
518
+ * │ ["a", "b", "c"] │
519
+ * ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
520
+ * │ ["x", "y", "z"] │
521
+ * └─────────────────┘
522
+ * ```
523
+ * @category List
524
+ */
525
+ concat(other: (string | T)[] | string | T): T;
526
+ /**
527
+ * Check if sublists contain the given item.
528
+ * @param item Item that will be checked for membership
529
+ * @param nullBehavior - bool, default True If True, treat null as a distinct value. Null values will not propagate.
530
+ * @example
531
+ * --------
532
+ * ```
533
+ * df = pl.DataFrame({"foo": [[3, 2, 1], [], [1, 2]]})
534
+ * df.select(pl.col("foo").list.contains(1))
535
+ * shape: (3, 1)
536
+ * ┌───────┐
537
+ * │ foo │
538
+ * │ --- │
539
+ * │ bool │
540
+ * ╞═══════╡
541
+ * │ true │
542
+ * ├╌╌╌╌╌╌╌┤
543
+ * │ false │
544
+ * ├╌╌╌╌╌╌╌┤
545
+ * │ true │
546
+ * └───────┘
547
+ * ```
548
+ * @category List
549
+ */
550
+ contains(item: any, nullBehavior?: boolean): T;
551
+ /**
552
+ * Calculate the n-th discrete difference of every sublist.
553
+ * @param n number of slots to shift
554
+ * @param nullBehavior 'ignore' | 'drop'
555
+ * ```
556
+ * s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
557
+ * s.list.diff()
558
+ *
559
+ * shape: (2,)
560
+ * Series: 'a' [list]
561
+ * [
562
+ * [null, 1, ... 1]
563
+ * [null, -8, -1]
564
+ * ]
565
+ * ```
566
+ * @category List
567
+ */
568
+ diff(n?: number, nullBehavior?: "ignore" | "drop"): T;
569
+ /**
570
+ * Get the value by index in the sublists.
571
+ * @param index - Index to return per sublist
572
+ * @param nullOnOob - Behavior if an index is out of bounds:
573
+ * True -> set as null
574
+ * False -> raise an error
575
+ * @example
576
+ * -------
577
+ * ```
578
+ * const s0 = pl.Series("a", [[1, 2], [2, 1]]);
579
+ * s0.list.get(0);
580
+ * Series: 'a' [f64]
581
+ [
582
+ 1.0
583
+ 2.0
584
+ ]
585
+ * ```
586
+ * @category List
587
+ */
588
+ get(index: number | Expr, nullOnOob?: boolean): T;
589
+ /**
590
+ * Run any polars expression against the lists' elements
591
+ * Parameters
592
+ * ----------
593
+ * @param expr
594
+ * Expression to run. Note that you can select an element with `pl.first()`, or `pl.col()`
595
+ * @example
596
+ * >df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]})
597
+ * >df.withColumn(
598
+ * ... pl.concatList(["a", "b"]).list.eval(pl.first().rank()).alias("rank")
599
+ * ... )
600
+ * shape: (3, 3)
601
+ * ┌─────┬─────┬────────────┐
602
+ * │ a ┆ b ┆ rank │
603
+ * │ --- ┆ --- ┆ --- │
604
+ * │ i64 ┆ i64 ┆ list [f32] │
605
+ * ╞═════╪═════╪════════════╡
606
+ * │ 1 ┆ 4 ┆ [1.0, 2.0] │
607
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
608
+ * │ 8 ┆ 5 ┆ [2.0, 1.0] │
609
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
610
+ * │ 3 ┆ 2 ┆ [2.0, 1.0] │
611
+ * └─────┴─────┴────────────┘
612
+ * @category List
613
+ */
614
+ eval(expr: Expr): T;
615
+ /**
616
+ * Get the first value of the sublists.
617
+ * @category List
618
+ */
619
+ first(): T;
620
+ /**
621
+ * Slice the head of every sublist
622
+ * @param n - How many values to take in the slice.
623
+ * @example
624
+ * ```
625
+ * s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
626
+ * s.list.head(2)
627
+ * shape: (2,)
628
+ * Series: 'a' [list]
629
+ * [
630
+ * [1, 2]
631
+ * [10, 2]
632
+ * ]
633
+ * ```
634
+ * @category List
635
+ */
636
+ head(n?: number): T;
637
+ /**
638
+ * Slice the tail of every sublist
639
+ * @param n - How many values to take in the slice.
640
+ * @example
641
+ * ```
642
+ * s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]])
643
+ * s.list.tail(2)
644
+ * shape: (2,)
645
+ * Series: 'a' [list]
646
+ * [
647
+ * [3, 4]
648
+ * [2, q]
649
+ * ]
650
+ * ```
651
+ * @category List
652
+ */
653
+ tail(n?: number): T;
654
+ /**
655
+ * Join all string items in a sublist and place a separator between them.
656
+ * This errors if inner type of list `!= Utf8`.
657
+ * @param options.separator A string used to separate one element of the list from the next in the resulting string.
658
+ * If omitted, the list elements are separated with a comma.
659
+ * @param options.ignoreNulls - If true, null values will be ignored.
660
+ * @category List
661
+ */
662
+ join(options: {
663
+ separator?: string | Expr;
664
+ ignoreNulls?: boolean;
665
+ }): T;
666
+ join(): T;
667
+ join(separator: string | Expr): T;
668
+ /**
669
+ * Get the last value of the sublists.
670
+ * @category List
671
+ */
672
+ last(): T;
673
+ /**
674
+ * Get the length of the sublists.
675
+ * @category List
676
+ */
677
+ lengths(): T;
678
+ /**
679
+ * Get the maximum value of the sublists.
680
+ * @category List
681
+ */
682
+ max(): T;
683
+ /**
684
+ * Get the mean value of the sublists.
685
+ * @category List
686
+ */
687
+ mean(): T;
688
+ /**
689
+ * Get the median value of the sublists.
690
+ * @category List
691
+ */
692
+ min(): T;
693
+ /**
694
+ * Reverse the sublists.
695
+ * @category List
696
+ */
697
+ reverse(): T;
698
+ /**
699
+ * Shift the sublists.
700
+ * @param periods - Number of periods to shift. Can be positive or negative.
701
+ * @category List
702
+ */
703
+ shift(periods: number): T;
704
+ /**
705
+ * Slice the sublists.
706
+ * @param offset - The offset of the slice.
707
+ * @param length - The length of the slice.
708
+ * @category List
709
+ */
710
+ slice(offset: number, length: number): T;
711
+ /**
712
+ * Sort the sublists.
713
+ * @param descending - Sort in reverse order.
714
+ * @category List
715
+ */
716
+ sort(descending?: boolean): T;
717
+ sort(opt: {
718
+ descending: boolean;
719
+ }): T;
720
+ /**
721
+ * Sum all elements of the sublists.
722
+ * @category List
723
+ */
724
+ sum(): T;
725
+ /**
726
+ * Get the unique values of the sublists.
727
+ * @category List
728
+ */
729
+ unique(): T;
730
+ }
731
+ /**
732
+ * Functions that can be applied to a Date or Datetime column.
733
+ */
734
+ export interface DateFunctions<T> {
735
+ /**
736
+ * Extract day from underlying Date representation.
737
+ * Can be performed on Date and Datetime.
738
+ *
739
+ * Returns the day of month starting from 1.
740
+ * The return value ranges from 1 to 31. (The last day of month differs by months.)
741
+ * @returns day as pl.UInt32
742
+ */
743
+ day(): T;
744
+ /**
745
+ * Extract hour from underlying DateTime representation.
746
+ * Can be performed on Datetime.
747
+ *
748
+ * Returns the hour number from 0 to 23.
749
+ * @returns Hour as UInt32
750
+ */
751
+ hour(): T;
752
+ /**
753
+ * Extract minutes from underlying DateTime representation.
754
+ * Can be performed on Datetime.
755
+ *
756
+ * Returns the minute number from 0 to 59.
757
+ * @returns minute as UInt32
758
+ */
759
+ minute(): T;
760
+ /**
761
+ * Extract month from underlying Date representation.
762
+ * Can be performed on Date and Datetime.
763
+ *
764
+ * Returns the month number starting from 1.
765
+ * The return value ranges from 1 to 12.
766
+ * @returns Month as UInt32
767
+ */
768
+ month(): T;
769
+ /**
770
+ * Extract seconds from underlying DateTime representation.
771
+ * Can be performed on Datetime.
772
+ *
773
+ * Returns the number of nanoseconds since the whole non-leap second.
774
+ * The range from 1,000,000,000 to 1,999,999,999 represents the leap second.
775
+ * @returns Nanosecond as UInt32
776
+ */
777
+ nanosecond(): T;
778
+ /**
779
+ * Extract ordinal day from underlying Date representation.
780
+ * Can be performed on Date and Datetime.
781
+ *
782
+ * Returns the day of year starting from 1.
783
+ * The return value ranges from 1 to 366. (The last day of year differs by years.)
784
+ * @returns Day as UInt32
785
+ */
786
+ ordinalDay(): T;
787
+ /**
788
+ * Extract seconds from underlying DateTime representation.
789
+ * Can be performed on Datetime.
790
+ *
791
+ * Returns the second number from 0 to 59.
792
+ * @returns Second as UInt32
793
+ */
794
+ second(): T;
795
+ /**
796
+ * Format Date/datetime with a formatting rule: See [chrono strftime/strptime](https://docs.rs/chrono/0.4.41/chrono/format/strftime/index.html).
797
+ */
798
+ strftime(fmt: string): T;
799
+ /** Return timestamp in ms as Int64 type. */
800
+ timestamp(): T;
801
+ /**
802
+ * Extract the week from the underlying Date representation.
803
+ * Can be performed on Date and Datetime
804
+ *
805
+ * Returns the ISO week number starting from 1.
806
+ * The return value ranges from 1 to 53. (The last week of year differs by years.)
807
+ * @returns Week number as UInt32
808
+ */
809
+ week(): T;
810
+ /**
811
+ * Extract the week day from the underlying Date representation.
812
+ * Can be performed on Date and Datetime.
813
+ *
814
+ * Returns the weekday number where monday = 0 and sunday = 6
815
+ * @returns Week day as UInt32
816
+ */
817
+ weekday(): T;
818
+ /**
819
+ * Extract year from underlying Date representation.
820
+ * Can be performed on Date and Datetime.
821
+ *
822
+ * Returns the year number in the calendar date.
823
+ * @returns Year as Int32
824
+ */
825
+ year(): T;
826
+ /**
827
+ * Divide the date/datetime range into buckets.
828
+ * Each date/datetime is mapped to the start of its bucket using the corresponding local datetime. Note that:
829
+
830
+ - Weekly buckets start on Monday.
831
+ - All other buckets start on the Unix epoch (1970-01-01).
832
+ - Ambiguous results are localised using the DST offset of the original
833
+ timestamp - for example, truncating `'2022-11-06 01:30:00 CST'` by
834
+ `'1h'` results in `'2022-11-06 01:00:00 CST'`, whereas truncating
835
+ `'2022-11-06 01:30:00 CDT'` by `'1h'` results in
836
+ `'2022-11-06 01:00:00 CDT'`.
837
+
838
+ Parameters
839
+ ----------
840
+ @param every - The size of each bucket.
841
+
842
+ Notes
843
+ -----
844
+ The `every` argument is created with
845
+ the following string language:
846
+
847
+ - 1ns (1 nanosecond)
848
+ - 1us (1 microsecond)
849
+ - 1ms (1 millisecond)
850
+ - 1s (1 second)
851
+ - 1m (1 minute)
852
+ - 1h (1 hour)
853
+ - 1d (1 calendar day)
854
+ - 1w (1 calendar week)
855
+ - 1mo (1 calendar month)
856
+ - 1q (1 calendar quarter)
857
+ - 1y (1 calendar year)
858
+
859
+ By "calendar day", we mean the corresponding time on the next day (which may
860
+ not be 24 hours, due to daylight savings). Similarly for "calendar week",
861
+ "calendar month", "calendar quarter", and "calendar year".
862
+
863
+ @returns Expr Expression of data type :class:`Date` or :class:`Datetime`.
864
+ @example
865
+ --------
866
+ const df = pl.DataFrame([
867
+ pl.Series("datetime", [
868
+ new Date(Date.parse("2020-01-01T01:32:00.002+00:00")),
869
+ new Date(Date.parse("2020-01-01T02:02:01.030+00:00")),
870
+ new Date(Date.parse("2020-01-01T04:42:20.001+00:00")),
871
+ ])]);
872
+
873
+ >>> df.select("datetime", pl.col("datetime").dt.truncate("1h").alias("hr0"));
874
+ shape: (3, 2)
875
+ ┌─────────────────────────┬─────────────────────┐
876
+ │ datetime ┆ hr0 │
877
+ │ --- ┆ --- │
878
+ │ datetime[ms] ┆ datetime[ms] │
879
+ ╞═════════════════════════╪═════════════════════╡
880
+ │ 2020-01-01 01:32:00.002 ┆ 2020-01-01 01:00:00 │
881
+ │ 2020-01-01 02:02:01.030 ┆ 2020-01-01 02:00:00 │
882
+ │ 2020-01-01 04:42:20.001 ┆ 2020-01-01 04:00:00 │
883
+ └─────────────────────────┴─────────────────────┘
884
+ >>> df.select("datetime", pl.col("datetime").dt.truncate("30m").alias("hr30m"));
885
+ shape: (3, 2)
886
+ ┌─────────────────────────┬─────────────────────┐
887
+ │ datetime ┆ hr30m │
888
+ │ --- ┆ --- │
889
+ │ datetime[ms] ┆ datetime[ms] │
890
+ ╞═════════════════════════╪═════════════════════╡
891
+ │ 2020-01-01 01:32:00.002 ┆ 2020-01-01 01:30:00 │
892
+ │ 2020-01-01 02:02:01.030 ┆ 2020-01-01 02:00:00 │
893
+ │ 2020-01-01 04:42:20.001 ┆ 2020-01-01 04:30:00 │
894
+ └─────────────────────────┴─────────────────────┘
895
+ */
896
+ truncate(every: string | Expr): T;
897
+ /**
898
+ * Divide the date/datetime range into buckets.
899
+ - Each date/datetime in the first half of the interval is mapped to the start of its bucket.
900
+ - Each date/datetime in the second half of the interval is mapped to the end of its bucket.
901
+ - Half-way points are mapped to the start of their bucket.
902
+
903
+ Ambiguous results are localised using the DST offset of the original timestamp -
904
+ for example, rounding `'2022-11-06 01:20:00 CST'` by `'1h'` results in
905
+ `'2022-11-06 01:00:00 CST'`, whereas rounding `'2022-11-06 01:20:00 CDT'` by
906
+ `'1h'` results in `'2022-11-06 01:00:00 CDT'`.
907
+
908
+ @param every - Every interval start and period length
909
+ @returns Expr Expression of data type :class:`Date` or :class:`Datetime`.
910
+
911
+ Notes
912
+ -----
913
+ The `every` argument is created with the following small string formatting language:
914
+ - 1ns (1 nanosecond)
915
+ - 1us (1 microsecond)
916
+ - 1ms (1 millisecond)
917
+ - 1s (1 second)
918
+ - 1m (1 minute)
919
+ - 1h (1 hour)
920
+ - 1d (1 calendar day)
921
+ - 1w (1 calendar week)
922
+ - 1mo (1 calendar month)
923
+ - 1q (1 calendar quarter)
924
+ - 1y (1 calendar year)
925
+
926
+ By "calendar day", we mean the corresponding time on the next day (which may not be 24 hours, due to daylight savings).
927
+ Similarly for "calendar week", "calendar month", "calendar quarter", and "calendar year".
928
+
929
+ @example
930
+ --------
931
+ const df = pl.DataFrame([
932
+ pl.Series("datetime", [
933
+ new Date(Date.parse("2020-01-01T01:30:00.002+00:00")),
934
+ new Date(Date.parse("2020-01-01T02:02:01.030+00:00")),
935
+ new Date(Date.parse("2020-01-01T04:42:20.001+00:00")),
936
+ ])]);
937
+
938
+ >>> df.select("datetime", pl.col("datetime").dt.round("1h").alias("hr0"));
939
+ shape: (3, 2)
940
+ ┌─────────────────────────┬─────────────────────┐
941
+ │ datetime ┆ hr0 │
942
+ │ --- ┆ --- │
943
+ │ datetime[ms] ┆ datetime[ms] │
944
+ ╞═════════════════════════╪═════════════════════╡
945
+ │ 2020-01-01 01:30:00.002 ┆ 2020-01-01 02:00:00 │
946
+ │ 2020-01-01 02:02:01.030 ┆ 2020-01-01 02:00:00 │
947
+ │ 2020-01-01 04:42:20.001 ┆ 2020-01-01 05:00:00 │
948
+ └─────────────────────────┴─────────────────────┘
949
+ >>> df.select("datetime", pl.col("datetime").dt.round("30m").alias("hr30m"));
950
+ shape: (3, 2)
951
+ ┌─────────────────────────┬─────────────────────┐
952
+ │ datetime ┆ hr30m │
953
+ │ --- ┆ --- │
954
+ │ datetime[ms] ┆ datetime[ms] │
955
+ ╞═════════════════════════╪═════════════════════╡
956
+ │ 2020-01-01 01:32:00.002 ┆ 2020-01-01 01:30:00 │
957
+ │ 2020-01-01 02:02:01.030 ┆ 2020-01-01 02:00:00 │
958
+ │ 2020-01-01 04:42:20.001 ┆ 2020-01-01 05:00:00 │
959
+ └─────────────────────────┴─────────────────────┘
960
+ */
961
+ round(every: string | Expr): T;
962
+ }
963
+ export interface StringFunctions<T> {
964
+ /**
965
+ * Vertically concat the values in the Series to a single string value.
966
+ * @example
967
+ * ```
968
+ * > df = pl.DataFrame({"foo": [1, null, 2]})
969
+ * > df = df.select(pl.col("foo").str.concat("-"))
970
+ * > df
971
+ * shape: (1, 1)
972
+ * ┌──────────┐
973
+ * │ foo │
974
+ * │ --- │
975
+ * │ str │
976
+ * ╞══════════╡
977
+ * │ 1-null-2 │
978
+ * └──────────┘
979
+ * ```
980
+ */
981
+ concat(delimiter: string, ignoreNulls?: boolean): T;
982
+ /**
983
+ * Check if strings in Series contain a substring that matches a pattern.
984
+ * @param pat A valid regular expression pattern, compatible with the `regex crate
985
+ * @param literal Treat `pattern` as a literal string, not as a regular expression.
986
+ * @param strict Raise an error if the underlying pattern is not a valid regex, otherwise mask out with a null value.
987
+ * @returns Boolean mask
988
+ * @example
989
+ * ```
990
+ * const df = pl.DataFrame({"txt": ["Crab", "cat and dog", "rab$bit", null]})
991
+ * df.select(
992
+ * ... pl.col("txt"),
993
+ * ... pl.col("txt").str.contains("cat|bit").alias("regex"),
994
+ * ... pl.col("txt").str.contains("rab$", true).alias("literal"),
995
+ * ... )
996
+ * shape: (4, 3)
997
+ * ┌─────────────┬───────┬─────────┐
998
+ * │ txt ┆ regex ┆ literal │
999
+ * │ --- ┆ --- ┆ --- │
1000
+ * │ str ┆ bool ┆ bool │
1001
+ * ╞═════════════╪═══════╪═════════╡
1002
+ * │ Crab ┆ false ┆ false │
1003
+ * │ cat and dog ┆ true ┆ false │
1004
+ * │ rab$bit ┆ true ┆ true │
1005
+ * │ null ┆ null ┆ null │
1006
+ * └─────────────┴───────┴─────────┘
1007
+ * ```
1008
+ */
1009
+ contains(pat: string | RegExp | Expr, literal: boolean, strict: boolean): T;
1010
+ /**
1011
+ * Decodes a value using the provided encoding
1012
+ * @param encoding - hex | base64
1013
+ * @param strict - how to handle invalid inputs
1014
+ *
1015
+ * - true: method will throw error if unable to decode a value
1016
+ * - false: unhandled values will be replaced with `null`
1017
+ * @example
1018
+ * ```
1019
+ * > df = pl.DataFrame({"strings": ["666f6f", "626172", null]})
1020
+ * > df.select(col("strings").str.decode("hex"))
1021
+ * shape: (3, 1)
1022
+ * ┌─────────┐
1023
+ * │ strings │
1024
+ * │ --- │
1025
+ * │ str │
1026
+ * ╞═════════╡
1027
+ * │ foo │
1028
+ * ├╌╌╌╌╌╌╌╌╌┤
1029
+ * │ bar │
1030
+ * ├╌╌╌╌╌╌╌╌╌┤
1031
+ * │ null │
1032
+ * └─────────┘
1033
+ * ```
1034
+ */
1035
+ decode(encoding: "hex" | "base64", strict?: boolean): T;
1036
+ decode(options: {
1037
+ encoding: "hex" | "base64";
1038
+ strict?: boolean;
1039
+ }): T;
1040
+ /**
1041
+ * Encodes a value using the provided encoding
1042
+ * @param encoding - hex | base64
1043
+ * @example
1044
+ * ```
1045
+ * > df = pl.DataFrame({"strings", ["foo", "bar", null]})
1046
+ * > df.select(col("strings").str.encode("hex"))
1047
+ * shape: (3, 1)
1048
+ * ┌─────────┐
1049
+ * │ strings │
1050
+ * │ --- │
1051
+ * │ str │
1052
+ * ╞═════════╡
1053
+ * │ 666f6f │
1054
+ * ├╌╌╌╌╌╌╌╌╌┤
1055
+ * │ 626172 │
1056
+ * ├╌╌╌╌╌╌╌╌╌┤
1057
+ * │ null │
1058
+ * └─────────┘
1059
+ * ```
1060
+ */
1061
+ encode(encoding: "hex" | "base64"): T;
1062
+ /**
1063
+ * Extract the target capture group from provided patterns.
1064
+ * @param pat A valid regex pattern
1065
+ * @param groupIndex Index of the targeted capture group.
1066
+ * Group 0 mean the whole pattern, first group begin at index 1
1067
+ * Default to the first capture group
1068
+ * @returns Utf8 array. Contain null if original value is null or regex capture nothing.
1069
+ * @example
1070
+ * ```
1071
+ * > df = pl.DataFrame({
1072
+ * ... 'a': [
1073
+ * ... 'http://vote.com/ballon_dor?candidate=messi&ref=polars',
1074
+ * ... 'http://vote.com/ballon_dor?candidat=jorginho&ref=polars',
1075
+ * ... 'http://vote.com/ballon_dor?candidate=ronaldo&ref=polars'
1076
+ * ... ]})
1077
+ * > df.select(pl.col('a').str.extract(/candidate=(\w+)/, 1))
1078
+ * shape: (3, 1)
1079
+ * ┌─────────┐
1080
+ * │ a │
1081
+ * │ --- │
1082
+ * │ str │
1083
+ * ╞═════════╡
1084
+ * │ messi │
1085
+ * ├╌╌╌╌╌╌╌╌╌┤
1086
+ * │ null │
1087
+ * ├╌╌╌╌╌╌╌╌╌┤
1088
+ * │ ronaldo │
1089
+ * └─────────┘
1090
+ * ```
1091
+ */
1092
+ extract(pat: string | RegExp, groupIndex: number): T;
1093
+ /**
1094
+ * Extract the first match of json string with provided JSONPath expression.
1095
+ * Throw errors if encounter invalid json strings.
1096
+ * All return value will be casted to Utf8 regardless of the original value.
1097
+ * @see https://goessner.net/articles/JsonPath/
1098
+ * @param pat - A valid JSON path query string
1099
+ * @returns Utf8 array. Contain null if original value is null or the `jsonPath` return nothing.
1100
+ * @example
1101
+ * ```
1102
+ * > df = pl.DataFrame({
1103
+ * ... 'json_val': [
1104
+ * ... '{"a":"1"}',
1105
+ * ... null,
1106
+ * ... '{"a":2}',
1107
+ * ... '{"a":2.1}',
1108
+ * ... '{"a":true}'
1109
+ * ... ]
1110
+ * ... })
1111
+ * > df.select(pl.col('json_val').str.jsonPathMatch('$.a')
1112
+ * shape: (5,)
1113
+ * Series: 'json_val' [str]
1114
+ * [
1115
+ * "1"
1116
+ * null
1117
+ * "2"
1118
+ * "2.1"
1119
+ * "true"
1120
+ * ]
1121
+ * ```
1122
+ */
1123
+ jsonPathMatch(pat: string): T;
1124
+ /** Get length of the string values in the Series. */
1125
+ lengths(): T;
1126
+ /** Remove leading whitespace. */
1127
+ lstrip(): T;
1128
+ /** Replace first regex match with a string value. */
1129
+ replace(pat: string | RegExp, val: string): T;
1130
+ /** Replace all regex matches with a string value. */
1131
+ replaceAll(pat: string | RegExp, val: string): T;
1132
+ /** Modify the strings to their lowercase equivalent. */
1133
+ toLowerCase(): T;
1134
+ /** Modify the strings to their uppercase equivalent. */
1135
+ toUpperCase(): T;
1136
+ /** Remove trailing whitespace. */
1137
+ rstrip(): T;
1138
+ /**
1139
+ * Create subslices of the string values of a Utf8 Series.
1140
+ * @param start - Start of the slice (negative indexing may be used).
1141
+ * @param length - Optional length of the slice.
1142
+ */
1143
+ slice(start: number, length?: number): T;
1144
+ /**
1145
+ * Split a string into substrings using the specified separator and return them as a Series.
1146
+ * @param by — A string that identifies character or characters to use in separating the string.
1147
+ * @param options.inclusive Include the split character/string in the results
1148
+ */
1149
+ split(by: string, options?: {
1150
+ inclusive?: boolean;
1151
+ } | boolean): T;
1152
+ /** Remove leading and trailing whitespace. */
1153
+ strip(): T;
1154
+ /**
1155
+ * Parse a Series of dtype Utf8 to a Date/Datetime Series.
1156
+ * @param datatype Date or Datetime.
1157
+ * @param fmt formatting syntax. [Read more](https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html)
1158
+ */
1159
+ strptime(datatype: DataType.Date | DataType.Datetime | typeof DataType.Datetime, fmt?: string): T;
1160
+ }
1161
+ export interface Serialize {
1162
+ /**
1163
+ * Serializes object to desired format via [serde](https://serde.rs/)
1164
+ *
1165
+ * @param format [json](https://github.com/serde-rs/json) | [bincode](https://github.com/bincode-org/bincode)
1166
+ *
1167
+ */
1168
+ serialize(format: "json" | "bincode"): Buffer;
1169
+ }
1170
+ export interface Deserialize<T> {
1171
+ /**
1172
+ * De-serializes buffer via [serde](https://serde.rs/)
1173
+ * @param buf buffer to deserialize
1174
+ * @param format [json](https://github.com/serde-rs/json) | [bincode](https://github.com/bincode-org/bincode)
1175
+ *
1176
+ */
1177
+ deserialize(buf: Buffer, format: "json" | "bincode"): T;
1178
+ }
1179
+ /**
1180
+ * GroupBy operations that can be applied to a DataFrame or LazyFrame.
1181
+ */
1182
+ export interface GroupByOps<T> {
1183
+ /**
1184
+ Create rolling groups based on a time column (or index value of type Int32, Int64).
1185
+
1186
+ Different from a rolling groupby the windows are now determined by the individual values and are not of constant
1187
+ intervals. For constant intervals use {@link groupByDynamic}
1188
+
1189
+ The `period` and `offset` arguments are created with
1190
+ the following string language:
1191
+
1192
+ - 1ns (1 nanosecond)
1193
+ - 1us (1 microsecond)
1194
+ - 1ms (1 millisecond)
1195
+ - 1s (1 second)
1196
+ - 1m (1 minute)
1197
+ - 1h (1 hour)
1198
+ - 1d (1 day)
1199
+ - 1w (1 week)
1200
+ - 1mo (1 calendar month)
1201
+ - 1y (1 calendar year)
1202
+ - 1i (1 index count)
1203
+
1204
+ Or combine them:
1205
+ "3d12h4m25s" # 3 days, 12 hours, 4 minutes, and 25 seconds
1206
+
1207
+ In case of a groupby_rolling on an integer column, the windows are defined by:
1208
+
1209
+ - "1i" # length 1
1210
+ - "10i" # length 10
1211
+
1212
+
1213
+ @param opts.indexColumn Column used to group based on the time window.
1214
+ Often to type Date/Datetime
1215
+ This column must be sorted in ascending order. If not the output will not make sense.
1216
+
1217
+ In case of a rolling groupby on indices, dtype needs to be one of {Int32, Int64}. Note that
1218
+ Int32 gets temporarily cast to Int64, so if performance matters use an Int64 column.
1219
+ @param opts.period length of the window
1220
+ @param opts.offset offset of the window. Default is `-period`
1221
+ @param opts.closed Defines if the window interval is closed or not. Any of `{"left", "right", "both" "none"}`
1222
+ @param opts.by Also group by this column/these columns
1223
+
1224
+ @example
1225
+ ```
1226
+
1227
+ >dates = [
1228
+ ... "2020-01-01 13:45:48",
1229
+ ... "2020-01-01 16:42:13",
1230
+ ... "2020-01-01 16:45:09",
1231
+ ... "2020-01-02 18:12:48",
1232
+ ... "2020-01-03 19:45:32",
1233
+ ... "2020-01-08 23:16:43",
1234
+ ... ]
1235
+ >df = pl.DataFrame({"dt": dates, "a": [3, 7, 5, 9, 2, 1]}).withColumn(
1236
+ ... pl.col("dt").str.strptime(pl.Datetime)
1237
+ ... )
1238
+ >out = df.groupbyRolling({indexColumn:"dt", period:"2d"}).agg(
1239
+ ... [
1240
+ ... pl.sum("a").alias("sum_a"),
1241
+ ... pl.min("a").alias("min_a"),
1242
+ ... pl.max("a").alias("max_a"),
1243
+ ... ]
1244
+ ... )
1245
+ >assert(out["sum_a"].toArray() === [3, 10, 15, 24, 11, 1])
1246
+ >assert(out["max_a"].toArray() === [3, 7, 7, 9, 9, 1])
1247
+ >assert(out["min_a"].toArray() === [3, 3, 3, 3, 2, 1])
1248
+ >out
1249
+ shape: (6, 4)
1250
+ ┌─────────────────────┬───────┬───────┬───────┐
1251
+ │ dt ┆ a_sum ┆ a_max ┆ a_min │
1252
+ │ --- ┆ --- ┆ --- ┆ --- │
1253
+ │ datetime[ms] ┆ i64 ┆ i64 ┆ i64 │
1254
+ ╞═════════════════════╪═══════╪═══════╪═══════╡
1255
+ │ 2020-01-01 13:45:48 ┆ 3 ┆ 3 ┆ 3 │
1256
+ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
1257
+ │ 2020-01-01 16:42:13 ┆ 10 ┆ 7 ┆ 3 │
1258
+ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
1259
+ │ 2020-01-01 16:45:09 ┆ 15 ┆ 7 ┆ 3 │
1260
+ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
1261
+ │ 2020-01-02 18:12:48 ┆ 24 ┆ 9 ┆ 3 │
1262
+ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
1263
+ │ 2020-01-03 19:45:32 ┆ 11 ┆ 9 ┆ 2 │
1264
+ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
1265
+ │ 2020-01-08 23:16:43 ┆ 1 ┆ 1 ┆ 1 │
1266
+ └─────────────────────┴───────┴───────┴───────┘
1267
+ ```
1268
+ */
1269
+ groupByRolling(opts: {
1270
+ indexColumn: ColumnsOrExpr;
1271
+ by?: ColumnsOrExpr;
1272
+ period: string;
1273
+ offset?: string;
1274
+ closed?: "left" | "right" | "both" | "none";
1275
+ }): T;
1276
+ /**
1277
+ Groups based on a time value (or index value of type Int32, Int64). Time windows are calculated and rows are assigned to windows.
1278
+ Different from a normal groupby is that a row can be member of multiple groups. The time/index window could
1279
+ be seen as a rolling window, with a window size determined by dates/times/values instead of slots in the DataFrame.
1280
+
1281
+
1282
+ A window is defined by:
1283
+ - every: interval of the window
1284
+ - period: length of the window
1285
+ - offset: offset of the window
1286
+
1287
+ The `every`, `period` and `offset` arguments are created with
1288
+ the following string language:
1289
+
1290
+ - 1ns (1 nanosecond)
1291
+ - 1us (1 microsecond)
1292
+ - 1ms (1 millisecond)
1293
+ - 1s (1 second)
1294
+ - 1m (1 minute)
1295
+ - 1h (1 hour)
1296
+ - 1d (1 day)
1297
+ - 1w (1 week)
1298
+ - 1mo (1 calendar month)
1299
+ - 1y (1 calendar year)
1300
+ - 1i (1 index count)
1301
+
1302
+ Or combine them:
1303
+ "3d12h4m25s" # 3 days, 12 hours, 4 minutes, and 25 seconds
1304
+
1305
+ In case of a groupbyDynamic on an integer column, the windows are defined by:
1306
+
1307
+ - "1i" # length 1
1308
+ - "10i" # length 10
1309
+
1310
+ Parameters
1311
+ ----------
1312
+ @param options.indexColumn Column used to group based on the time window.
1313
+ Often to type Date/Datetime
1314
+ This column must be sorted in ascending order. If not the output will not make sense.
1315
+
1316
+ In case of a dynamic groupby on indices, dtype needs to be one of {Int32, Int64}. Note that
1317
+ Int32 gets temporarily cast to Int64, so if performance matters use an Int64 column.
1318
+ @param options.every interval of the window
1319
+ @param options.period length of the window, if None it is equal to 'every'
1320
+ @param options.offset offset of the window if None and period is None it will be equal to negative `every`
1321
+ @param options.label Define which label to use for the window: Any if {'left', 'right', 'datapoint'}
1322
+ @param options.includeBoundaries add the lower and upper bound of the window to the "_lower_bound" and "_upper_bound" columns. This will impact performance because it's harder to parallelize
1323
+ @param options.closed Defines if the window interval is closed or not. Any of {"left", "right", "both" "none"}
1324
+ @param options.by Also group by this column/these columns
1325
+ @param options.startBy The strategy to determine the start of the first window by. Any of {'window', 'datapoint', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'}
1326
+ */
1327
+ groupByDynamic(options: {
1328
+ indexColumn: string;
1329
+ every: string;
1330
+ period?: string;
1331
+ offset?: string;
1332
+ label?: string;
1333
+ includeBoundaries?: boolean;
1334
+ closed?: "left" | "right" | "both" | "none";
1335
+ by?: ColumnsOrExpr;
1336
+ startBy?: StartBy;
1337
+ }): T;
1338
+ }
1339
+ /***
1340
+ * Exponentially-weighted operations that can be applied to a Series and Expr
1341
+ */
1342
+ export interface EwmOps<T> {
1343
+ /**
1344
+ * Exponentially-weighted moving average.
1345
+ *
1346
+ * @param alpha Specify smoothing factor alpha directly, :math:`0 < \alpha \leq 1`.
1347
+ * @param adjust Divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings
1348
+ * - When ``adjust: true`` the EW function is calculated using weights :math:`w_i = (1 - \alpha)^i`
1349
+ * - When ``adjust=false`` the EW function is calculated recursively
1350
+ * @param bias When ``bias: false``, apply a correction to make the estimate statistically unbiased.
1351
+ * @param minPeriods Minimum number of observations in window required to have a value (otherwise result is null).
1352
+ * @param ignoreNulls Ignore missing values when calculating weights.
1353
+ * - When ``ignoreNulls: false`` (default), weights are based on absolute positions.
1354
+ * - When ``ignoreNulls: true``, weights are based on relative positions.
1355
+ * @returns Expr that evaluates to a float 64 Series.
1356
+ * @example
1357
+ * ```
1358
+ * > const df = pl.DataFrame({a: [1, 2, 3]});
1359
+ * > df.select(pl.col("a").ewmMean())
1360
+ * shape: (3, 1)
1361
+ * ┌──────────┐
1362
+ * │ a │
1363
+ * | --- │
1364
+ * │ f64 │
1365
+ * ╞══════════╡
1366
+ * │ 1.0 │
1367
+ * │ 1.666667 │
1368
+ * │ 2.428571 │
1369
+ * └──────────┘
1370
+ * ```
1371
+ */
1372
+ ewmMean(alpha?: number, adjust?: boolean, minPeriods?: number, bias?: boolean, ignoreNulls?: boolean): T;
1373
+ ewmMean(opts: {
1374
+ alpha?: number;
1375
+ adjust?: boolean;
1376
+ minPeriods?: number;
1377
+ bias?: boolean;
1378
+ ignoreNulls?: boolean;
1379
+ }): T;
1380
+ ewmMean(): T;
1381
+ /**
1382
+ * Exponentially-weighted standard deviation.
1383
+ *
1384
+ * @param alpha Specify smoothing factor alpha directly, :math:`0 < \alpha \leq 1`.
1385
+ * @param adjust Divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings
1386
+ * - When ``adjust: true`` the EW function is calculated using weights :math:`w_i = (1 - \alpha)^i`
1387
+ * - When ``adjust: false`` the EW function is calculated recursively
1388
+ * @param minPeriods Minimum number of observations in window required to have a value (otherwise result is null).
1389
+ * @param bias When ``bias: false``, apply a correction to make the estimate statistically unbiased.
1390
+ * @param ignoreNulls Ignore missing values when calculating weights.
1391
+ * - When ``ignoreNulls: false`` (default), weights are based on absolute positions.
1392
+ * For example, the weights of :math:`x_0` and :math:`x_2` used in calculating the final weighted average of
1393
+ * - When ``ignoreNulls: true``, weights are based on relative positions.
1394
+ * @returns Expr that evaluates to a float 64 Series.
1395
+ * @example
1396
+ * ```
1397
+ * > const df = pl.DataFrame({a: [1, 2, 3]});
1398
+ * > df.select(pl.col("a").ewmStd())
1399
+ * shape: (3, 1)
1400
+ * ┌──────────┐
1401
+ * │ a │
1402
+ * | --- │
1403
+ * │ f64 │
1404
+ * ╞══════════╡
1405
+ * │ 0.0 │
1406
+ * │ 0.707107 │
1407
+ * │ 0.963624 │
1408
+ * └──────────┘
1409
+ * ```
1410
+ */
1411
+ ewmStd(alpha?: number, adjust?: boolean, minPeriods?: number, bias?: boolean, ignoreNulls?: boolean): T;
1412
+ ewmStd(opts: {
1413
+ alpha?: number;
1414
+ adjust?: boolean;
1415
+ minPeriods?: number;
1416
+ bias?: boolean;
1417
+ ignoreNulls?: boolean;
1418
+ }): T;
1419
+ ewmStd(): T;
1420
+ /**
1421
+ * Exponentially-weighted variance.
1422
+ *
1423
+ * @param alpha Specify smoothing factor alpha directly, :math:`0 < \alpha \leq 1`.
1424
+ * @param adjust Divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings
1425
+ * - When ``adjust: true`` the EW function is calculated using weights :math:`w_i = (1 - \alpha)^i`
1426
+ * - When ``adjust: false`` the EW function is calculated recursively
1427
+ * @param minPeriods Minimum number of observations in window required to have a value (otherwise result is null).
1428
+ * @param bias When ``bias: false``, apply a correction to make the estimate statistically unbiased.
1429
+ * @param ignoreNulls Ignore missing values when calculating weights.
1430
+ * - When ``ignoreNulls: false`` (default), weights are based on absolute positions.
1431
+ * - When ``ignoreNulls=true``, weights are based on relative positions.
1432
+ * @returns Expr that evaluates to a float 64 Series.
1433
+ * @example
1434
+ * ```
1435
+ * > const df = pl.DataFrame({a: [1, 2, 3]});
1436
+ * > df.select(pl.col("a").ewmVar())
1437
+ * shape: (3, 1)
1438
+ * ┌──────────┐
1439
+ * │ a │
1440
+ * | --- │
1441
+ * │ f64 │
1442
+ * ╞══════════╡
1443
+ * │ 0.0 │
1444
+ * │ 0.5 │
1445
+ * │ 0.928571 │
1446
+ * └──────────┘
1447
+ * ```
1448
+ */
1449
+ ewmVar(alpha?: number, adjust?: boolean, minPeriods?: number, bias?: boolean, ignoreNulls?: boolean): T;
1450
+ ewmVar(opts: {
1451
+ alpha?: number;
1452
+ adjust?: boolean;
1453
+ minPeriods?: number;
1454
+ bias?: boolean;
1455
+ ignoreNulls?: boolean;
1456
+ }): T;
1457
+ ewmVar(): T;
1458
+ }