-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathindex.ts
1905 lines (1866 loc) · 57.9 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as dt from "./datetime";
import * as lst from "./list";
import * as str from "./string";
import * as struct from "./struct";
export type { StringNamespace } from "./string";
export type { ExprList as ListNamespace } from "./list";
export type { ExprDateTime as DatetimeNamespace } from "./datetime";
export type { ExprStruct as StructNamespace } from "./struct";
import { isRegExp } from "node:util/types";
import type { DataType } from "../../datatypes";
import pli from "../../internals/polars_internal";
import { Series } from "../../series";
import type {
Arithmetic,
Comparison,
Cumulative,
Deserialize,
EwmOps,
Rolling,
Round,
Sample,
Serialize,
} from "../../shared_traits";
import type {
FillNullStrategy,
InterpolationMethod,
RankMethod,
} from "../../types";
import {
type ExprOrString,
INSPECT_SYMBOL,
regexToString,
selectionToExprList,
} from "../../utils";
/**
* Expressions that can be used in various contexts.
*/
export interface Expr
extends Rolling<Expr>,
Arithmetic<Expr>,
Comparison<Expr>,
Cumulative<Expr>,
Sample<Expr>,
Round<Expr>,
EwmOps<Expr>,
Serialize {
_expr: any;
/**
* Datetime namespace
*/
get date(): dt.ExprDateTime;
/**
* String namespace
*/
get str(): str.StringNamespace;
/**
* List namespace
*/
get lst(): lst.ExprList;
/**
* Struct namespace
*/
get struct(): struct.ExprStruct;
[Symbol.toStringTag](): string;
[INSPECT_SYMBOL](): string;
toString(): string;
/** compat with `JSON.stringify` */
toJSON(): string;
/** Take absolute values */
abs(): Expr;
/**
* Get the group indexes of the group by operation.
* Should be used in aggregation context only.
* @example
* ```
>>> const df = pl.DataFrame(
... {
... "group": [
... "one",
... "one",
... "one",
... "two",
... "two",
... "two",
... ],
... "value": [94, 95, 96, 97, 97, 99],
... }
... )
>>> df.group_by("group", maintainOrder=True).agg(pl.col("value").aggGroups())
shape: (2, 2)
┌───────┬───────────┐
│ group ┆ value │
│ --- ┆ --- │
│ str ┆ list[u32] │
╞═══════╪═══════════╡
│ one ┆ [0, 1, 2] │
│ two ┆ [3, 4, 5] │
└───────┴───────────┘
*```
*/
aggGroups(): Expr;
/**
* Rename the output of an expression.
* @param name new name
* @see {@link Expr.as}
* @example
* ```
* > const df = pl.DataFrame({
* ... "a": [1, 2, 3],
* ... "b": ["a", "b", None],
* ... });
* > df
* shape: (3, 2)
* ╭─────┬──────╮
* │ a ┆ b │
* │ --- ┆ --- │
* │ i64 ┆ str │
* ╞═════╪══════╡
* │ 1 ┆ "a" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 2 ┆ "b" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 3 ┆ null │
* ╰─────┴──────╯
* > df.select([
* ... pl.col("a").alias("bar"),
* ... pl.col("b").alias("foo"),
* ... ])
* shape: (3, 2)
* ╭─────┬──────╮
* │ bar ┆ foo │
* │ --- ┆ --- │
* │ i64 ┆ str │
* ╞═════╪══════╡
* │ 1 ┆ "a" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 2 ┆ "b" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 3 ┆ null │
* ╰─────┴──────╯
*```
*/
alias(name: string): Expr;
and(other: any): Expr;
/**
* Compute the element-wise value for the inverse cosine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [0.0]})
>>> df.select(pl.col("a").acrcos())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 1.570796 │
└──────────┘
* ```
*/
arccos(): Expr;
/**
* Compute the element-wise value for the inverse hyperbolic cosine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").acrcosh())
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ f64 │
╞═════╡
│ 0.0 │
└─────┘
* ```
*/
arccosh(): Expr;
/**
* Compute the element-wise value for the inverse sine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").acrsin())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 1.570796 │
└──────────┘
* ```
*/
arcsin(): Expr;
/**
* Compute the element-wise value for the inverse hyperbolic sine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").acrsinh())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 0.881374 │
└──────────┘
* ```
*/
arcsinh(): Expr;
/**
* Compute the element-wise value for the inverse tangent.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").arctan())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 0.785398 │
└──────────┘
* ```
*/
arctan(): Expr;
/**
* Compute the element-wise value for the inverse hyperbolic tangent.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").arctanh())
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ f64 │
╞═════╡
│ inf │
└─────┘
* ```
*/
arctanh(): Expr;
/** Get the index of the maximal value. */
argMax(): Expr;
/** Get the index of the minimal value. */
argMin(): Expr;
/**
* Get the index values that would sort this column.
* @param descending
* - false -> order from small to large.
* - true -> order from large to small.
* @returns UInt32 Series
*/
argSort(descending?: boolean, maintainOrder?: boolean): Expr;
argSort({
reverse, // deprecated
maintainOrder,
}: { reverse?: boolean; maintainOrder?: boolean }): Expr;
argSort({
descending,
maintainOrder,
}: { descending?: boolean; maintainOrder?: boolean }): Expr;
/** Get index of first unique value. */
argUnique(): Expr;
/** @see {@link Expr.alias} */
as(name: string): Expr;
/** Fill missing values with the next to be seen values */
backwardFill(): Expr;
/** Cast between data types. */
cast(dtype: DataType, strict?: boolean): Expr;
/**
* Compute the element-wise value for the cosine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [0.0]})
>>> df.select(pl.col("a").cos())
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ f64 │
╞═════╡
│ 1.0 │
└─────┘
* ```
*/
cos(): Expr;
/**
* Compute the element-wise value for the hyperbolic cosine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").cosh())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 1.543081 │
└──────────┘
* ```
*/
cosh(): Expr;
/**
* Compute the element-wise value for the cotangent.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").cot().round(2))
shape: (1, 1)
┌──────┐
│ a │
│ --- │
│ f64 │
╞══════╡
│ 0.64 │
└──────┘
* ```
*/
cot(): Expr;
/** Count the number of values in this expression */
count(): Expr;
/** Calculate the n-th discrete difference.
*
* @param n number of slots to shift
* @param nullBehavior ignore or drop
*/
diff(n: number, nullBehavior: "ignore" | "drop"): Expr;
diff(o: { n: number; nullBehavior: "ignore" | "drop" }): Expr;
/**
* Compute the dot/inner product between two Expressions
* @param other Expression to compute dot product with
*/
dot(other: any): Expr;
/**
* Exclude certain columns from a wildcard/regex selection.
*
* You may also use regexes in the exclude list. They must start with `^` and end with `$`.
*
* @param columns Column(s) to exclude from selection
* @example
* ```
* > const df = pl.DataFrame({
* ... "a": [1, 2, 3],
* ... "b": ["a", "b", None],
* ... "c": [None, 2, 1],
* ...});
* > df
* shape: (3, 3)
* ╭─────┬──────┬──────╮
* │ a ┆ b ┆ c │
* │ --- ┆ --- ┆ --- │
* │ i64 ┆ str ┆ i64 │
* ╞═════╪══════╪══════╡
* │ 1 ┆ "a" ┆ null │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 2 ┆ "b" ┆ 2 │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 3 ┆ null ┆ 1 │
* ╰─────┴──────┴──────╯
* > df.select(
* ... pl.col("*").exclude("b"),
* ... );
* shape: (3, 2)
* ╭─────┬──────╮
* │ a ┆ c │
* │ --- ┆ --- │
* │ i64 ┆ i64 │
* ╞═════╪══════╡
* │ 1 ┆ null │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 2 ┆ 2 │
* ├╌╌╌╌╌┼╌╌╌╌╌╌┤
* │ 3 ┆ 1 │
* ╰─────┴──────╯
* ```
*/
exclude(column: string, ...columns: string[]): Expr;
/**
* Compute the exponential, element-wise.
* @example
* ```
>>> const df = pl.DataFrame({"values": [1.0, 2.0, 4.0]})
>>> df.select(pl.col("values").exp())
shape: (3, 1)
┌──────────┐
│ values │
│ --- │
│ f64 │
╞══════════╡
│ 2.718282 │
│ 7.389056 │
│ 54.59815 │
└──────────┘
* ```
*/
exp(): Expr;
/**
* Explode a list or utf8 Series.
*
* This means that every item is expanded to a new row.
*/
explode(): Expr;
/**
* Extend the Series with given number of values.
* @param value The value to extend the Series with. This value may be null to fill with nulls.
* @param n The number of values to extend.
* @deprecated
* @see {@link extendConstant}
*/
extend(value: any, n: number): Expr;
extend(opt: { value: any; n: number }): Expr;
/**
* Extend the Series with given number of values.
* @param value The value to extend the Series with. This value may be null to fill with nulls.
* @param n The number of values to extend.
*/
extendConstant(value: any, n: number): Expr;
extendConstant(opt: { value: any; n: number }): Expr;
/** Fill nan value with a fill value */
fillNan(other: any): Expr;
/** Fill null value with a fill value or strategy */
fillNull(other: any | FillNullStrategy): Expr;
/**
* Filter a single column.
*
* Mostly useful in in aggregation context.
* If you want to filter on a DataFrame level, use `LazyFrame.filter`.
* @param predicate Boolean expression.
*/
filter(predicate: Expr): Expr;
/** Get the first value. */
first(): Expr;
/** @see {@link Expr.explode} */
flatten(): Expr;
/** Fill missing values with the latest seen values */
forwardFill(): Expr;
/**
* Take values by index.
* @param index An expression that leads to a UInt32 dtyped Series.
*/
gather(index: Expr | number[] | Series): Expr;
gather({ index }: { index: Expr | number[] | Series }): Expr;
/** Take every nth value in the Series and return as a new Series. */
gatherEvery(n: number, offset?: number): Expr;
/** Hash the Series. */
hash(k0?: number, k1?: number, k2?: number, k3?: number): Expr;
hash({
k0,
k1,
k2,
k3,
}: { k0?: number; k1?: number; k2?: number; k3?: number }): Expr;
/** Take the first n values. */
head(length?: number): Expr;
head({ length }: { length: number }): Expr;
inner(): any;
/** Interpolate intermediate values. The interpolation method is linear. */
interpolate(): Expr;
/** Get mask of duplicated values. */
isDuplicated(): Expr;
/** Create a boolean expression returning `true` where the expression values are finite. */
isFinite(): Expr;
/** Get a mask of the first unique value. */
isFirstDistinct(): Expr;
/**
* Check if elements of this Series are in the right Series, or List values of the right Series.
*
* @param other Series of primitive type or List type.
* @returns Expr that evaluates to a Boolean Series.
* @example
* ```
* > const df = pl.DataFrame({
* ... "sets": [[1, 2, 3], [1, 2], [9, 10]],
* ... "optional_members": [1, 2, 3]
* ... });
* > df.select(
* ... pl.col("optional_members").isIn("sets").alias("contains")
* ... );
* shape: (3, 1)
* ┌──────────┐
* │ contains │
* │ --- │
* │ bool │
* ╞══════════╡
* │ true │
* ├╌╌╌╌╌╌╌╌╌╌┤
* │ true │
* ├╌╌╌╌╌╌╌╌╌╌┤
* │ false │
* └──────────┘
* ```
*/
isIn(other): Expr;
/** Create a boolean expression returning `true` where the expression values are infinite. */
isInfinite(): Expr;
/** Create a boolean expression returning `true` where the expression values are NaN (Not A Number). */
isNan(): Expr;
/** Create a boolean expression returning `true` where the expression values are not NaN (Not A Number). */
isNotNan(): Expr;
/** Create a boolean expression returning `true` where the expression does not contain null values. */
isNotNull(): Expr;
/** Create a boolean expression returning `True` where the expression contains null values. */
isNull(): Expr;
/** Get mask of unique values. */
isUnique(): Expr;
/**
* Keep the original root name of the expression.
*
* A groupby aggregation often changes the name of a column.
* With `keepName` we can keep the original name of the column
* @example
* ```
* > const df = pl.DataFrame({
* ... "a": [1, 2, 3],
* ... "b": ["a", "b", None],
* ... });
*
* > df
* ... .groupBy("a")
* ... .agg(pl.col("b").list())
* ... .sort({by:"a"});
*
* shape: (3, 2)
* ╭─────┬────────────╮
* │ a ┆ b_agg_list │
* │ --- ┆ --- │
* │ i64 ┆ list [str] │
* ╞═════╪════════════╡
* │ 1 ┆ [a] │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 2 ┆ [b] │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 3 ┆ [null] │
* ╰─────┴────────────╯
*
* Keep the original column name:
*
* > df
* ... .groupby("a")
* ... .agg(col("b").list().keepName())
* ... .sort({by:"a"})
*
* shape: (3, 2)
* ╭─────┬────────────╮
* │ a ┆ b │
* │ --- ┆ --- │
* │ i64 ┆ list [str] │
* ╞═════╪════════════╡
* │ 1 ┆ [a] │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 2 ┆ [b] │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 3 ┆ [null] │
* ╰─────┴────────────╯
* ```
*/
keepName(): Expr;
kurtosis(): Expr;
kurtosis(fisher: boolean, bias?: boolean): Expr;
kurtosis({ fisher, bias }: { fisher?: boolean; bias?: boolean }): Expr;
/** Get the last value. */
last(): Expr;
/** Aggregate to list. */
list(): Expr;
/***
* Compute the natural logarithm of each element plus one.
* This computes `log(1 + x)` but is more numerically stable for `x` close to zero.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1, 2, 3]})
>>> df.select(pl.col("a").log1p())
shape: (3, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 0.693147 │
│ 1.098612 │
│ 1.386294 │
└──────────┘
* ```
*/
log1p(): Expr;
/**
* Compute the logarithm to a given base.
* @param base - Given base, defaults to `e`
* @example
* ```
>>> const df = pl.DataFrame({"a": [1, 2, 3]})
>>> df.select(pl.col("a").log(base=2))
shape: (3, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 0.0 │
│ 1.0 │
│ 1.584963 │
└──────────┘
* ```
*/
log(base?: number): Expr;
/** Returns a unit Series with the lowest value possible for the dtype of this expression. */
lowerBound(): Expr;
peakMax(): Expr;
peakMin(): Expr;
/** Compute the max value of the arrays in the list */
max(): Expr;
/** Compute the mean value of the arrays in the list */
mean(): Expr;
/** Get median value. */
median(): Expr;
/** Get minimum value. */
min(): Expr;
/** Compute the most occurring value(s). Can return multiple Values */
mode(): Expr;
/** Negate a boolean expression. */
not(): Expr;
/** Count unique values. */
nUnique(): Expr;
or(other: any): Expr;
/**
* Apply window function over a subgroup.
*
* This is similar to a groupby + aggregation + self join.
* Or similar to [window functions in Postgres](https://www.postgresql.org/docs/9.1/tutorial-window.html)
* @param partitionBy Column(s) to partition by.
*
* @example
* ```
* > const df = pl.DataFrame({
* ... "groups": [1, 1, 2, 2, 1, 2, 3, 3, 1],
* ... "values": [1, 2, 3, 4, 5, 6, 7, 8, 8],
* ... });
* > df.select(
* ... pl.col("groups").sum().over("groups")
* ... );
* ╭────────┬────────╮
* │ groups ┆ values │
* │ --- ┆ --- │
* │ i32 ┆ i32 │
* ╞════════╪════════╡
* │ 1 ┆ 16 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 1 ┆ 16 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 2 ┆ 13 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 2 ┆ 13 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ ... ┆ ... │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 1 ┆ 16 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 2 ┆ 13 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 3 ┆ 15 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 3 ┆ 15 │
* ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
* │ 1 ┆ 16 │
* ╰────────┴────────╯
* ```
*/
over(by: ExprOrString, ...partitionBy: ExprOrString[]): Expr;
/** Raise expression to the power of exponent. */
pow(exponent: number): Expr;
pow({ exponent }: { exponent: number }): Expr;
/**
* Add a prefix the to root column name of the expression.
* @example
* ```
* > const df = pl.DataFrame({
* ... "A": [1, 2, 3, 4, 5],
* ... "fruits": ["banana", "banana", "apple", "apple", "banana"],
* ... "B": [5, 4, 3, 2, 1],
* ... "cars": ["beetle", "audi", "beetle", "beetle", "beetle"],
* ... });
* shape: (5, 4)
* ╭─────┬──────────┬─────┬──────────╮
* │ A ┆ fruits ┆ B ┆ cars │
* │ --- ┆ --- ┆ --- ┆ --- │
* │ i64 ┆ str ┆ i64 ┆ str │
* ╞═════╪══════════╪═════╪══════════╡
* │ 1 ┆ "banana" ┆ 5 ┆ "beetle" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
* │ 2 ┆ "banana" ┆ 4 ┆ "audi" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
* │ 3 ┆ "apple" ┆ 3 ┆ "beetle" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
* │ 4 ┆ "apple" ┆ 2 ┆ "beetle" │
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
* │ 5 ┆ "banana" ┆ 1 ┆ "beetle" │
* ╰─────┴──────────┴─────┴──────────╯
* > df.select(
* ... pl.col("*").reverse().prefix("reverse_"),
* ... )
* shape: (5, 8)
* ╭───────────┬────────────────┬───────────┬──────────────╮
* │ reverse_A ┆ reverse_fruits ┆ reverse_B ┆ reverse_cars │
* │ --- ┆ --- ┆ --- ┆ --- │
* │ i64 ┆ str ┆ i64 ┆ str │
* ╞═══════════╪════════════════╪═══════════╪══════════════╡
* │ 5 ┆ "banana" ┆ 1 ┆ "beetle" │
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 4 ┆ "apple" ┆ 2 ┆ "beetle" │
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 3 ┆ "apple" ┆ 3 ┆ "beetle" │
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 2 ┆ "banana" ┆ 4 ┆ "audi" │
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
* │ 1 ┆ "banana" ┆ 5 ┆ "beetle" │
* ╰───────────┴────────────────┴───────────┴──────────────╯
* ```
*/
prefix(prefix: string): Expr;
/** Get quantile value. */
quantile(quantile: number | Expr): Expr;
/**
* Assign ranks to data, dealing with ties appropriately.
* @param method : {'average', 'min', 'max', 'dense', 'ordinal', 'random'}
* @param descending - Rank in descending order.
* */
rank(method?: RankMethod, descending?: boolean): Expr;
rank({ method, descending }: { method: string; descending: boolean }): Expr;
reinterpret(signed?: boolean): Expr;
reinterpret({ signed }: { signed: boolean }): Expr;
/**
* Repeat the elements in this Series `n` times by dictated by the number given by `by`.
* The elements are expanded into a `List`
* @param by Numeric column that determines how often the values will be repeated.
*
* The column will be coerced to UInt32. Give this dtype to make the coercion a no-op.
*/
repeatBy(by: Expr | string): Expr;
/**
* Replace values by different values.
* @param old - Value or sequence of values to replace.
Accepts expression input. Sequences are parsed as Series, other non-expression inputs are parsed as literals.
* @param new_ - Value or sequence of values to replace by.
Accepts expression input. Sequences are parsed as Series, other non-expression inputs are parsed as literals.
Length must match the length of `old` or have length 1.
* @param default_ - Set values that were not replaced to this value.
Defaults to keeping the original value.
Accepts expression input. Non-expression inputs are parsed as literals.
* @param returnDtype - The data type of the resulting expression. If set to `None` (default), the data type is determined automatically based on the other inputs.
* @see {@link str.replace}
* @see {@link replace}
* @example
* Replace a single value by another value. Values that were not replaced remain unchanged.
* ```
>>> const df = pl.DataFrame({"a": [1, 2, 2, 3]});
>>> df.withColumns(pl.col("a").replace(2, 100).alias("replaced"));
shape: (4, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪══════════╡
│ 1 ┆ 1 │
│ 2 ┆ 100 │
│ 2 ┆ 100 │
│ 3 ┆ 3 │
└─────┴──────────┘
* ```
* Replace multiple values by passing sequences to the `old` and `new_` parameters.
* ```
>>> df.withColumns(pl.col("a").replace([2, 3], [100, 200]).alias("replaced"));
shape: (4, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪══════════╡
│ 1 ┆ 1 │
│ 2 ┆ 100 │
│ 2 ┆ 100 │
│ 3 ┆ 200 │
└─────┴──────────┘
* ```
* Passing a mapping with replacements is also supported as syntactic sugar.
Specify a default to set all values that were not matched.
* ```
>>> const mapping = {2: 100, 3: 200};
>>> df.withColumns(pl.col("a").replaceStrict({ old: mapping, default_: -1, returnDtype: pl.Int64 }).alias("replaced");
shape: (4, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪══════════╡
│ 1 ┆ -1 │
│ 2 ┆ 100 │
│ 2 ┆ 100 │
│ 3 ┆ 200 │
└─────┴──────────┘
* ```
Replacing by values of a different data type sets the return type based on
a combination of the `new_` data type and either the original data type or the
default data type if it was set.
* ```
>>> const df = pl.DataFrame({"a": ["x", "y", "z"]});
>>> const mapping = {"x": 1, "y": 2, "z": 3};
>>> df.withColumns(pl.col("a").replaceStrict({ old: mapping }).alias("replaced"));
shape: (3, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ str ┆ str │
╞═════╪══════════╡
│ x ┆ 1 │
│ y ┆ 2 │
│ z ┆ 3 │
└─────┴──────────┘
>>> df.withColumns(pl.col("a").replaceStrict({ old: mapping, default_: None }).alias("replaced"));
shape: (3, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ str ┆ i64 │
╞═════╪══════════╡
│ x ┆ 1 │
│ y ┆ 2 │
│ z ┆ 3 │
└─────┴──────────┘
* ```
Set the `returnDtype` parameter to control the resulting data type directly.
* ```
>>> df.withColumns(pl.col("a").replaceStrict({ old: mapping, returnDtype: pl.UInt8 }).alias("replaced"));
shape: (3, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ str ┆ u8 │
╞═════╪══════════╡
│ x ┆ 1 │
│ y ┆ 2 │
│ z ┆ 3 │
└─────┴──────────┘
* ```
* Expression input is supported for all parameters.
* ```
>>> const df = pl.DataFrame({"a": [1, 2, 2, 3], "b": [1.5, 2.5, 5.0, 1.0]});
>>> df.withColumns(
... pl.col("a").replaceStrict({
... old: pl.col("a").max(),
... new_: pl.col("b").sum(),
... default_: pl.col("b"),
... }).alias("replaced")
... );
shape: (4, 3)
┌─────┬─────┬──────────┐
│ a ┆ b ┆ replaced │
│ --- ┆ --- ┆ --- │
│ i64 ┆ f64 ┆ f64 │
╞═════╪═════╪══════════╡
│ 1 ┆ 1.5 ┆ 1.5 │
│ 2 ┆ 2.5 ┆ 2.5 │
│ 2 ┆ 5.0 ┆ 5.0 │
│ 3 ┆ 1.0 ┆ 10.0 │
└─────┴─────┴──────────┘
* ```
*/
replaceStrict(
old: Expr | string | number | (number | string)[],
new_: Expr | string | number | (number | string)[],
default_?: Expr | string | number | (number | string)[],
returnDtype?: DataType,
): Expr;
replaceStrict({
old,
new_,
default_,
returnDtype,
}: {
old: unknown | Expr | string | number | (number | string)[];
new_?: Expr | string | number | (number | string)[];
default_?: Expr | string | number | (number | string)[];
returnDtype?: DataType;
}): Expr;
/**
* Replace the given values by different values of the same data type.
* @param old - Value or sequence of values to replace.
Accepts expression input. Sequences are parsed as Series, other non-expression inputs are parsed as literals.
* @param new_ - Value or sequence of values to replace by.
Accepts expression input. Sequences are parsed as Series, other non-expression inputs are parsed as literals.
Length must match the length of `old` or have length 1.
* @see {@link replace_strict}
* @see {@link str.replace}
* @example
* Replace a single value by another value. Values that were not replaced remain unchanged.
* ```
>>> const df = pl.DataFrame({"a": [1, 2, 2, 3]});
>>> df.withColumns(pl.col("a").replace(2, 100).alias("replaced"));
shape: (4, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪══════════╡
│ 1 ┆ 1 │
│ 2 ┆ 100 │
│ 2 ┆ 100 │
│ 3 ┆ 3 │
└─────┴──────────┘
* ```
* Replace multiple values by passing sequences to the `old` and `new_` parameters.
* ```
>>> df.withColumns(pl.col("a").replace([2, 3], [100, 200]).alias("replaced"));
shape: (4, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪══════════╡
│ 1 ┆ 1 │
│ 2 ┆ 100 │
│ 2 ┆ 100 │
│ 3 ┆ 200 │
└─────┴──────────┘
* ```
* Passing a mapping with replacements is also supported as syntactic sugar.
Specify a default to set all values that were not matched.
* ```
>>> const mapping = {2: 100, 3: 200};
>>> df.withColumns(pl.col("a").replace({ old: mapping }).alias("replaced");
shape: (4, 2)
┌─────┬──────────┐
│ a ┆ replaced │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪══════════╡
│ 1 ┆ -1 │
│ 2 ┆ 100 │
│ 2 ┆ 100 │
│ 3 ┆ 200 │
└─────┴──────────┘
* ```
*/
replace(
old: Expr | string | number | (number | string)[],
new_: Expr | string | number | (number | string)[],
): Expr;
replace({
old,
new_,
}: {
old: unknown | Expr | string | number | (number | string)[];
new_?: Expr | string | number | (number | string)[];
}): Expr;
/** Reverse the arrays in the list */
reverse(): Expr;
/**
* Shift the values by a given period and fill the parts that will be empty due to this operation
* @param periods number of places to shift (may be negative).
*/
shift(periods?: number): Expr;
shift({ periods }: { periods: number }): Expr;
/**
* Shift the values by a given period and fill the parts that will be empty due to this operation
* @param periods Number of places to shift (may be negative).
* @param fillValue Fill null values with the result of this expression.
*/
shiftAndFill(periods: number, fillValue: number): Expr;
shiftAndFill({
periods,
fillValue,
}: { periods: number; fillValue: number }): Expr;
/**
* Compute the element-wise value for the sine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [0.0]})
>>> df.select(pl.col("a").sin())
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ f64 │
╞═════╡
│ 0.0 │