@@ -69,6 +69,36 @@ export interface Expr
69
69
toJSON ( ) : string ;
70
70
/** Take absolute values */
71
71
abs ( ) : Expr ;
72
+ /**
73
+ * Get the group indexes of the group by operation.
74
+ * Should be used in aggregation context only.
75
+ * @example
76
+ * ```
77
+ >>> const df = pl.DataFrame(
78
+ ... {
79
+ ... "group": [
80
+ ... "one",
81
+ ... "one",
82
+ ... "one",
83
+ ... "two",
84
+ ... "two",
85
+ ... "two",
86
+ ... ],
87
+ ... "value": [94, 95, 96, 97, 97, 99],
88
+ ... }
89
+ ... )
90
+ >>> df.group_by("group", maintain_order=True).agg(pl.col("value").aggGroups())
91
+ shape: (2, 2)
92
+ ┌───────┬───────────┐
93
+ │ group ┆ value │
94
+ │ --- ┆ --- │
95
+ │ str ┆ list[u32] │
96
+ ╞═══════╪═══════════╡
97
+ │ one ┆ [0, 1, 2] │
98
+ │ two ┆ [3, 4, 5] │
99
+ └───────┴───────────┘
100
+ *```
101
+ */
72
102
aggGroups ( ) : Expr ;
73
103
/**
74
104
* Rename the output of an expression.
@@ -137,6 +167,24 @@ export interface Expr
137
167
backwardFill ( ) : Expr ;
138
168
/** Cast between data types. */
139
169
cast ( dtype : DataType , strict ?: boolean ) : Expr ;
170
+ /**
171
+ * Compute the element-wise value for the cosine.
172
+ * @returns Expression of data type :class:`Float64`.
173
+ * @example
174
+ * ```
175
+ >>> const df = pl.DataFrame({"a": [0.0]})
176
+ >>> df.select(pl.col("a").cos())
177
+ shape: (1, 1)
178
+ ┌─────┐
179
+ │ a │
180
+ │ --- │
181
+ │ f64 │
182
+ ╞═════╡
183
+ │ 1.0 │
184
+ └─────┘
185
+ * ```
186
+ */
187
+ cos ( ) : Expr ;
140
188
/** Count the number of values in this expression */
141
189
count ( ) : Expr ;
142
190
/** Calculate the n-th discrete difference.
@@ -151,7 +199,6 @@ export interface Expr
151
199
* @param other Expression to compute dot product with
152
200
*/
153
201
dot ( other : any ) : Expr ;
154
-
155
202
/**
156
203
* Exclude certain columns from a wildcard/regex selection.
157
204
*
@@ -196,6 +243,25 @@ export interface Expr
196
243
* ```
197
244
*/
198
245
exclude ( column : string , ...columns : string [ ] ) : Expr ;
246
+ /**
247
+ * Compute the exponential, element-wise.
248
+ * @example
249
+ * ```
250
+ >>> const df = pl.DataFrame({"values": [1.0, 2.0, 4.0]})
251
+ >>> df.select(pl.col("values").exp())
252
+ shape: (3, 1)
253
+ ┌──────────┐
254
+ │ values │
255
+ │ --- │
256
+ │ f64 │
257
+ ╞══════════╡
258
+ │ 2.718282 │
259
+ │ 7.389056 │
260
+ │ 54.59815 │
261
+ └──────────┘
262
+ * ```
263
+ */
264
+ exp ( ) : Expr ;
199
265
/**
200
266
* Explode a list or utf8 Series.
201
267
*
@@ -236,6 +302,14 @@ export interface Expr
236
302
flatten ( ) : Expr ;
237
303
/** Fill missing values with the latest seen values */
238
304
forwardFill ( ) : Expr ;
305
+ /**
306
+ * Take values by index.
307
+ * @param index An expression that leads to a UInt32 dtyped Series.
308
+ */
309
+ gather ( index : Expr | number [ ] | Series ) : Expr ;
310
+ gather ( { index } : { index : Expr | number [ ] | Series } ) : Expr ;
311
+ /** Take every nth value in the Series and return as a new Series. */
312
+ gatherEvery ( n : number , offset ?: number ) : Expr ;
239
313
/** Hash the Series. */
240
314
hash ( k0 ?: number , k1 ?: number , k2 ?: number , k3 ?: number ) : Expr ;
241
315
hash ( {
@@ -356,6 +430,46 @@ export interface Expr
356
430
last ( ) : Expr ;
357
431
/** Aggregate to list. */
358
432
list ( ) : Expr ;
433
+ /***
434
+ * Compute the natural logarithm of each element plus one.
435
+ * This computes `log(1 + x)` but is more numerically stable for `x` close to zero.
436
+ * @example
437
+ * ```
438
+ >>> const df = pl.DataFrame({"a": [1, 2, 3]})
439
+ >>> df.select(pl.col("a").log1p())
440
+ shape: (3, 1)
441
+ ┌──────────┐
442
+ │ a │
443
+ │ --- │
444
+ │ f64 │
445
+ ╞══════════╡
446
+ │ 0.693147 │
447
+ │ 1.098612 │
448
+ │ 1.386294 │
449
+ └──────────┘
450
+ * ```
451
+ */
452
+ log1p ( ) : Expr ;
453
+ /**
454
+ * Compute the logarithm to a given base.
455
+ * @param base - Given base, defaults to `e`
456
+ * @example
457
+ * ```
458
+ >>> const df = pl.DataFrame({"a": [1, 2, 3]})
459
+ >>> df.select(pl.col("a").log(base=2))
460
+ shape: (3, 1)
461
+ ┌──────────┐
462
+ │ a │
463
+ │ --- │
464
+ │ f64 │
465
+ ╞══════════╡
466
+ │ 0.0 │
467
+ │ 1.0 │
468
+ │ 1.584963 │
469
+ └──────────┘
470
+ * ```
471
+ */
472
+ log ( base ?: number ) : Expr ;
359
473
/** Returns a unit Series with the lowest value possible for the dtype of this expression. */
360
474
lowerBound ( ) : Expr ;
361
475
peakMax ( ) : Expr ;
@@ -503,6 +617,24 @@ export interface Expr
503
617
periods,
504
618
fillValue,
505
619
} : { periods : number ; fillValue : number } ) : Expr ;
620
+ /**
621
+ * Compute the element-wise value for the sine.
622
+ * @returns Expression of data type :class:`Float64`.
623
+ * @example
624
+ * ```
625
+ >>> const df = pl.DataFrame({"a": [0.0]})
626
+ >>> df.select(pl.col("a").sin())
627
+ shape: (1, 1)
628
+ ┌─────┐
629
+ │ a │
630
+ │ --- │
631
+ │ f64 │
632
+ ╞═════╡
633
+ │ 0.0 │
634
+ └─────┘
635
+ *```
636
+ */
637
+ sin ( ) : Expr ;
506
638
/**
507
639
* Compute the sample skewness of a data set.
508
640
* For normally distributed data, the skewness should be about zero. For
@@ -565,13 +697,23 @@ export interface Expr
565
697
tail ( length ?: number ) : Expr ;
566
698
tail ( { length } : { length : number } ) : Expr ;
567
699
/**
568
- * Take values by index.
569
- * @param index An expression that leads to a UInt32 dtyped Series.
700
+ * Compute the element-wise value for the tangent.
701
+ * @returns Expression of data type :class:`Float64`.
702
+ * @example
703
+ *```
704
+ >>> const df = pl.DataFrame({"a": [1.0]})
705
+ >>> df.select(pl.col("a").tan().round(2))
706
+ shape: (1, 1)
707
+ ┌──────┐
708
+ │ a │
709
+ │ --- │
710
+ │ f64 │
711
+ ╞══════╡
712
+ │ 1.56 │
713
+ └──────┘
714
+ *```
570
715
*/
571
- gather ( index : Expr | number [ ] | Series ) : Expr ;
572
- gather ( { index } : { index : Expr | number [ ] | Series } ) : Expr ;
573
- /** Take every nth value in the Series and return as a new Series. */
574
- gatherEvery ( n : number , offset ?: number ) : Expr ;
716
+ tan ( ) : Expr ;
575
717
/**
576
718
* Get the unique values of this expression;
577
719
* @param maintainOrder Maintain order of data. This requires more work.
@@ -709,6 +851,9 @@ export const _Expr = (_expr: any): Expr => {
709
851
) ,
710
852
) ;
711
853
} ,
854
+ cos ( ) {
855
+ return _Expr ( _expr . cos ( ) ) ;
856
+ } ,
712
857
count ( ) {
713
858
return _Expr ( _expr . count ( ) ) ;
714
859
} ,
@@ -859,6 +1004,9 @@ export const _Expr = (_expr: any): Expr => {
859
1004
explode ( ) {
860
1005
return _Expr ( _expr . explode ( ) ) ;
861
1006
} ,
1007
+ exp ( ) {
1008
+ return _Expr ( _expr . exp ( ) ) ;
1009
+ } ,
862
1010
extend ( o , n ?) {
863
1011
if ( n !== null && typeof n === "number" ) {
864
1012
return _Expr ( _expr . extendConstant ( o , n ) ) ;
@@ -908,6 +1056,17 @@ export const _Expr = (_expr: any): Expr => {
908
1056
forwardFill ( ) {
909
1057
return _Expr ( _expr . forwardFill ( ) ) ;
910
1058
} ,
1059
+ gather ( indices ) {
1060
+ if ( Array . isArray ( indices ) ) {
1061
+ indices = pli . lit ( Series ( indices ) . inner ( ) ) ;
1062
+ } else {
1063
+ indices = indices . inner ( ) ;
1064
+ }
1065
+ return wrap ( "gather" , indices ) ;
1066
+ } ,
1067
+ gatherEvery ( n , offset = 0 ) {
1068
+ return _Expr ( _expr . gatherEvery ( n , offset ) ) ;
1069
+ } ,
911
1070
hash ( obj : any = 0 , k1 = 1 , k2 = 2 , k3 = 3 ) {
912
1071
if ( typeof obj === "number" || typeof obj === "bigint" ) {
913
1072
return wrap ( "hash" , BigInt ( obj ) , BigInt ( k1 ) , BigInt ( k2 ) , BigInt ( k3 ) ) ;
@@ -974,7 +1133,6 @@ export const _Expr = (_expr: any): Expr => {
974
1133
kurtosis ( obj ?, bias = true ) {
975
1134
const fisher = obj ?. [ "fisher" ] ?? ( typeof obj === "boolean" ? obj : true ) ;
976
1135
bias = obj ?. [ "bias" ] ?? bias ;
977
-
978
1136
return _Expr ( _expr . kurtosis ( fisher , bias ) ) ;
979
1137
} ,
980
1138
last ( ) {
@@ -983,6 +1141,13 @@ export const _Expr = (_expr: any): Expr => {
983
1141
list ( ) {
984
1142
return _Expr ( _expr . list ( ) ) ;
985
1143
} ,
1144
+ log1p ( ) {
1145
+ console . log ( _expr . log1p ) ;
1146
+ return _Expr ( _expr . log1p ( ) ) ;
1147
+ } ,
1148
+ log ( base ?: number ) {
1149
+ return _Expr ( _expr . log ( base ?? Math . E ) ) ;
1150
+ } ,
986
1151
lowerBound ( ) {
987
1152
return _Expr ( _expr . lowerBound ( ) ) ;
988
1153
} ,
@@ -1139,6 +1304,9 @@ export const _Expr = (_expr: any): Expr => {
1139
1304
skew ( bias ) {
1140
1305
return wrap ( "skew" , bias ?. bias ?? bias ?? true ) ;
1141
1306
} ,
1307
+ sin ( ) {
1308
+ return _Expr ( _expr . sin ( ) ) ;
1309
+ } ,
1142
1310
slice ( arg , len ?) {
1143
1311
if ( typeof arg === "number" ) {
1144
1312
return wrap ( "slice" , pli . lit ( arg ) , pli . lit ( len ) ) ;
@@ -1181,16 +1349,8 @@ export const _Expr = (_expr: any): Expr => {
1181
1349
tail ( length ) {
1182
1350
return _Expr ( _expr . tail ( length ) ) ;
1183
1351
} ,
1184
- gather ( indices ) {
1185
- if ( Array . isArray ( indices ) ) {
1186
- indices = pli . lit ( Series ( indices ) . inner ( ) ) ;
1187
- } else {
1188
- indices = indices . inner ( ) ;
1189
- }
1190
- return wrap ( "gather" , indices ) ;
1191
- } ,
1192
- gatherEvery ( n , offset = 0 ) {
1193
- return _Expr ( _expr . gatherEvery ( n , offset ) ) ;
1352
+ tan ( ) {
1353
+ return _Expr ( _expr . tan ( ) ) ;
1194
1354
} ,
1195
1355
unique ( opt ?) {
1196
1356
if ( opt || opt ?. maintainOrder ) {
0 commit comments