df-script 1.8.0 → 2.0.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 (64) hide show
  1. package/README.md +153 -203
  2. package/dist/api.d.ts +41 -36
  3. package/dist/columnExpressions/ColumnExpr.d.ts +5 -8
  4. package/dist/columnExpressions/ExprBase.d.ts +7 -0
  5. package/dist/columnExpressions/constants.d.ts +1 -0
  6. package/dist/columnExpressions/functions/all.d.ts +13 -13
  7. package/dist/columnExpressions/functions/coalesce.d.ts +2 -2
  8. package/dist/columnExpressions/functions/duration.d.ts +16 -21
  9. package/dist/columnExpressions/functions/element.d.ts +10 -10
  10. package/dist/columnExpressions/functions/exclude.d.ts +14 -14
  11. package/dist/columnExpressions/functions/implode.d.ts +7 -7
  12. package/dist/columnExpressions/functions/lit.d.ts +9 -9
  13. package/dist/columnExpressions/functions/seqRange.d.ts +69 -0
  14. package/dist/columnExpressions/functions/struct.d.ts +6 -6
  15. package/dist/columnExpressions/functions/when.d.ts +31 -32
  16. package/dist/columnExpressions/index.d.ts +4 -7
  17. package/dist/columnExpressions/mixins/AggregationExpr.d.ts +672 -141
  18. package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +701 -327
  19. package/dist/columnExpressions/mixins/ArrayExpr.d.ts +543 -231
  20. package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +398 -201
  21. package/dist/columnExpressions/mixins/LogicalExpr.d.ts +59 -29
  22. package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +23 -9
  23. package/dist/columnExpressions/mixins/StandardExpr.d.ts +3234 -0
  24. package/dist/columnExpressions/mixins/StringExpr.d.ts +1299 -396
  25. package/dist/columnExpressions/mixins/StructExpr.d.ts +72 -30
  26. package/dist/columnExpressions/mixins/TemporalExpr.d.ts +518 -212
  27. package/dist/columnExpressions/mixins/WindowExpr.d.ts +270 -102
  28. package/dist/columnExpressions/typeInference.d.ts +13 -0
  29. package/dist/columnExpressions/types.d.ts +6 -1
  30. package/dist/columnExpressions/utils.d.ts +16 -0
  31. package/dist/constants.d.ts +38 -0
  32. package/dist/dataframe/dataframe.d.ts +755 -608
  33. package/dist/dataframe/grouped/grouped.d.ts +24 -6
  34. package/dist/dataframe/grouped.d.ts +70 -0
  35. package/dist/dataframe/index.d.ts +1 -1
  36. package/dist/dataframe/lazy.d.ts +37 -0
  37. package/dist/dataframe/types.d.ts +46 -22
  38. package/dist/dataframe/utils.d.ts +10 -4
  39. package/dist/datatypes/index.d.ts +11 -4
  40. package/dist/expressions.js +1 -0
  41. package/dist/expressions.mjs +1 -0
  42. package/dist/functions/concat.d.ts +68 -16
  43. package/dist/functions/index.d.ts +2 -2
  44. package/dist/functions/readCsv.d.ts +35 -0
  45. package/dist/functions/readJson.d.ts +33 -0
  46. package/dist/index.js +5 -6
  47. package/dist/index.mjs +5 -6
  48. package/dist/types.d.ts +148 -7
  49. package/dist/utils/array.d.ts +54 -18
  50. package/dist/utils/binary.d.ts +6 -2
  51. package/dist/utils/csv.d.ts +4 -1
  52. package/dist/utils/date.d.ts +3 -19
  53. package/dist/utils/duration.d.ts +7 -5
  54. package/dist/utils/json.d.ts +56 -2
  55. package/dist/utils/number.d.ts +5 -2
  56. package/dist/utils/object.d.ts +7 -12
  57. package/dist/utils/string.d.ts +83 -2
  58. package/dist/utils/table.d.ts +76 -0
  59. package/dist/utils.js +4 -0
  60. package/dist/utils.mjs +4 -0
  61. package/package.json +29 -8
  62. package/dist/assets/index-DBhGK6Tp.css +0 -1
  63. package/dist/assets/index-DEJEV_tU.js +0 -195
  64. package/dist/index.html +0 -17
@@ -1,4 +1,4 @@
1
- import type { AggFn, UniqueArrayStatsOptions } from "../../types";
1
+ import type { AggFn, UniqueArrayStatsOptions, SkewOptions, KurtosisOptions, EntropyOptions } from "../../types";
2
2
  import { ExprBase } from "../ExprBase";
3
3
  /**
4
4
  * @namespace $df.col
@@ -12,81 +12,205 @@ export declare class AggregationExpr extends ExprBase {
12
12
  * Aggregation: Returns true if all values in the group are truthy.
13
13
  * @returns ColumnExpression
14
14
  * @example
15
- * >>> const df = $df.data({ group: ["A", "A", "B"], val: [true, true, false] })
16
- * >>> df.group_by("group").agg($df.col("val").all().alias("all_true"))
17
- * shape: (2, 2)
18
- * ┌───────┬──────────┐
19
- * │ group all_true
20
- * ├───────┼──────────┤
21
- * │ "A" │ true
22
- * │ "B" │ false
23
- * └───────┴──────────┘
15
+ * >>> const df = $df.data({ a: [true, true, false, false], b: [true, false, true, false] })
16
+ * >>> df
17
+ * shape: (4, 2)
18
+ * ┌───────┬───────┐
19
+ * │ a b
20
+ * ├───────┼───────┤
21
+ * │ true │ true
22
+ * │ true │ false
23
+ * │ false │ true │
24
+ * │ false │ false │
25
+ * └───────┴───────┘
26
+ * >>> df.select($df.col("a").all().alias("all_true"))
27
+ * shape: (1, 1)
28
+ * ┌──────────┐
29
+ * │ all_true │
30
+ * ├──────────┤
31
+ * │ false │
32
+ * └──────────┘
24
33
  */
