@ohos-ports/nodejs-polars 0.23.4-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +2135 -0
- package/bin/dataframe.js +783 -0
- package/bin/datatypes/conversion.d.ts +2 -0
- package/bin/datatypes/conversion.js +2 -0
- package/bin/datatypes/datatype.d.ts +285 -0
- package/bin/datatypes/datatype.js +430 -0
- package/bin/datatypes/field.d.ts +26 -0
- package/bin/datatypes/field.js +36 -0
- package/bin/datatypes/index.d.ts +43 -0
- package/bin/datatypes/index.js +120 -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 +212 -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 +256 -0
- package/bin/index.js +267 -0
- package/bin/internals/construction.d.ts +7 -0
- package/bin/internals/construction.js +256 -0
- package/bin/internals/polars_internal.d.ts +2 -0
- package/bin/internals/polars_internal.js +7 -0
- package/bin/io.d.ts +433 -0
- package/bin/io.js +344 -0
- package/bin/lazy/dataframe.d.ts +785 -0
- package/bin/lazy/dataframe.js +427 -0
- package/bin/lazy/expr/datetime.d.ts +8 -0
- package/bin/lazy/expr/datetime.js +27 -0
- package/bin/lazy/expr/index.d.ts +1152 -0
- package/bin/lazy/expr/index.js +632 -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 +612 -0
- package/bin/lazy/functions.js +687 -0
- package/bin/lazy/groupby.d.ts +29 -0
- package/bin/lazy/groupby.js +30 -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 +34 -0
- package/bin/series/index.d.ts +1135 -0
- package/bin/series/index.js +700 -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 +1458 -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 +287 -0
- package/bin/types.js +2 -0
- package/bin/utils.d.ts +38 -0
- package/bin/utils.js +69 -0
- package/package.json +45 -0
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
import { DataFrame } from "../dataframe";
|
|
2
|
+
import { DataType } from "../datatypes";
|
|
3
|
+
import { Series } from "../series";
|
|
4
|
+
import { type ExprOrString } from "../utils";
|
|
5
|
+
import { Expr } from "./expr";
|
|
6
|
+
/**
|
|
7
|
+
* __A column in a DataFrame.__
|
|
8
|
+
* Can be used to select:
|
|
9
|
+
* * a single column by name
|
|
10
|
+
* * all columns by using a wildcard `"*"`
|
|
11
|
+
* * column by regular expression if the regex starts with `^` and ends with `$`
|
|
12
|
+
* @param col
|
|
13
|
+
* @example
|
|
14
|
+
* ```
|
|
15
|
+
* > df = pl.DataFrame({
|
|
16
|
+
* > "ham": [1, 2, 3],
|
|
17
|
+
* > "hamburger": [11, 22, 33],
|
|
18
|
+
* > "foo": [3, 2, 1]})
|
|
19
|
+
* > df.select(col("foo"))
|
|
20
|
+
* shape: (3, 1)
|
|
21
|
+
* ╭─────╮
|
|
22
|
+
* │ foo │
|
|
23
|
+
* │ --- │
|
|
24
|
+
* │ i64 │
|
|
25
|
+
* ╞═════╡
|
|
26
|
+
* │ 3 │
|
|
27
|
+
* ├╌╌╌╌╌┤
|
|
28
|
+
* │ 2 │
|
|
29
|
+
* ├╌╌╌╌╌┤
|
|
30
|
+
* │ 1 │
|
|
31
|
+
* ╰─────╯
|
|
32
|
+
* > df.select(col("*"))
|
|
33
|
+
* shape: (3, 3)
|
|
34
|
+
* ╭─────┬───────────┬─────╮
|
|
35
|
+
* │ ham ┆ hamburger ┆ foo │
|
|
36
|
+
* │ --- ┆ --- ┆ --- │
|
|
37
|
+
* │ i64 ┆ i64 ┆ i64 │
|
|
38
|
+
* ╞═════╪═══════════╪═════╡
|
|
39
|
+
* │ 1 ┆ 11 ┆ 3 │
|
|
40
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
41
|
+
* │ 2 ┆ 22 ┆ 2 │
|
|
42
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
43
|
+
* │ 3 ┆ 33 ┆ 1 │
|
|
44
|
+
* ╰─────┴───────────┴─────╯
|
|
45
|
+
* > df.select(col("^ham.*$"))
|
|
46
|
+
* shape: (3, 2)
|
|
47
|
+
* ╭─────┬───────────╮
|
|
48
|
+
* │ ham ┆ hamburger │
|
|
49
|
+
* │ --- ┆ --- │
|
|
50
|
+
* │ i64 ┆ i64 │
|
|
51
|
+
* ╞═════╪═══════════╡
|
|
52
|
+
* │ 1 ┆ 11 │
|
|
53
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
|
|
54
|
+
* │ 2 ┆ 22 │
|
|
55
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
|
|
56
|
+
* │ 3 ┆ 33 │
|
|
57
|
+
* ╰─────┴───────────╯
|
|
58
|
+
* > df.select(col("*").exclude("ham"))
|
|
59
|
+
* shape: (3, 2)
|
|
60
|
+
* ╭───────────┬─────╮
|
|
61
|
+
* │ hamburger ┆ foo │
|
|
62
|
+
* │ --- ┆ --- │
|
|
63
|
+
* │ i64 ┆ i64 │
|
|
64
|
+
* ╞═══════════╪═════╡
|
|
65
|
+
* │ 11 ┆ 3 │
|
|
66
|
+
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
67
|
+
* │ 22 ┆ 2 │
|
|
68
|
+
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
69
|
+
* │ 33 ┆ 1 │
|
|
70
|
+
* ╰───────────┴─────╯
|
|
71
|
+
* > df.select(col(["hamburger", "foo"])
|
|
72
|
+
* shape: (3, 2)
|
|
73
|
+
* ╭───────────┬─────╮
|
|
74
|
+
* │ hamburger ┆ foo │
|
|
75
|
+
* │ --- ┆ --- │
|
|
76
|
+
* │ i64 ┆ i64 │
|
|
77
|
+
* ╞═══════════╪═════╡
|
|
78
|
+
* │ 11 ┆ 3 │
|
|
79
|
+
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
80
|
+
* │ 22 ┆ 2 │
|
|
81
|
+
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
82
|
+
* │ 33 ┆ 1 │
|
|
83
|
+
* ╰───────────┴─────╯
|
|
84
|
+
* > df.select(col(pl.Series(["hamburger", "foo"]))
|
|
85
|
+
* shape: (3, 2)
|
|
86
|
+
* ╭───────────┬─────╮
|
|
87
|
+
* │ hamburger ┆ foo │
|
|
88
|
+
* │ --- ┆ --- │
|
|
89
|
+
* │ i64 ┆ i64 │
|
|
90
|
+
* ╞═══════════╪═════╡
|
|
91
|
+
* │ 11 ┆ 3 │
|
|
92
|
+
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
93
|
+
* │ 22 ┆ 2 │
|
|
94
|
+
* ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
95
|
+
* │ 33 ┆ 1 │
|
|
96
|
+
* ╰───────────┴─────╯
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function col(col: string | string[] | Series | DataType): Expr;
|
|
100
|
+
export declare function cols(col: string | string[]): Expr;
|
|
101
|
+
export declare function cols(col: string, ...cols2: string[]): Expr;
|
|
102
|
+
/**
|
|
103
|
+
* Select nth column index in a DataFrame.
|
|
104
|
+
* @param n - Column index to select, starting at 0.
|
|
105
|
+
* @example
|
|
106
|
+
* ```
|
|
107
|
+
* > df = pl.DataFrame({
|
|
108
|
+
* > "ham": [1, 2, 3],
|
|
109
|
+
* > "hamburger": [11, 22, 33],
|
|
110
|
+
* > "foo": [3, 2, 1]})
|
|
111
|
+
* > df.select(nth(2))
|
|
112
|
+
* shape: (3, 1)
|
|
113
|
+
* ╭─────╮
|
|
114
|
+
* │ foo │
|
|
115
|
+
* │ --- │
|
|
116
|
+
* │ i64 │
|
|
117
|
+
* ╞═════╡
|
|
118
|
+
* │ 3 │
|
|
119
|
+
* ├╌╌╌╌╌┤
|
|
120
|
+
* │ 2 │
|
|
121
|
+
* ├╌╌╌╌╌┤
|
|
122
|
+
* │ 1 │
|
|
123
|
+
* ╰─────╯
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function nth(n: number): Expr;
|
|
127
|
+
export declare function lit(value: any): Expr;
|
|
128
|
+
/**
|
|
129
|
+
* Generate a range of integers.
|
|
130
|
+
*
|
|
131
|
+
* This can be used in a `select`, `with_column` etc.
|
|
132
|
+
* Be sure that the range size is equal to the DataFrame you are collecting.
|
|
133
|
+
* @param start - Start of the range (inclusive). Defaults to 0.
|
|
134
|
+
* @param end - End of the range (exclusive). If set to `None` (default), the value of `start` is used and `start` is set to `0`.
|
|
135
|
+
* @param step - Step size of the range.
|
|
136
|
+
* @param dtype - Data type of the range.
|
|
137
|
+
* @param eager - Evaluate immediately and return a `Series`. If set to `False` (default), return an expression instead.
|
|
138
|
+
* @returns Expr or Series Column of integer data type `dtype`.
|
|
139
|
+
* @see {@link intRanges}
|
|
140
|
+
* @example
|
|
141
|
+
* ```
|
|
142
|
+
* > df.lazy()
|
|
143
|
+
* > .filter(pl.col("foo").lt(pl.intRange(0, 100)))
|
|
144
|
+
* > .collect()
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
147
|
+
*
|
|
148
|
+
* Generate an index column by using `intRange` in conjunction with :func:`len`.
|
|
149
|
+
* ```
|
|
150
|
+
* df = pl.DataFrame({"a": [1, 3, 5], "b": [2, 4, 6]})
|
|
151
|
+
df.select(
|
|
152
|
+
... pl.intRange(pl.len()).alias("index"),
|
|
153
|
+
... pl.all(),
|
|
154
|
+
... )
|
|
155
|
+
shape: (3, 3)
|
|
156
|
+
┌───────┬─────┬─────┐
|
|
157
|
+
│ index ┆ a ┆ b │
|
|
158
|
+
│ --- ┆ --- ┆ --- │
|
|
159
|
+
│ u32 ┆ i64 ┆ i64 │
|
|
160
|
+
╞═══════╪═════╪═════╡
|
|
161
|
+
│ 0 ┆ 1 ┆ 2 │
|
|
162
|
+
│ 1 ┆ 3 ┆ 4 │
|
|
163
|
+
│ 2 ┆ 5 ┆ 6 │
|
|
164
|
+
└───────┴─────┴─────┘
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare function intRange(start: number | Expr, end?: number | Expr, step?: number | Expr, dtype?: DataType, eager?: false): Expr;
|
|
168
|
+
export declare function intRange<DT extends DataType = DataType.Int64>(opts: {
|
|
169
|
+
start: number | Expr;
|
|
170
|
+
end: number | Expr;
|
|
171
|
+
step?: number | Expr;
|
|
172
|
+
dtype?: DT;
|
|
173
|
+
eager: true;
|
|
174
|
+
}): Series<DT>;
|
|
175
|
+
export declare function intRange(opts: {
|
|
176
|
+
start: number | Expr;
|
|
177
|
+
end: number | Expr;
|
|
178
|
+
step?: number | Expr;
|
|
179
|
+
dtype?: DataType;
|
|
180
|
+
eager?: false;
|
|
181
|
+
}): Expr;
|
|
182
|
+
export declare function intRange<DT extends DataType = DataType.Int64>(opts: {
|
|
183
|
+
start: number | Expr;
|
|
184
|
+
end: number | Expr;
|
|
185
|
+
step?: number | Expr;
|
|
186
|
+
dtype?: DT;
|
|
187
|
+
eager?: boolean;
|
|
188
|
+
}): Expr | Series<DT>;
|
|
189
|
+
export declare function intRange<DT extends DataType = DataType.Int64>(start: number | Expr, end?: number | Expr, step?: number | Expr, dtype?: DT, eager?: true): Series<DT>;
|
|
190
|
+
/***
|
|
191
|
+
* Generate a range of integers for each row of the input columns.
|
|
192
|
+
* @param start - Start of the range (inclusive). Defaults to 0.
|
|
193
|
+
* @param end - End of the range (exclusive). If set to `None` (default), the value of `start` is used and `start` is set to `0`.
|
|
194
|
+
* @param step - Step size of the range.
|
|
195
|
+
* @param dtype - Integer data type of the ranges. Defaults to `Int64`.
|
|
196
|
+
* @param eager - Evaluate immediately and return a ``Series``. If set to ``False`` (default), return an expression instead.
|
|
197
|
+
* @return - Expr or Series Column of data type `List(dtype)`.
|
|
198
|
+
* @see {@link intRange}
|
|
199
|
+
* @example
|
|
200
|
+
* ```
|
|
201
|
+
* const df = pl.DataFrame({"a": [1, 2], "b": [3, 4]})
|
|
202
|
+
* const result = df.select(pl.intRanges("a", "b"));
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
export declare function intRanges(start: any, end: any, step?: number, dtype?: DataType, eager?: false): Expr;
|
|
206
|
+
export declare function intRanges(start: any, end: any, step?: number, dtype?: DataType, eager?: true): Series;
|
|
207
|
+
/** Alias for `pl.col("*")` */
|
|
208
|
+
export declare function all(): Expr;
|
|
209
|
+
/**
|
|
210
|
+
* Return the row indices that would sort the columns.
|
|
211
|
+
* @param exprs Column(s) to arg sort by. Accepts expression input.
|
|
212
|
+
* @param descending Sort in descending order. When sorting by multiple columns, can be specified per column by passing a sequence of booleans.
|
|
213
|
+
* @example
|
|
214
|
+
* ```
|
|
215
|
+
* const df = pl.DataFrame({"a": [0, 1, 1, 0], "b": [3, 2, 3, 2],});
|
|
216
|
+
* df.select(pl.argSortBy(pl.col("a")));
|
|
217
|
+
* shape: (4, 1)
|
|
218
|
+
* ┌─────┐
|
|
219
|
+
* │ a │
|
|
220
|
+
* │ --- │
|
|
221
|
+
* │ u32 │
|
|
222
|
+
* ╞═════╡
|
|
223
|
+
* │ 0 │
|
|
224
|
+
* │ 3 │
|
|
225
|
+
* │ 1 │
|
|
226
|
+
* │ 2 │
|
|
227
|
+
* └─────┘
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
export declare function argSortBy(exprs: Expr[] | string[], descending?: boolean | boolean[]): Expr;
|
|
231
|
+
/** Alias for mean. @see {@link mean} */
|
|
232
|
+
export declare function avg(column: string): Expr;
|
|
233
|
+
export declare function avg(column: Series): number;
|
|
234
|
+
/**
|
|
235
|
+
* Concat the arrays in a Series dtype List in linear time.
|
|
236
|
+
* @param exprs Columns to concat into a List Series
|
|
237
|
+
*/
|
|
238
|
+
export declare function concatList(exprs: ExprOrString[]): Expr;
|
|
239
|
+
export declare function concatList(expr: ExprOrString, ...exprs: ExprOrString[]): Expr;
|
|
240
|
+
export declare function concatList(expr: ExprOrString, expr2: ExprOrString, ...exprs: ExprOrString[]): Expr;
|
|
241
|
+
/** Concat Utf8 Series in linear time. Non utf8 columns are cast to utf8. */
|
|
242
|
+
export declare function concatString(opts: {
|
|
243
|
+
exprs: ExprOrString[];
|
|
244
|
+
sep: string;
|
|
245
|
+
ignoreNulls?: boolean;
|
|
246
|
+
}): any;
|
|
247
|
+
export declare function concatString(exprs: ExprOrString[], sep?: string, ignoreNulls?: boolean): any;
|
|
248
|
+
/** Count the number of values in this column. */
|
|
249
|
+
export declare function count(column: string): Expr;
|
|
250
|
+
export declare function count(column: Series): number;
|
|
251
|
+
/** Compute the covariance between two columns/ expressions. */
|
|
252
|
+
export declare function cov(a: ExprOrString, b: ExprOrString, ddof?: number): Expr;
|
|
253
|
+
/**
|
|
254
|
+
* Exclude certain columns from a wildcard expression.
|
|
255
|
+
*
|
|
256
|
+
* Syntactic sugar for:
|
|
257
|
+
* ```
|
|
258
|
+
* > pl.col("*").exclude(columns)
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
export declare function exclude(columns: string[] | string): Expr;
|
|
262
|
+
export declare function exclude(col: string, ...cols: string[]): Expr;
|
|
263
|
+
/** Get the first value. */
|
|
264
|
+
export declare function first(): Expr;
|
|
265
|
+
export declare function first(column: string): Expr;
|
|
266
|
+
export declare function first<T>(column: Series): T;
|
|
267
|
+
/**
|
|
268
|
+
* String format utility for expressions
|
|
269
|
+
* Note: strings will be interpolated as `col(<value>)`. if you want a literal string, use `lit(<value>)`
|
|
270
|
+
* @example
|
|
271
|
+
* ```
|
|
272
|
+
* > df = pl.DataFrame({
|
|
273
|
+
* ... "a": ["a", "b", "c"],
|
|
274
|
+
* ... "b": [1, 2, 3],
|
|
275
|
+
* ... })
|
|
276
|
+
* > df.select(
|
|
277
|
+
* ... pl.format("foo_{}_bar_{}", pl.col("a"), "b").alias("fmt"),
|
|
278
|
+
* ... )
|
|
279
|
+
* shape: (3, 1)
|
|
280
|
+
* ┌─────────────┐
|
|
281
|
+
* │ fmt │
|
|
282
|
+
* │ --- │
|
|
283
|
+
* │ str │
|
|
284
|
+
* ╞═════════════╡
|
|
285
|
+
* │ foo_a_bar_1 │
|
|
286
|
+
* ├╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
287
|
+
* │ foo_b_bar_2 │
|
|
288
|
+
* ├╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
289
|
+
* │ foo_c_bar_3 │
|
|
290
|
+
* └─────────────┘
|
|
291
|
+
*
|
|
292
|
+
* // You can use format as tag function as well
|
|
293
|
+
* > pl.format("foo_{}_bar_{}", pl.col("a"), "b") // is the same as
|
|
294
|
+
* > pl.format`foo_${pl.col("a")}_bar_${"b"}`
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
export declare function format(strings: string | TemplateStringsArray, ...expr: ExprOrString[]): Expr;
|
|
298
|
+
/** Syntactic sugar for `pl.col(column).aggGroups()` */
|
|
299
|
+
export declare function groups(column: string): Expr;
|
|
300
|
+
/** Get the first n rows of an Expression. */
|
|
301
|
+
export declare function head(column: ExprOrString, n?: number): Expr;
|
|
302
|
+
export declare function head(column: Series, n?: number): Series;
|
|
303
|
+
/** Return the number of elements in the column.
|
|
304
|
+
This is similar to `COUNT(*)` in SQL.
|
|
305
|
+
|
|
306
|
+
@return Expr - Expression of data type :class:`UInt32`.
|
|
307
|
+
@example
|
|
308
|
+
```
|
|
309
|
+
>>> const df = pl.DataFrame(
|
|
310
|
+
... {
|
|
311
|
+
... "a": [1, 2, None],
|
|
312
|
+
... "b": [3, None, None],
|
|
313
|
+
... "c": ["foo", "bar", "foo"],
|
|
314
|
+
... }
|
|
315
|
+
... )
|
|
316
|
+
>>> df.select(pl.len())
|
|
317
|
+
shape: (1, 1)
|
|
318
|
+
┌─────┐
|
|
319
|
+
│ len │
|
|
320
|
+
│ --- │
|
|
321
|
+
│ u32 │
|
|
322
|
+
╞═════╡
|
|
323
|
+
│ 3 │
|
|
324
|
+
└─────┘
|
|
325
|
+
```
|
|
326
|
+
Generate an index column by using `len` in conjunction with :func:`intRange`.
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
>>> df.select(
|
|
330
|
+
... pl.intRange(pl.len(), dtype=pl.UInt32).alias("index"),
|
|
331
|
+
... pl.all(),
|
|
332
|
+
... )
|
|
333
|
+
shape: (3, 4)
|
|
334
|
+
┌───────┬──────┬──────┬─────┐
|
|
335
|
+
│ index ┆ a ┆ b ┆ c │
|
|
336
|
+
│ --- ┆ --- ┆ --- ┆ --- │
|
|
337
|
+
│ u32 ┆ i64 ┆ i64 ┆ str │
|
|
338
|
+
╞═══════╪══════╪══════╪═════╡
|
|
339
|
+
│ 0 ┆ 1 ┆ 3 ┆ foo │
|
|
340
|
+
│ 1 ┆ 2 ┆ null ┆ bar │
|
|
341
|
+
│ 2 ┆ null ┆ null ┆ foo │
|
|
342
|
+
└───────┴──────┴──────┴─────┘
|
|
343
|
+
```
|
|
344
|
+
*/
|
|
345
|
+
export declare function len(): Expr;
|
|
346
|
+
/** Get the last value. */
|
|
347
|
+
export declare function last(column: ExprOrString | Series): any;
|
|
348
|
+
/** Get the mean value. */
|
|
349
|
+
export declare function mean(column: ExprOrString): Expr;
|
|
350
|
+
export declare function mean(column: Series): number;
|
|
351
|
+
/** Get the median value. */
|
|
352
|
+
export declare function median(column: ExprOrString): Expr;
|
|
353
|
+
export declare function median(column: Series): number;
|
|
354
|
+
/** Count unique values. */
|
|
355
|
+
export declare function nUnique(column: ExprOrString): Expr;
|
|
356
|
+
export declare function nUnique(column: Series): number;
|
|
357
|
+
/** Compute the pearson's correlation between two columns. */
|
|
358
|
+
export declare function pearsonCorr(a: ExprOrString, b: ExprOrString): Expr;
|
|
359
|
+
/** Get the quantile */
|
|
360
|
+
export declare function quantile(column: ExprOrString, q: number): Expr;
|
|
361
|
+
export declare function quantile(column: Series, q: number): number;
|
|
362
|
+
/**
|
|
363
|
+
* __Run polars expressions without a context.__
|
|
364
|
+
*
|
|
365
|
+
* This is syntactic sugar for running `df.select` on an empty DataFrame.
|
|
366
|
+
*/
|
|
367
|
+
export declare function select(expr: ExprOrString, ...exprs: ExprOrString[]): DataFrame<{}>;
|
|
368
|
+
/** Compute the spearman rank correlation between two columns. */
|
|
369
|
+
export declare function spearmanRankCorr(a: ExprOrString, b: ExprOrString): Expr;
|
|
370
|
+
/** Get the last n rows of an Expression. */
|
|
371
|
+
export declare function tail(column: ExprOrString, n?: number): Expr;
|
|
372
|
+
export declare function tail(column: Series, n?: number): Series;
|
|
373
|
+
/** Syntactic sugar for `pl.col(column).list()` */
|
|
374
|
+
export declare function list(column: ExprOrString): Expr;
|
|
375
|
+
/**
|
|
376
|
+
Collect several columns into a Series of dtype Struct
|
|
377
|
+
Parameters
|
|
378
|
+
----------
|
|
379
|
+
@param exprs Columns/Expressions to collect into a Struct
|
|
380
|
+
Examples
|
|
381
|
+
--------
|
|
382
|
+
```
|
|
383
|
+
>pl.DataFrame(
|
|
384
|
+
... {
|
|
385
|
+
... "int": [1, 2],
|
|
386
|
+
... "str": ["a", "b"],
|
|
387
|
+
... "bool": [True, None],
|
|
388
|
+
... "list": [[1, 2], [3]],
|
|
389
|
+
... }
|
|
390
|
+
... ).select([pl.struct(pl.all()).alias("my_struct")])
|
|
391
|
+
shape: (2, 1)
|
|
392
|
+
┌───────────────────────┐
|
|
393
|
+
│ my_struct │
|
|
394
|
+
│ --- │
|
|
395
|
+
│ struct{int, ... list} │
|
|
396
|
+
╞═══════════════════════╡
|
|
397
|
+
│ {1,"a",true,[1, 2]} │
|
|
398
|
+
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
399
|
+
│ {2,"b",null,[3]} │
|
|
400
|
+
└───────────────────────┘
|
|
401
|
+
|
|
402
|
+
// Only collect specific columns as a struct:
|
|
403
|
+
>df = pl.DataFrame({
|
|
404
|
+
... "a": [1, 2, 3, 4],
|
|
405
|
+
... "b": ["one", "two", "three", "four"],
|
|
406
|
+
... "c": [9, 8, 7, 6]
|
|
407
|
+
... })
|
|
408
|
+
>df.withColumn(pl.struct(pl.col(["a", "b"])).alias("a_and_b"))
|
|
409
|
+
shape: (4, 4)
|
|
410
|
+
┌─────┬───────┬─────┬───────────────────────────────┐
|
|
411
|
+
│ a ┆ b ┆ c ┆ a_and_b │
|
|
412
|
+
│ --- ┆ --- ┆ --- ┆ --- │
|
|
413
|
+
│ i64 ┆ str ┆ i64 ┆ struct[2]{'a': i64, 'b': str} │
|
|
414
|
+
╞═════╪═══════╪═════╪═══════════════════════════════╡
|
|
415
|
+
│ 1 ┆ one ┆ 9 ┆ {1,"one"} │
|
|
416
|
+
├╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
417
|
+
│ 2 ┆ two ┆ 8 ┆ {2,"two"} │
|
|
418
|
+
├╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
419
|
+
│ 3 ┆ three ┆ 7 ┆ {3,"three"} │
|
|
420
|
+
├╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
421
|
+
│ 4 ┆ four ┆ 6 ┆ {4,"four"} │
|
|
422
|
+
└─────┴───────┴─────┴───────────────────────────────┘
|
|
423
|
+
```
|
|
424
|
+
*/
|
|
425
|
+
export declare function struct(exprs: Series[]): Series;
|
|
426
|
+
export declare function struct(exprs: ExprOrString | ExprOrString[]): Expr;
|
|
427
|
+
/**
|
|
428
|
+
* Alias for an element in evaluated in an `eval` expression.
|
|
429
|
+
|
|
430
|
+
* @example
|
|
431
|
+
*
|
|
432
|
+
* A horizontal rank computation by taking the elements of a list
|
|
433
|
+
*
|
|
434
|
+
* >df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]})
|
|
435
|
+
* >df.withColumn(
|
|
436
|
+
* ... pl.concatList(["a", "b"]).arr.eval(pl.element().rank()).alias("rank")
|
|
437
|
+
* ... )
|
|
438
|
+
* shape: (3, 3)
|
|
439
|
+
* ┌─────┬─────┬────────────┐
|
|
440
|
+
* │ a ┆ b ┆ rank │
|
|
441
|
+
* │ --- ┆ --- ┆ --- │
|
|
442
|
+
* │ i64 ┆ i64 ┆ list[f32] │
|
|
443
|
+
* ╞═════╪═════╪════════════╡
|
|
444
|
+
* │ 1 ┆ 4 ┆ [1.0, 2.0] │
|
|
445
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
446
|
+
* │ 8 ┆ 5 ┆ [2.0, 1.0] │
|
|
447
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
448
|
+
* │ 3 ┆ 2 ┆ [2.0, 1.0] │
|
|
449
|
+
* └─────┴─────┴────────────┘
|
|
450
|
+
*
|
|
451
|
+
* A mathematical operation on array elements
|
|
452
|
+
*
|
|
453
|
+
* >df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]})
|
|
454
|
+
* >df.withColumn(
|
|
455
|
+
* ... pl.concatList(["a", "b"]).arr.eval(pl.element().multiplyBy(2)).alias("a_b_doubled")
|
|
456
|
+
* ... )
|
|
457
|
+
* shape: (3, 3)
|
|
458
|
+
* ┌─────┬─────┬─────────────┐
|
|
459
|
+
* │ a ┆ b ┆ a_b_doubled │
|
|
460
|
+
* │ --- ┆ --- ┆ --- │
|
|
461
|
+
* │ i64 ┆ i64 ┆ list[i64] │
|
|
462
|
+
* ╞═════╪═════╪═════════════╡
|
|
463
|
+
* │ 1 ┆ 4 ┆ [2, 8] │
|
|
464
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
465
|
+
* │ 8 ┆ 5 ┆ [16, 10] │
|
|
466
|
+
* ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
467
|
+
* │ 3 ┆ 2 ┆ [6, 4] │
|
|
468
|
+
* └─────┴─────┴─────────────┘
|
|
469
|
+
*/
|
|
470
|
+
export declare function element(): Expr;
|
|
471
|
+
/**
|
|
472
|
+
* Compute the bitwise AND horizontally across columns.
|
|
473
|
+
* @param exprs
|
|
474
|
+
* Column(s) to use in the aggregation. Accepts expression input. Strings are
|
|
475
|
+
* parsed as column names, other non-expression inputs are parsed as literals.
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* ```
|
|
479
|
+
* >>> const df = pl.DataFrame(
|
|
480
|
+
* {
|
|
481
|
+
* "a": [false, false, true, true],
|
|
482
|
+
* "b": [false, true, null, true],
|
|
483
|
+
* "c": ["w", "x", "y", "z"],
|
|
484
|
+
* }
|
|
485
|
+
* )
|
|
486
|
+
* >>> df.withColumns(pl.allHorizontal([pl.col("a"), pl.col("b")]))
|
|
487
|
+
* shape: (4, 4)
|
|
488
|
+
* ┌───────┬───────┬─────┬───────┐
|
|
489
|
+
* │ a ┆ b ┆ c ┆ all │
|
|
490
|
+
* │ --- ┆ --- ┆ --- ┆ --- │
|
|
491
|
+
* │ bool ┆ bool ┆ str ┆ bool │
|
|
492
|
+
* ╞═══════╪═══════╪═════╪═══════╡
|
|
493
|
+
* │ false ┆ false ┆ w ┆ false │
|
|
494
|
+
* │ false ┆ true ┆ x ┆ false │
|
|
495
|
+
* │ true ┆ null ┆ y ┆ null │
|
|
496
|
+
* │ true ┆ true ┆ z ┆ true │
|
|
497
|
+
* └───────┴───────┴─────┴───────┘
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
500
|
+
export declare function allHorizontal(exprs: ExprOrString | ExprOrString[]): Expr;
|
|
501
|
+
/**
|
|
502
|
+
* Compute the bitwise OR horizontally across columns.
|
|
503
|
+
* @param exprs
|
|
504
|
+
* Column(s) to use in the aggregation. Accepts expression input. Strings are
|
|
505
|
+
* parsed as column names, other non-expression inputs are parsed as literals.
|
|
506
|
+
* @example
|
|
507
|
+
* ```
|
|
508
|
+
* >>> const df = pl.DataFrame(
|
|
509
|
+
* ... {
|
|
510
|
+
* ... "a": [false, false, true, null],
|
|
511
|
+
* ... "b": [false, true, null, null],
|
|
512
|
+
* ... "c": ["w", "x", "y", "z"],
|
|
513
|
+
* ... }
|
|
514
|
+
* ... )
|
|
515
|
+
* >>> df.withColumns(pl.anyHorizontal([pl.col("a"), pl.col("b")]))
|
|
516
|
+
* shape: (4, 4)
|
|
517
|
+
* ┌───────┬───────┬─────┬───────┐
|
|
518
|
+
* │ a ┆ b ┆ c ┆ any │
|
|
519
|
+
* │ --- ┆ --- ┆ --- ┆ --- │
|
|
520
|
+
* │ bool ┆ bool ┆ str ┆ bool │
|
|
521
|
+
* ╞═══════╪═══════╪═════╪═══════╡
|
|
522
|
+
* │ false ┆ false ┆ w ┆ false │
|
|
523
|
+
* │ false ┆ true ┆ x ┆ true │
|
|
524
|
+
* │ true ┆ null ┆ y ┆ true │
|
|
525
|
+
* │ null ┆ null ┆ z ┆ null │
|
|
526
|
+
* └───────┴───────┴─────┴───────┘
|
|
527
|
+
* ```
|
|
528
|
+
*/
|
|
529
|
+
export declare function anyHorizontal(exprs: ExprOrString | ExprOrString[]): Expr;
|
|
530
|
+
/**
|
|
531
|
+
* Get the maximum value horizontally across columns.
|
|
532
|
+
* @param exprs
|
|
533
|
+
* Column(s) to use in the aggregation. Accepts expression input. Strings are
|
|
534
|
+
* parsed as column names, other non-expression inputs are parsed as literals.
|
|
535
|
+
* @example
|
|
536
|
+
* ```
|
|
537
|
+
* >>> const df = pl.DataFrame(
|
|
538
|
+
* ... {
|
|
539
|
+
* ... "a": [1, 8, 3],
|
|
540
|
+
* ... "b": [4, 5, null],
|
|
541
|
+
* ... "c": ["x", "y", "z"],
|
|
542
|
+
* ... }
|
|
543
|
+
* ... )
|
|
544
|
+
* >>> df.withColumns(pl.maxHorizontal(pl.col("a"), pl.col("b")))
|
|
545
|
+
* shape: (3, 4)
|
|
546
|
+
* ┌─────┬──────┬─────┬─────┐
|
|
547
|
+
* │ a ┆ b ┆ c ┆ max │
|
|
548
|
+
* │ --- ┆ --- ┆ --- ┆ --- │
|
|
549
|
+
* │ i64 ┆ i64 ┆ str ┆ i64 │
|
|
550
|
+
* ╞═════╪══════╪═════╪═════╡
|
|
551
|
+
* │ 1 ┆ 4 ┆ x ┆ 4 │
|
|
552
|
+
* │ 8 ┆ 5 ┆ y ┆ 8 │
|
|
553
|
+
* │ 3 ┆ null ┆ z ┆ 3 │
|
|
554
|
+
* └─────┴──────┴─────┴─────┘
|
|
555
|
+
* ```
|
|
556
|
+
*/
|
|
557
|
+
export declare function maxHorizontal(exprs: ExprOrString | ExprOrString[]): Expr;
|
|
558
|
+
/**
|
|
559
|
+
* Get the minimum value horizontally across columns.
|
|
560
|
+
* @param exprs Column(s) to use in the aggregation. Accepts expression input. Strings are
|
|
561
|
+
* parsed as column names, other non-expression inputs are parsed as literals.
|
|
562
|
+
* @example
|
|
563
|
+
* ```
|
|
564
|
+
* >>> const df = pl.DataFrame(
|
|
565
|
+
* ... {
|
|
566
|
+
* ... "a": [1, 8, 3],
|
|
567
|
+
* ... "b": [4, 5, null],
|
|
568
|
+
* ... "c": ["x", "y", "z"],
|
|
569
|
+
* ... }
|
|
570
|
+
* ... )
|
|
571
|
+
* >>> df.withColumns(pl.minHorizontal(pl.col("a"), pl.col("b")))
|
|
572
|
+
* shape: (3, 4)
|
|
573
|
+
* ┌─────┬──────┬─────┬─────┐
|
|
574
|
+
* │ a ┆ b ┆ c ┆ min │
|
|
575
|
+
* │ --- ┆ --- ┆ --- ┆ --- │
|
|
576
|
+
* │ i64 ┆ i64 ┆ str ┆ i64 │
|
|
577
|
+
* ╞═════╪══════╪═════╪═════╡
|
|
578
|
+
* │ 1 ┆ 4 ┆ x ┆ 1 │
|
|
579
|
+
* │ 8 ┆ 5 ┆ y ┆ 5 │
|
|
580
|
+
* │ 3 ┆ null ┆ z ┆ 3 │
|
|
581
|
+
* └─────┴──────┴─────┴─────┘
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
584
|
+
export declare function minHorizontal(exprs: ExprOrString | ExprOrString[]): Expr;
|
|
585
|
+
/**
|
|
586
|
+
* Sum all values horizontally across columns.
|
|
587
|
+
* @param exprs
|
|
588
|
+
* Column(s) to use in the aggregation. Accepts expression input. Strings are
|
|
589
|
+
* parsed as column names, other non-expression inputs are parsed as literals.
|
|
590
|
+
* @example
|
|
591
|
+
* ```
|
|
592
|
+
* >>> const df = pl.DataFrame(
|
|
593
|
+
* ... {
|
|
594
|
+
* ... "a": [1, 8, 3],
|
|
595
|
+
* ... "b": [4, 5, null],
|
|
596
|
+
* ... "c": ["x", "y", "z"],
|
|
597
|
+
* ... }
|
|
598
|
+
* ... )
|
|
599
|
+
* >>> df.withColumns(pl.sumHorizontal(pl.col("a"), ol.col("b")))
|
|
600
|
+
* shape: (3, 4)
|
|
601
|
+
* ┌─────┬──────┬─────┬──────┐
|
|
602
|
+
* │ a ┆ b ┆ c ┆ sum │
|
|
603
|
+
* │ --- ┆ --- ┆ --- ┆ --- │
|
|
604
|
+
* │ i64 ┆ i64 ┆ str ┆ i64 │
|
|
605
|
+
* ╞═════╪══════╪═════╪══════╡
|
|
606
|
+
* │ 1 ┆ 4 ┆ x ┆ 5 │
|
|
607
|
+
* │ 8 ┆ 5 ┆ y ┆ 13 │
|
|
608
|
+
* │ 3 ┆ null ┆ z ┆ null │
|
|
609
|
+
* └─────┴──────┴─────┴──────┘
|
|
610
|
+
* ```
|
|
611
|
+
*/
|
|
612
|
+
export declare function sumHorizontal(exprs: ExprOrString | ExprOrString[]): Expr;
|