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