25
34
  all(): this;
26
35
  /**
27
- * Aggregation: Checks if all values in the group are null.
36
+ * Aggregation: Checks if any value in the group is truthy.
28
37
  * @returns ColumnExpression
29
38
  * @example
30
- * >>> const df = $df.data({ group: ["A", "A"], val: [null, null] })
31
- * >>> df.group_by("group").agg($df.col("val").all_null().alias("is_null"))
32
- * shape: (1, 2)
33
- * ┌───────┬─────────┐
34
- * │ group is_null
35
- * ├───────┼─────────┤
36
- * │ "A" │ true
37
- * └───────┴─────────┘
39
+ * >>> const df = $df.data({ a: [true, true, false, false], b: [true, false, true, false] })
40
+ * >>> df
41
+ * shape: (4, 2)
42
+ * ┌───────┬───────┐
43
+ * │ a b
44
+ * ├───────┼───────┤
45
+ * │ true │ true
46
+ * │ true │ false │
47
+ * │ false │ true │
48
+ * │ false │ false │
49
+ * └───────┴───────┘
50
+ * >>> df.select($df.col("a").any().alias("any_true"))
51
+ * shape: (1, 1)
52
+ * ┌──────────┐
53
+ * │ any_true │
54
+ * ├──────────┤
55
+ * │ true │
56
+ * └──────────┘
38
57
  */
39
- all_null(): this;
58
+ any(): this;
40
59
  /**
41
- * Aggregation: Checks if any value in the group is truthy.
60
+ * Aggregation: Finds the index of the maximum value in the group.
42
61
  * @returns ColumnExpression
43
62
  * @example
44
- * >>> const df = $df.data({ group: ["A", "A", "B"], val: [true, false, false] })
45
- * >>> df.group_by("group").agg($df.col("val").any().alias("any_true"))
46
- * shape: (2, 2)
47
- * ┌───────┬──────────┐
48
- * │ group any_true │
49
- * ├───────┼──────────┤
50
- * │ "A" │ true
51
- * │ "B" │ false
52
- * └───────┴──────────┘
63
+ * >>> const df = $df.data({ a: [1, 2, 3] })
64
+ * >>> df
65
+ * shape: (3, 1)
66
+ * ┌───┐
67
+ * │ a
68
+ * ├───┤
69
+ * │ 1
70
+ * │ 2
71
+ * │ 3 │
72
+ * └───┘
73
+ * >>> df.select($df.col("val").argMax().alias("max_idx"))
74
+ * shape: (1, 1)
75
+ * ┌─────────┐
76
+ * │ max_idx │
77
+ * ├─────────┤
78
+ * │ 2 │
79
+ * └─────────┘
53
80
  */
54
- any(): this;
81
+ argMax(): this;
55
82
  /**
56
- * Aggregation: Checks if any value in the group is null.
83
+ * Aggregation: Finds the index of the minimum value in the group.
57
84
  * @returns ColumnExpression
58
85
  * @example
59
- * >>> const df = $df.data({ group: ["A", "A"], val: [10, null] })
60
- * >>> df.group_by("group").agg($df.col("val").any_null().alias("has_null"))
61
- * shape: (1, 2)
62
- * ┌───────┬──────────┐
63
- * │ group has_null │
64
- * ├───────┼──────────┤
65
- * │ "A" │ true
66
- * └───────┴──────────┘
86
+ * >>> const df = $df.data({ a: [1, 2, 3] })
87
+ * >>> df
88
+ * shape: (3, 1)
89
+ * ┌───┐
90
+ * │ a
91
+ * ├───┤
92
+ * │ 1
93
+ * │ 2 │
94
+ * │ 3 │
95
+ * └───┘
96
+ * >>> df.select($df.col("val").argMin().alias("min_idx"))
97
+ * shape: (1, 1)
98
+ * ┌─────────┐
99
+ * │ min_idx │
100
+ * ├─────────┤
101
+ * │ 0 │
102
+ * └─────────┘
67
103
  */
68
- any_null(): this;
104
+ argMin(): this;
69
105
  /**
70
106
  * Aggregation: Computes the arithmetic mean of the group.
71
107
  * @returns ColumnExpression
72
108
  * @example
73
- * >>> const df = $df.data({ group: ["A", "A"], val: [10, 20] })
74
- * >>> df.group_by("group").agg($df.col("val").avg().alias("mean"))
75
- * shape: (1, 2)
109
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
110
+ * >>> df
111
+ * shape: (3, 2)
112
+ * ┌───────┬─────┐
113
+ * │ group │ val │
114
+ * ├───────┼─────┤
115
+ * │ A │ 10 │
116
+ * │ A │ 20 │
117
+ * │ B │ 30 │
118
+ * └───────┴─────┘
119
+ * >>> df.groupBy("group").agg($df.col("val").avg().alias("mean"))
120
+ * shape: (2, 2)
76
121
  * ┌───────┬──────┐
77
122
  * │ group │ mean │
78
123
  * ├───────┼──────┤
79
- * │ "A" │ 15 │
124
+ * │ A │ 15 │
125
+ * │ B │ 30 │
80
126
  * └───────┴──────┘
81
127
  */
82
128
  avg(): this;
129
+ /**
130
+ * Aggregation: Computes bitwise AND across all elements in the group.
131
+ * @returns ColumnExpression
132
+ * @example
133
+ * >>> const df = $df.data({ a: [1, 2, 3] })
134
+ * >>> df
135
+ * shape: (3, 1)
136
+ * ┌───┐
137
+ * │ a │
138
+ * ├───┤
139
+ * │ 1 │
140
+ * │ 2 │
141
+ * │ 3 │
142
+ * └───┘
143
+ * >>> df.select($df.col("a").bitwiseAnd().alias("res"))
144
+ * shape: (1, 1)
145
+ * ┌─────┐
146
+ * │ res │
147
+ * ├─────┤
148
+ * │ 0 │
149
+ * └─────┘
150
+ */
151
+ bitwiseAnd(): this;
152
+ /**
153
+ * Aggregation: Computes bitwise OR across all elements in the group.
154
+ * @returns ColumnExpression
155
+ * @example
156
+ * >>> const df = $df.data({ a: [1, 2, 3] })
157
+ * >>> df
158
+ * shape: (3, 1)
159
+ * ┌───┐
160
+ * │ a │
161
+ * ├───┤
162
+ * │ 1 │
163
+ * │ 2 │
164
+ * │ 3 │
165
+ * └───┘
166
+ * >>> df.select($df.col("a").bitwiseOr().alias("res"))
167
+ * shape: (1, 1)
168
+ * ┌─────┐
169
+ * │ res │
170
+ * ├─────┤
171
+ * │ 3 │
172
+ * └─────┘
173
+ */
174
+ bitwiseOr(): this;
175
+ /**
176
+ * Aggregation: Computes bitwise XOR across all elements in the group.
177
+ * @returns ColumnExpression
178
+ * @example
179
+ * >>> const df = $df.data({ a: [1, 2, 3] })
180
+ * >>> df
181
+ * shape: (3, 1)
182
+ * ┌───┐
183
+ * │ a │
184
+ * ├───┤
185
+ * │ 1 │
186
+ * │ 2 │
187
+ * │ 3 │
188
+ * └───┘
189
+ * >>> df.select($df.col("a").bitwiseXor().alias("res"))
190
+ * shape: (1, 1)
191
+ * ┌─────┐
192
+ * │ res │
193
+ * ├─────┤
194
+ * │ 0 │
195
+ * └─────┘
196
+ */
197
+ bitwiseXor(): this;
83
198
  /**
84
199
  * Aggregation: Computes the Pearson correlation coefficient between two columns.
85
200
  * @param other The target column expression to correlate with.
86
201
  * @returns ColumnExpression
87
202
  * @example
88
- * >>> const df = $df.data({ x: [1, 2, 3], y: [2, 4, 6] })
89
- * >>> df.select($df.col("x").corr($df.col("y")).alias("correlation"))
203
+ * >>> const df = $df.data({ a: [1, 2, 3], b: [10, 20, 30] })
204
+ * >>> df
205
+ * shape: (3, 2)
206
+ * ┌───┬────┐
207
+ * │ a │ b │
208
+ * ├───┼────┤
209
+ * │ 1 │ 10 │
210
+ * │ 2 │ 20 │
211
+ * │ 3 │ 30 │
212
+ * └───┴────┘
213
+ * >>> df.select($df.col("a").corr($df.col("b")).alias("correlation"))
90
214
  * shape: (1, 1)
91
215
  * ┌─────────────┐
92
216
  * │ correlation │
@@ -100,13 +224,23 @@ export declare class AggregationExpr extends ExprBase {
100
224
  * @param options Config flags including whether to count null values.
101
225
  * @returns ColumnExpression
102
226
  * @example
103
- * >>> const df = $df.data({ group: ["A", "A"], val: [10, null] })
104
- * >>> df.group_by("group").agg($df.col("val").count().alias("cnt"))
105
- * shape: (1, 2)
227
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
228
+ * >>> df
229
+ * shape: (3, 2)
230
+ * ┌───────┬─────┐
231
+ * │ group │ val │
232
+ * ├───────┼─────┤
233
+ * │ A │ 10 │
234
+ * │ A │ 20 │
235
+ * │ B │ 30 │
236
+ * └───────┴─────┘
237
+ * >>> df.groupBy("group").agg($df.col("val").count().alias("cnt"))
238
+ * shape: (2, 2)
106
239
  * ┌───────┬─────┐
107
240
  * │ group │ cnt │
108
241
  * ├───────┼─────┤
109
- * │ "A" 1
242
+ * │ A 2
243
+ * │ B │ 1 │
110
244
  * └───────┴─────┘
111
245
  */
112
246
  count(options?: {
@@ -117,13 +251,22 @@ export declare class AggregationExpr extends ExprBase {
117
251
  * @param other The target column expression to compute covariance with.
118
252
  * @returns ColumnExpression
119
253
  * @example
120
- * >>> const df = $df.data({ x: [1, 2, 3], y: [2, 4, 6] })
121
- * >>> df.select($df.col("x").cov($df.col("y")).alias("covariance"))
254
+ * >>> const df = $df.data({ a: [1, 2, 3], b: [10, 20, 30] })
255
+ * >>> df
256
+ * shape: (3, 2)
257
+ * ┌───┬────┐
258
+ * │ a │ b │
259
+ * ├───┼────┤
260
+ * │ 1 │ 10 │
261
+ * │ 2 │ 20 │
262
+ * │ 3 │ 30 │
263
+ * └───┴────┘
264
+ * >>> df.select($df.col("a").cov($df.col("b")).alias("covariance"))
122
265
  * shape: (1, 1)
123
266
  * ┌────────────┐
124
267
  * │ covariance │
125
268
  * ├────────────┤
126
- * │ 2
269
+ * │ 10
127
270
  * └────────────┘
128
271
  */
129
272
  cov(other: any): this;
@@ -132,55 +275,165 @@ export declare class AggregationExpr extends ExprBase {
132
275
  * @param other The other column expression to compute the dot product with.
133
276
  * @returns ColumnExpression
134
277
  * @example
135
- * >>> const df = $df.data({ x: [1, 2, 3], y: [2, 3, 4] })
136
- * >>> df.select($df.col("x").dot($df.col("y")).alias("dot_product"))
278
+ * >>> const df = $df.data({ a: [1, 2, 3], b: [10, 20, 30] })
279
+ * >>> df
280
+ * shape: (3, 2)
281
+ * ┌───┬────┐
282
+ * │ a │ b │
283
+ * ├───┼────┤
284
+ * │ 1 │ 10 │
285
+ * │ 2 │ 20 │
286
+ * │ 3 │ 30 │
287
+ * └───┴────┘
288
+ * >>> df.select($df.col("a").dot($df.col("b")).alias("dot_product"))
137
289
  * shape: (1, 1)
138
290
  * ┌─────────────┐
139
291
  * │ dot_product │
140
292
  * ├─────────────┤
141
- * │ 20
293
+ * │ 140
142
294
  * └─────────────┘
143
295
  */
144
296
  dot(other: any): this;
297
+ /**
298
+ * Aggregation: Computes the Shannon entropy of a column or group.
299
+ * @param options Entropy options ({ base?: number, normalize?: boolean }, default base=Math.E, normalize=true).
300
+ * @returns ColumnExpression
301
+ * @example
302
+ * >>> const df = $df.data({ a: [1, 2, 3] })
303
+ * >>> df
304
+ * shape: (3, 1)
305
+ * ┌───┐
306
+ * │ a │
307
+ * ├───┤
308
+ * │ 1 │
309
+ * │ 2 │
310
+ * │ 3 │
311
+ * └───┘
312
+ * >>> df.select($df.col("a").entropy().alias("h"))
313
+ * shape: (1, 1)
314
+ * ┌──────────┐
315
+ * │ h │
316
+ * ├──────────┤
317
+ * │ 1.386294 │
318
+ * └──────────┘
319
+ */
320
+ entropy(options?: EntropyOptions): this;
145
321
  /**
146
322
  * Aggregation: Finds the first value in the group.
147
323
  * @returns ColumnExpression
148
324
  * @example
149
- * >>> const df = $df.data({ group: ["A", "A"], val: [10, 20] })
150
- * >>> df.group_by("group").agg($df.col("val").first().alias("first_val"))
151
- * shape: (1, 2)
325
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
326
+ * >>> df
327
+ * shape: (3, 2)
328
+ * ┌───────┬─────┐
329
+ * │ group │ val │
330
+ * ├───────┼─────┤
331
+ * │ A │ 10 │
332
+ * │ A │ 20 │
333
+ * │ B │ 30 │
334
+ * └───────┴─────┘
335
+ * >>> df.groupBy("group").agg($df.col("val").first().alias("first_val"))
336
+ * shape: (2, 2)
152
337
  * ┌───────┬───────────┐
153
338
  * │ group │ first_val │
154
339
  * ├───────┼───────────┤
155
- * │ "A" │ 10 │
340
+ * │ A │ 10 │
341
+ * │ B │ 30 │
156
342
  * └───────┴───────────┘
157
343
  */
158
344
  first(): this;
345
+ /**
346
+ * Aggregation: Checks if any value in the group is null.
347
+ * @returns ColumnExpression
348
+ * @example
349
+ * >>> const df = $df.data({ a: [1, null, 3], b: [null, 2, null] })
350
+ * >>> df
351
+ * shape: (3, 2)
352
+ * ┌──────┬──────┐
353
+ * │ a │ b │
354
+ * ├──────┼──────┤
355
+ * │ 1 │ null │
356
+ * │ null │ 2 │
357
+ * │ 3 │ null │
358
+ * └──────┴──────┘
359
+ * >>> df.select($df.col("a").hasNulls().alias("has_nulls"))
360
+ * shape: (1, 1)
361
+ * ┌───────────┐
362
+ * │ has_nulls │
363
+ * ├───────────┤
364
+ * │ true │
365
+ * └───────────┘
366
+ */
367
+ hasNulls(): this;
159
368
  /**
160
369
  * Aggregation: Combines all values in the group into a single array/list cell.
161
370
  * @returns ColumnExpression
162
371
  * @example
163
- * >>> const df = $df.data({ group: ["A", "A"], val: [10, 20] })
164
- * >>> df.group_by("group").agg($df.col("val").implode().alias("list_val"))
165
- * shape: (1, 2)
372
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
373
+ * >>> df
374
+ * shape: (3, 2)
375
+ * ┌───────┬─────┐
376
+ * │ group │ val │
377
+ * ├───────┼─────┤
378
+ * │ A │ 10 │
379
+ * │ A │ 20 │
380
+ * │ B │ 30 │
381
+ * └───────┴─────┘
382
+ * >>> df.groupBy("group").agg($df.col("val").implode().alias("list_val"))
383
+ * shape: (2, 2)
166
384
  * ┌───────┬──────────┐
167
385
  * │ group │ list_val │
168
386
  * ├───────┼──────────┤
169
- * │ "A" │ [10, 20] │
387
+ * │ A │ [10, 20] │
388
+ * │ B │ [30] │
170
389
  * └───────┴──────────┘
171
390
  */
172
391
  implode(): this;
392
+ /**
393
+ * Aggregation: Computes the kurtosis (peakedness/tailedness) of a numeric column.
394
+ * @param options Kurtosis calculation options ({ fisher?: boolean, bias?: boolean }, default fisher=true, bias=true).
395
+ * @returns ColumnExpression
396
+ * @example
397
+ * >>> const df = $df.data({ a: [1, 2, 3] })
398
+ * >>> df
399
+ * shape: (3, 1)
400
+ * ┌───┐
401
+ * │ a │
402
+ * ├───┤
403
+ * │ 1 │
404
+ * │ 2 │
405
+ * │ 3 │
406
+ * └───┘
407
+ * >>> df.select($df.col("a").kurtosis().alias("kurt"))
408
+ * shape: (1, 1)
409
+ * ┌───────┐
410
+ * │ kurt │
411
+ * ├───────┤
412
+ * │ -1.36 │
413
+ * └───────┘
414
+ */
415
+ kurtosis(options?: KurtosisOptions): this;
173
416
  /**
174
417
  * Aggregation: Finds the last value in the group.
175
418
  * @returns ColumnExpression
176
419
  * @example
177
- * >>> const df = $df.data({ group: ["A", "A"], val: [10, 20] })
178
- * >>> df.group_by("group").agg($df.col("val").last().alias("last_val"))
179
- * shape: (1, 2)
420
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
421
+ * >>> df
422
+ * shape: (3, 2)
423
+ * ┌───────┬─────┐
424
+ * │ group │ val │
425
+ * ├───────┼─────┤
426
+ * │ A │ 10 │
427
+ * │ A │ 20 │
428
+ * │ B │ 30 │
429
+ * └───────┴─────┘
430
+ * >>> df.groupBy("group").agg($df.col("val").last().alias("last_val"))
431
+ * shape: (2, 2)
180
432
  * ┌───────┬──────────┐
181
433
  * │ group │ last_val │
182
434
  * ├───────┼──────────┤
183
- * │ "A" │ 20 │
435
+ * │ A │ 20 │
436
+ * │ B │ 30 │
184
437
  * └───────┴──────────┘
185
438
  */
186
439
  last(): this;
@@ -188,27 +441,71 @@ export declare class AggregationExpr extends ExprBase {
188
441
  * Aggregation: Finds the maximum value in the group.
189
442
  * @returns ColumnExpression
190
443
  * @example
191
- * >>> const df = $df.data({ group: ["A", "A"], val: [10, 50] })
192
- * >>> df.group_by("group").agg($df.col("val").max().alias("max_val"))
193
- * shape: (1, 2)
444
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
445
+ * >>> df
446
+ * shape: (3, 2)
447
+ * ┌───────┬─────┐
448
+ * │ group │ val │
449
+ * ├───────┼─────┤
450
+ * │ A │ 10 │
451
+ * │ A │ 20 │
452
+ * │ B │ 30 │
453
+ * └───────┴─────┘
454
+ * >>> df.groupBy("group").agg($df.col("val").max().alias("max_val"))
455
+ * shape: (2, 2)
194
456
  * ┌───────┬─────────┐
195
457
  * │ group │ max_val │
196
458
  * ├───────┼─────────┤
197
- * │ "A" 50
459
+ * │ A 20
460
+ * │ B │ 30 │
198
461
  * └───────┴─────────┘
199
462
  */
200
463
  max(): this;
464
+ /**
465
+ * Aggregation: Finds the value in this column corresponding to the maximum value in the `by` expression.
466
+ * @param by Column or expression to order by.
467
+ * @returns ColumnExpression
468
+ * @example
469
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
470
+ * >>> df
471
+ * shape: (3, 2)
472
+ * ┌───────┬─────┐
473
+ * │ group │ val │
474
+ * ├───────┼─────┤
475
+ * │ A │ 10 │
476
+ * │ A │ 20 │
477
+ * │ B │ 30 │
478
+ * └───────┴─────┘
479
+ * >>> df.select($df.col("group").maxBy($df.col("val")).alias("top_group"))
480
+ * shape: (1, 1)
481
+ * ┌───────────┐
482
+ * │ top_group │
483
+ * ├───────────┤
484
+ * │ B │
485
+ * └───────────┘
486
+ */
487
+ maxBy(by: any): this;
201
488
  /**
202
489
  * Aggregation: Computes the arithmetic mean of elements in the group.
203
490
  * @returns ColumnExpression
204
491
  * @example
205
- * >>> const df = $df.data({ group: ["A", "A"], val: [10, 30] })
206
- * >>> df.group_by("group").agg($df.col("val").mean().alias("mean_val"))
207
- * shape: (1, 2)
492
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
493
+ * >>> df
494
+ * shape: (3, 2)
495
+ * ┌───────┬─────┐
496
+ * │ group │ val │
497
+ * ├───────┼─────┤
498
+ * │ A │ 10 │
499
+ * │ A │ 20 │
500
+ * │ B │ 30 │
501
+ * └───────┴─────┘
502
+ * >>> df.groupBy("group").agg($df.col("val").mean().alias("mean_val"))
503
+ * shape: (2, 2)
208
504
  * ┌───────┬──────────┐
209
505
  * │ group │ mean_val │
210
506
  * ├───────┼──────────┤
211
- * │ "A" 20
507
+ * │ A 15
508
+ * │ B │ 30 │
212
509
  * └───────┴──────────┘
213
510
  */
214
511
  mean(): this;
@@ -216,13 +513,23 @@ export declare class AggregationExpr extends ExprBase {
216
513
  * Aggregation: Computes the 50th percentile median.
217
514
  * @returns ColumnExpression
218
515
  * @example
219
- * >>> const df = $df.data({ group: ["A", "A", "A"], val: [10, 50, 20] })
220
- * >>> df.group_by("group").agg($df.col("val").median().alias("med"))
221
- * shape: (1, 2)
516
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
517
+ * >>> df
518
+ * shape: (3, 2)
519
+ * ┌───────┬─────┐
520
+ * │ group │ val │
521
+ * ├───────┼─────┤
522
+ * │ A │ 10 │
523
+ * │ A │ 20 │
524
+ * │ B │ 30 │
525
+ * └───────┴─────┘
526
+ * >>> df.groupBy("group").agg($df.col("val").median().alias("med"))
527
+ * shape: (2, 2)
222
528
  * ┌───────┬─────┐
223
529
  * │ group │ med │
224
530
  * ├───────┼─────┤
225
- * │ "A" 20
531
+ * │ A 15
532
+ * │ B │ 30 │
226
533
  * └───────┴─────┘
227
534
  */
228
535
  median(): this;
@@ -230,28 +537,71 @@ export declare class AggregationExpr extends ExprBase {
230
537
  * Aggregation: Finds the minimum value in the group.
231
538
  * @returns ColumnExpression
232
539
  * @example
233
- * >>> const df = $df.data({ group: ["A", "A"], val: [10, 50] })
234
- * >>> df.group_by("group").agg($df.col("val").min().alias("min_val"))
235
- * shape: (1, 2)
540
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
541
+ * >>> df
542
+ * shape: (3, 2)
543
+ * ┌───────┬─────┐
544
+ * │ group │ val │
545
+ * ├───────┼─────┤
546
+ * │ A │ 10 │
547
+ * │ A │ 20 │
548
+ * │ B │ 30 │
549
+ * └───────┴─────┘
550
+ * >>> df.groupBy("group").agg($df.col("val").min().alias("min_val"))
551
+ * shape: (2, 2)
236
552
  * ┌───────┬─────────┐
237
553
  * │ group │ min_val │
238
554
  * ├───────┼─────────┤
239
- * │ "A" │ 10 │
555
+ * │ A │ 10 │
556
+ * │ B │ 30 │
240
557
  * └───────┴─────────┘
241
558
  */
242
559
  min(): this;
560
+ /**
561
+ * Aggregation: Finds the value in this column corresponding to the minimum value in the `by` expression.
562
+ * @param by Column or expression to order by.
563
+ * @returns ColumnExpression
564
+ * @example
565
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
566
+ * >>> df
567
+ * shape: (3, 2)
568
+ * ┌───────┬─────┐
569
+ * │ group │ val │
570
+ * ├───────┼─────┤
571
+ * │ A │ 10 │
572
+ * │ A │ 20 │
573
+ * │ B │ 30 │
574
+ * └───────┴─────┘
575
+ * >>> df.select($df.col("group").minBy($df.col("val")).alias("lowest_group"))
576
+ * shape: (1, 1)
577
+ * ┌──────────────┐
578
+ * │ lowest_group │
579
+ * ├──────────────┤
580
+ * │ A │
581
+ * └──────────────┘
582
+ */
583
+ minBy(by: any): this;
243
584
  /**
244
585
  * Aggregation: Finds the statistical mode (most frequent value).
245
586
  * @returns ColumnExpression
246
587
  * @example
247
- * >>> const df = $df.data({ group: ["A", "A", "A"], val: [5, 5, 10] })
248
- * >>> df.group_by("group").agg($df.col("val").mode().alias("mode_val"))
249
- * shape: (1, 2)
250
- * ┌───────┬──────────┐
251
- * │ group │ mode_val
252
- * ├───────┼──────────┤
253
- * │ "A" 5
254
- * └───────┴──────────┘
588
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
589
+ * >>> df
590
+ * shape: (3, 2)
591
+ * ┌───────┬─────┐
592
+ * │ group │ val
593
+ * ├───────┼─────┤
594
+ * │ A 10
595
+ * │ A │ 20 │
596
+ * │ B │ 30 │
597
+ * └───────┴─────┘
598
+ * >>> df.select($df.col("group").mode().alias("mode_group"))
599
+ * shape: (1, 1)
600
+ * ┌────────────┐
601
+ * │ mode_group │
602
+ * ├────────────┤
603
+ * │ ["A"] │
604
+ * └────────────┘
255
605
  */
256
606
  mode(): this;
257
607
  /**
@@ -259,52 +609,182 @@ export declare class AggregationExpr extends ExprBase {
259
609
  * @param options Uniqueness options.
260
610
  * @returns ColumnExpression
261
611
  * @example
262
- * >>> const df = $df.data({ group: ["A", "A", "A"], val: [5, 5, 10] })
263
- * >>> df.group_by("group").agg($df.col("val").n_unique().alias("unique_cnt"))
264
- * shape: (1, 2)
265
- * ┌───────┬────────────┐
266
- * │ group │ unique_cnt
267
- * ├───────┼────────────┤
268
- * │ "A" 2
269
- * └───────┴────────────┘
612
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
613
+ * >>> df
614
+ * shape: (3, 2)
615
+ * ┌───────┬─────┐
616
+ * │ group │ val
617
+ * ├───────┼─────┤
618
+ * │ A 10
619
+ * │ A │ 20 │
620
+ * │ B │ 30 │
621
+ * └───────┴─────┘
622
+ * >>> df.select($df.col("group").nUnique().alias("unique_cnt"))
623
+ * shape: (1, 1)
624
+ * ┌────────────┐
625
+ * │ unique_cnt │
626
+ * ├────────────┤
627
+ * │ 2 │
628
+ * └────────────┘
629
+ */
630
+ nUnique(options?: UniqueArrayStatsOptions): this;
631
+ /**
632
+ * Aggregation: Finds the maximum value in the group, taking NaN values into account (NaN propagates).
633
+ * @returns ColumnExpression
634
+ * @example
635
+ * >>> const df = $df.data({ a: [1, 2, 3] })
636
+ * >>> df
637
+ * shape: (3, 1)
638
+ * ┌───┐
639
+ * │ a │
640
+ * ├───┤
641
+ * │ 1 │
642
+ * │ 2 │
643
+ * │ 3 │
644
+ * └───┘
645
+ * >>> df.select($df.col("val").nanMax().alias("nan_max_val"))
646
+ * shape: (1, 1)
647
+ * ┌─────────────┐
648
+ * │ nan_max_val │
649
+ * ├─────────────┤
650
+ * │ 30 │
651
+ * └─────────────┘
652
+ */
653
+ nanMax(): this;
654
+ /**
655
+ * Aggregation: Finds the minimum value in the group, taking NaN values into account (NaN propagates).
656
+ * @returns ColumnExpression
657
+ * @example
658
+ * >>> const df = $df.data({ a: [1, 2, 3] })
659
+ * >>> df
660
+ * shape: (3, 1)
661
+ * ┌───┐
662
+ * │ a │
663
+ * ├───┤
664
+ * │ 1 │
665
+ * │ 2 │
666
+ * │ 3 │
667
+ * └───┘
668
+ * >>> df.select($df.col("val").nanMin().alias("nan_min_val"))
669
+ * shape: (1, 1)
670
+ * ┌─────────────┐
671
+ * │ nan_min_val │
672
+ * ├─────────────┤
673
+ * │ 10 │
674
+ * └─────────────┘
270
675
  */
271
- n_unique(options?: UniqueArrayStatsOptions): this;
676
+ nanMin(): this;
272
677
  /**
273
678
  * Aggregation: Counts the number of null or missing records.
274
679
  * @returns ColumnExpression
275
680
  * @example
276
- * >>> const df = $df.data({ group: ["A", "A"], val: [10, null] })
277
- * >>> df.group_by("group").agg($df.col("val").null_count().alias("nulls"))
278
- * shape: (1, 2)
279
- * ┌───────┬───────┐
280
- * │ group nulls
281
- * ├───────┼───────┤
282
- * │ "A" 1
283
- * └───────┴───────┘
681
+ * >>> const df = $df.data({ a: [1, null, 3], b: [null, 2, null] })
682
+ * >>> df
683
+ * shape: (3, 2)
684
+ * ┌──────┬──────┐
685
+ * │ a b
686
+ * ├──────┼──────┤
687
+ * │ 1 null
688
+ * │ null │ 2 │
689
+ * │ 3 │ null │
690
+ * └──────┴──────┘
691
+ * >>> df.select($df.col("a").nullCount().alias("nulls"))
692
+ * shape: (1, 1)
693
+ * ┌───────┐
694
+ * │ nulls │
695
+ * ├───────┤
696
+ * │ 1 │
697
+ * └───────┘
284
698
  */
285
- null_count(): this;
699
+ nullCount(): this;
286
700
  /**
287
701
  * Aggregation: Computes the specific quantile values (0.0 to 1.0).
288
702
  * @param q The quantile parameter value between 0.0 and 1.0.
289
703
  * @returns ColumnExpression
290
704
  * @example
291
- * >>> const df = $df.data({ val: [10, 20, 30, 40] })
292
- * >>> df.select($df.col("val").quantile(0.75).alias("q75"))
705
+ * >>> const df = $df.data({ a: [1, 2, 3] })
706
+ * >>> df
707
+ * shape: (3, 1)
708
+ * ┌───┐
709
+ * │ a │
710
+ * ├───┤
711
+ * │ 1 │
712
+ * │ 2 │
713
+ * │ 3 │
714
+ * └───┘
715
+ * >>> df.select($df.col("a").quantile(0.75).alias("q75"))
293
716
  * shape: (1, 1)
294
- * ┌─────┐
295
- * │ q75
296
- * ├─────┤
297
- * │ 32.5
298
- * └─────┘
717
+ * ┌──────┐
718
+ * │ q75
719
+ * ├──────┤
720
+ * │ 3.25
721
+ * └──────┘
299
722
  */
300
723
  quantile(q: number): this;
724
+ /**
725
+ * Aggregation: Computes the product of all elements in the group.
726
+ * @returns ColumnExpression
727
+ * @example
728
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
729
+ * >>> df
730
+ * shape: (3, 2)
731
+ * ┌───────┬─────┐
732
+ * │ group │ val │
733
+ * ├───────┼─────┤
734
+ * │ A │ 10 │
735
+ * │ A │ 20 │
736
+ * │ B │ 30 │
737
+ * └───────┴─────┘
738
+ * >>> df.groupBy("group").agg($df.col("val").product().alias("p"))
739
+ * shape: (2, 2)
740
+ * ┌───────┬─────┐
741
+ * │ group │ p │
742
+ * ├───────┼─────┤
743
+ * │ A │ 200 │
744
+ * │ B │ 30 │
745
+ * └───────┴─────┘
746
+ */
747
+ product(): this;
748
+ /**
749
+ * Aggregation: Computes the sample skewness as the Fisher-Pearson coefficient of skewness.
750
+ * @param options Skew calculation options ({ bias?: boolean }, default bias=true).
751
+ * @returns ColumnExpression
752
+ * @example
753
+ * >>> const df = $df.data({ a: [1, 2, 3] })
754
+ * >>> df
755
+ * shape: (3, 1)
756
+ * ┌───┐
757
+ * │ a │
758
+ * ├───┤
759
+ * │ 1 │
760
+ * │ 2 │
761
+ * │ 3 │
762
+ * └───┘
763
+ * >>> df.select($df.col("a").skew().alias("skewness"))
764
+ * shape: (1, 1)
765
+ * ┌──────────┐
766
+ * │ skewness │
767
+ * ├──────────┤
768
+ * │ 0 │
769
+ * └──────────┘
770
+ */
771
+ skew(options?: SkewOptions): this;
301
772
  /**
302
773
  * Aggregation: Computes the Spearman rank correlation coefficient.
303
774
  * @param other The other column expression to correlate with.
304
775
  * @returns ColumnExpression
305
776
  * @example
306
- * >>> const df = $df.data({ x: [1, 2, 3], y: [5, 6, 7] })
307
- * >>> df.select($df.col("x").spearman_corr($df.col("y")).alias("spearman"))
777
+ * >>> const df = $df.data({ a: [1, 2, 3], b: [10, 20, 30] })
778
+ * >>> df
779
+ * shape: (3, 2)
780
+ * ┌───┬────┐
781
+ * │ a │ b │
782
+ * ├───┼────┤
783
+ * │ 1 │ 10 │
784
+ * │ 2 │ 20 │
785
+ * │ 3 │ 30 │
786
+ * └───┴────┘
787
+ * >>> df.select($df.col("a").spearmanCorr($df.col("b")).alias("spearman"))
308
788
  * shape: (1, 1)
309
789
  * ┌──────────┐
310
790
  * │ spearman │
@@ -312,48 +792,99 @@ export declare class AggregationExpr extends ExprBase {
312
792
  * │ 1 │
313
793
  * └──────────┘
314
794
  */
315
- spearman_corr(other: any): this;
795
+ spearmanCorr(other: any): this;
316
796
  /**
317
797
  * Aggregation: Computes sample standard deviation.
318
798
  * @returns ColumnExpression
319
799
  * @example
320
- * >>> const df = $df.data({ group: ["A", "A", "A"], val: [10, 20, 30] })
321
- * >>> df.group_by("group").agg($df.col("val").std().alias("std_dev"))
322
- * shape: (1, 2)
323
- * ┌───────┬─────────┐
324
- * │ group std_dev │
325
- * ├───────┼─────────┤
326
- * │ "A" │ 10
327
- * └───────┴─────────┘
800
+ * >>> const df = $df.data({ a: [1, 2, 3] })
801
+ * >>> df
802
+ * shape: (3, 1)
803
+ * ┌───┐
804
+ * │ a
805
+ * ├───┤
806
+ * │ 1
807
+ * │ 2 │
808
+ * │ 3 │
809
+ * └───┘
810
+ * >>> df.select($df.col("val").std().alias("std_dev"))
811
+ * shape: (1, 1)
812
+ * ┌─────────┐
813
+ * │ std_dev │
814
+ * ├─────────┤
815
+ * │ 10 │
816
+ * └─────────┘
328
817
  */
329
818
  std(): this;
330
819
  /**
331
820
  * Aggregation: Computes the sum of elements in the group.
332
821
  * @returns ColumnExpression
333
822
  * @example
334
- * >>> const df = $df.data({ group: ["A", "A"], val: [10, 20] })
335
- * >>> df.group_by("group").agg($df.col("val").sum().alias("total"))
336
- * shape: (1, 2)
823
+ * >>> const df = $df.data({ group: ["A", "A", "B"], val: [10, 20, 30] })
824
+ * >>> df
825
+ * shape: (3, 2)
826
+ * ┌───────┬─────┐
827
+ * │ group │ val │
828
+ * ├───────┼─────┤
829
+ * │ A │ 10 │
830
+ * │ A │ 20 │
831
+ * │ B │ 30 │
832
+ * └───────┴─────┘
833
+ * >>> df.groupBy("group").agg($df.col("val").sum().alias("total"))
834
+ * shape: (2, 2)
337
835
  * ┌───────┬───────┐
338
836
  * │ group │ total │
339
837
  * ├───────┼───────┤
340
- * │ "A" │ 30 │
838
+ * │ A │ 30 │
839
+ * │ B │ 30 │
341
840
  * └───────┴───────┘
342
841
  */
343
842
  sum(): this;
843
+ /**
844
+ * Aggregation: Computes sample variance.
845
+ * @returns ColumnExpression
846
+ * @example
847
+ * >>> const df = $df.data({ a: [1, 2, 3] })
848
+ * >>> df
849
+ * shape: (3, 1)
850
+ * ┌───┐
851
+ * │ a │
852
+ * ├───┤
853
+ * │ 1 │
854
+ * │ 2 │
855
+ * │ 3 │
856
+ * └───┘
857
+ * >>> df.select($df.col("val").variance().alias("v"))
858
+ * shape: (1, 1)
859
+ * ┌─────┐
860
+ * │ v │
861
+ * ├─────┤
862
+ * │ 100 │
863
+ * └─────┘
864
+ */
865
+ variance(): this;
344
866
  /**
345
867
  * Aggregation: Computes weighted average.
346
868
  * @param weights The weight values or column expression.
347
869
  * @returns ColumnExpression
348
870
  * @example
349
- * >>> const df = $df.data({ val: [10, 20], weight: [1, 3] })
350
- * >>> df.select($df.col("val").w_avg($df.col("weight")).alias("w_mean"))
871
+ * >>> const df = $df.data({ a: [1, 2, 3], b: [10, 20, 30] })
872
+ * >>> df
873
+ * shape: (3, 2)
874
+ * ┌───┬────┐
875
+ * │ a │ b │
876
+ * ├───┼────┤
877
+ * │ 1 │ 10 │
878
+ * │ 2 │ 20 │
879
+ * │ 3 │ 30 │
880
+ * └───┴────┘
881
+ * >>> df.select($df.col("a").wAvg($df.col("b")).alias("w_mean"))
351
882
  * shape: (1, 1)
352
- * ┌────────┐
353
- * │ w_mean
354
- * ├────────┤
355
- * │ 17.5
356
- * └────────┘
883
+ * ┌──────────┐
884
+ * │ w_mean
885
+ * ├──────────┤
886
+ * │ 2.333333
887
+ * └──────────┘
357
888
  */
358
- w_avg(weights: any): this;
889
+ wAvg(weights: any): this;
359
890
  }