@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.
Files changed (71) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +217 -0
  3. package/bin/cfg.d.ts +156 -0
  4. package/bin/cfg.js +52 -0
  5. package/bin/dataframe.d.ts +2135 -0
  6. package/bin/dataframe.js +783 -0
  7. package/bin/datatypes/conversion.d.ts +2 -0
  8. package/bin/datatypes/conversion.js +2 -0
  9. package/bin/datatypes/datatype.d.ts +285 -0
  10. package/bin/datatypes/datatype.js +430 -0
  11. package/bin/datatypes/field.d.ts +26 -0
  12. package/bin/datatypes/field.js +36 -0
  13. package/bin/datatypes/index.d.ts +43 -0
  14. package/bin/datatypes/index.js +120 -0
  15. package/bin/error.d.ts +7 -0
  16. package/bin/error.js +17 -0
  17. package/bin/functions.d.ts +26 -0
  18. package/bin/functions.js +208 -0
  19. package/bin/groupby.d.ts +212 -0
  20. package/bin/groupby.js +156 -0
  21. package/bin/html.d.ts +4 -0
  22. package/bin/html.js +18 -0
  23. package/bin/index.d.ts +256 -0
  24. package/bin/index.js +267 -0
  25. package/bin/internals/construction.d.ts +7 -0
  26. package/bin/internals/construction.js +256 -0
  27. package/bin/internals/polars_internal.d.ts +2 -0
  28. package/bin/internals/polars_internal.js +7 -0
  29. package/bin/io.d.ts +433 -0
  30. package/bin/io.js +344 -0
  31. package/bin/lazy/dataframe.d.ts +785 -0
  32. package/bin/lazy/dataframe.js +427 -0
  33. package/bin/lazy/expr/datetime.d.ts +8 -0
  34. package/bin/lazy/expr/datetime.js +27 -0
  35. package/bin/lazy/expr/index.d.ts +1152 -0
  36. package/bin/lazy/expr/index.js +632 -0
  37. package/bin/lazy/expr/list.d.ts +8 -0
  38. package/bin/lazy/expr/list.js +115 -0
  39. package/bin/lazy/expr/string.d.ts +534 -0
  40. package/bin/lazy/expr/string.js +131 -0
  41. package/bin/lazy/expr/struct.d.ts +126 -0
  42. package/bin/lazy/expr/struct.js +26 -0
  43. package/bin/lazy/functions.d.ts +612 -0
  44. package/bin/lazy/functions.js +687 -0
  45. package/bin/lazy/groupby.d.ts +29 -0
  46. package/bin/lazy/groupby.js +30 -0
  47. package/bin/lazy/index.d.ts +4 -0
  48. package/bin/lazy/index.js +20 -0
  49. package/bin/lazy/whenthen.d.ts +67 -0
  50. package/bin/lazy/whenthen.js +81 -0
  51. package/bin/native-polars.d.ts +2 -0
  52. package/bin/native-polars.js +267 -0
  53. package/bin/series/datetime.d.ts +8 -0
  54. package/bin/series/datetime.js +34 -0
  55. package/bin/series/index.d.ts +1135 -0
  56. package/bin/series/index.js +700 -0
  57. package/bin/series/list.d.ts +8 -0
  58. package/bin/series/list.js +87 -0
  59. package/bin/series/string.d.ts +300 -0
  60. package/bin/series/string.js +125 -0
  61. package/bin/series/struct.d.ts +36 -0
  62. package/bin/series/struct.js +35 -0
  63. package/bin/shared_traits.d.ts +1458 -0
  64. package/bin/shared_traits.js +2 -0
  65. package/bin/sql.d.ts +244 -0
  66. package/bin/sql.js +63 -0
  67. package/bin/types.d.ts +287 -0
  68. package/bin/types.js +2 -0
  69. package/bin/utils.d.ts +38 -0
  70. package/bin/utils.js +69 -0
  71. package/package.json +45 -0
@@ -0,0 +1,2135 @@
1
+ import { Writable } from "node:stream";
2
+ import { DataType, type DTypeToJs, type JsToDtype } from "./datatypes";
3
+ import { type GroupBy, RollingGroupBy } from "./groupby";
4
+ import { type LazyDataFrame } from "./lazy/dataframe";
5
+ import { Expr } from "./lazy/expr";
6
+ import { Series } from "./series";
7
+ import type { Arithmetic, Deserialize, GroupByOps, Sample, Serialize } from "./shared_traits";
8
+ import type { CrossJoinOptions, CsvWriterOptions, DifferentNameColumnJoinOptions, FillNullStrategy, JoinOptions, SameNameColumnJoinOptions, WriteAvroOptions, WriteIPCOptions, WriteParquetOptions } from "./types";
9
+ import { type ColumnSelection, type ColumnsOrExpr, type ExprOrString, type Simplify } from "./utils";
10
+ declare const inspect: unique symbol;
11
+ export declare const writeCsvDefaultOptions: Partial<CsvWriterOptions>;
12
+ /**
13
+ * Write methods for DataFrame
14
+ */
15
+ interface WriteMethods {
16
+ /**
17
+ * __Write DataFrame to comma-separated values file (csv).__
18
+ *
19
+ * If no options are specified, it will return a new string containing the contents
20
+ * ___
21
+ * @param dest file or stream to write to
22
+ * @param options.includeBom - Whether to include UTF-8 BOM in the CSV output.
23
+ * @param options.lineTerminator - String used to end each row.
24
+ * @param options.includeHeader - Whether or not to include header in the CSV output.
25
+ * @param options.separator - Separate CSV fields with this symbol. Defaults: `,`
26
+ * @param options.quoteChar - Character to use for quoting. Default: '"'
27
+ * @param options.batchSize - Number of rows that will be processed per thread.
28
+ * @param options.datetimeFormat - A format string, with the specifiers defined by the
29
+ * `chrono <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>`_
30
+ * Rust crate. If no format specified, the default fractional-second
31
+ * precision is inferred from the maximum timeunit found in the frame's
32
+ * Datetime cols (if any).
33
+ * @param options.dateFormat - A format string, with the specifiers defined by the
34
+ * `chrono <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>`_
35
+ * Rust crate.
36
+ * @param options.timeFormat A format string, with the specifiers defined by the
37
+ * `chrono <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>`_
38
+ * Rust crate.
39
+ * @param options.floatPrecision - Number of decimal places to write, applied to both `Float32` and `Float64` datatypes.
40
+ * @param options.nullValue - A string representing null values (defaulting to the empty string).
41
+ * @example
42
+ * ```
43
+ * > const df = pl.DataFrame({
44
+ * ... "foo": [1, 2, 3],
45
+ * ... "bar": [6, 7, 8],
46
+ * ... "ham": ['a', 'b', 'c']
47
+ * ... });
48
+ * > df.writeCSV();
49
+ * foo,bar,ham
50
+ * 1,6,a
51
+ * 2,7,b
52
+ * 3,8,c
53
+ *
54
+ * // using a file path
55
+ * > df.head(1).writeCSV("./foo.csv")
56
+ * // foo.csv
57
+ * foo,bar,ham
58
+ * 1,6,a
59
+ *
60
+ * // using a write stream
61
+ * > const writeStream = new Stream.Writable({
62
+ * ... write(chunk, encoding, callback) {
63
+ * ... console.log("writeStream: %O', chunk.toString());
64
+ * ... callback(null);
65
+ * ... }
66
+ * ... });
67
+ * > df.head(1).writeCSV(writeStream, {includeHeader: false});
68
+ * writeStream: '1,6,a'
69
+ * ```
70
+ * @category IO
71
+ */
72
+ writeCSV(dest: string | Writable, options?: CsvWriterOptions): void;
73
+ writeCSV(): Buffer;
74
+ writeCSV(options: CsvWriterOptions): Buffer;
75
+ /**
76
+ * Write Dataframe to JSON string, file, or write stream
77
+ * @param destination file or write stream
78
+ * @param options.format - json | lines
79
+ * @example
80
+ * ```
81
+ * > const df = pl.DataFrame({
82
+ * ... foo: [1,2,3],
83
+ * ... bar: ['a','b','c']
84
+ * ... })
85
+ *
86
+ * > df.writeJSON({format:"json"})
87
+ * `[ {"foo":1.0,"bar":"a"}, {"foo":2.0,"bar":"b"}, {"foo":3.0,"bar":"c"}]`
88
+ *
89
+ * > df.writeJSON({format:"lines"})
90
+ * `{"foo":1.0,"bar":"a"}
91
+ * {"foo":2.0,"bar":"b"}
92
+ * {"foo":3.0,"bar":"c"}`
93
+ *
94
+ * // writing to a file
95
+ * > df.writeJSON("/path/to/file.json", {format:'lines'})
96
+ * ```
97
+ * @category IO
98
+ */
99
+ writeJSON(destination: string | Writable, options?: {
100
+ format: "lines" | "json";
101
+ }): void;
102
+ writeJSON(options?: {
103
+ format: "lines" | "json";
104
+ }): Buffer;
105
+ /**
106
+ * Write to Arrow IPC feather file, either to a file path or to a write stream.
107
+ * @param destination File path to which the file should be written, or writable.
108
+ * @param options.compression Compression method *defaults to "uncompressed"*
109
+ * @category IO
110
+ */
111
+ writeIPC(destination: string | Writable, options?: WriteIPCOptions): void;
112
+ writeIPC(options?: WriteIPCOptions): Buffer;
113
+ /**
114
+ * Write to Arrow IPC stream file, either to a file path or to a write stream.
115
+ * @param destination File path to which the file should be written, or writable.
116
+ * @param options.compression Compression method *defaults to "uncompressed"*
117
+ * @category IO
118
+ */
119
+ writeIPCStream(destination: string | Writable, options?: WriteIPCOptions): void;
120
+ writeIPCStream(options?: WriteIPCOptions): Buffer;
121
+ /**
122
+ * Write the DataFrame disk in parquet format.
123
+ * @param destination File path to which the file should be written, or writable.
124
+ * @param options.compression Compression method *defaults to "uncompressed"*
125
+ * @category IO
126
+ */
127
+ writeParquet(destination: string | Writable, options?: WriteParquetOptions): void;
128
+ writeParquet(options?: WriteParquetOptions): Buffer;
129
+ /**
130
+ * Write the DataFrame disk in avro format.
131
+ * @param destination File path to which the file should be written, or writable.
132
+ * @param options.compression Compression method *defaults to "uncompressed"*
133
+ * @category IO
134
+ */
135
+ writeAvro(destination: string | Writable, options?: WriteAvroOptions): void;
136
+ writeAvro(options?: WriteAvroOptions): Buffer;
137
+ }
138
+ export type Schema = Record<string, DataType>;
139
+ type SchemaToSeriesRecord<T extends Record<string, DataType>> = {
140
+ [K in keyof T]: K extends string ? Series<T[K], K> : never;
141
+ };
142
+ type ArrayLikeLooseRecordToSchema<T extends Record<string, ArrayLike<any>>> = {
143
+ [K in keyof T]: K extends string | number ? T[K] extends ArrayLike<infer V> ? V extends DataType ? V : JsToDtype<V> : never : never;
144
+ };
145
+ type ExtractJoinKeys<T> = T extends string[] ? T[number] : T;
146
+ type ExtractSuffix<T extends JoinOptions> = T extends {
147
+ suffix: infer Suffix;
148
+ } ? Suffix : "_right";
149
+ export type JoinSchemas<S1 extends Schema, S2 extends Schema, Opt extends JoinOptions> = Simplify<{
150
+ [K1 in keyof S1]: S1[K1];
151
+ } & {
152
+ [K2 in Exclude<keyof S2, keyof S1>]: K2 extends keyof S1 ? never : S2[K2];
153
+ } & {
154
+ [K_SUFFIXED in keyof S1 & Exclude<keyof S2, Opt extends CrossJoinOptions ? never : Opt extends SameNameColumnJoinOptions ? ExtractJoinKeys<Opt["on"]> : Opt extends DifferentNameColumnJoinOptions ? ExtractJoinKeys<Opt["rightOn"]> : never> as `${K_SUFFIXED extends string ? K_SUFFIXED : never}${ExtractSuffix<Opt>}`]: K_SUFFIXED extends string ? S2[K_SUFFIXED] : never;
155
+ }>;
156
+ /**
157
+ * A DataFrame is a two-dimensional data structure that represents data as a table
158
+ * with rows and columns.
159
+ *
160
+ * @param data - Object, Array, or Series
161
+ * Two-dimensional data in various forms. object must contain Arrays.
162
+ * Array may contain Series or other Arrays.
163
+ * @param columns - Array of str, default undefined
164
+ * Column labels to use for resulting DataFrame. If specified, overrides any
165
+ * labels already present in the data. Must match data dimensions.
166
+ * @param orient - 'col' | 'row' default undefined
167
+ * Whether to interpret two-dimensional data as columns or as rows. If None,
168
+ * the orientation is inferred by matching the columns and data dimensions. If
169
+ * this does not yield conclusive results, column orientation is used.
170
+ * @example
171
+ * Constructing a DataFrame from an object :
172
+ * ```
173
+ * > const data = {'a': [1n, 2n], 'b': [3, 4]};
174
+ * > const df = pl.DataFrame(data);
175
+ * > console.log(df.toString());
176
+ * shape: (2, 2)
177
+ * ╭─────┬─────╮
178
+ * │ a ┆ b │
179
+ * │ --- ┆ --- │
180
+ * │ u64 ┆ i64 │
181
+ * ╞═════╪═════╡
182
+ * │ 1 ┆ 3 │
183
+ * ├╌╌╌╌╌┼╌╌╌╌╌┤
184
+ * │ 2 ┆ 4 │
185
+ * ╰─────┴─────╯
186
+ * ```
187
+ * Notice that the dtype is automatically inferred as a polars Int64:
188
+ * ```
189
+ * > df.dtypes
190
+ * ['UInt64', `Int64']
191
+ * ```
192
+ * In order to specify dtypes for your columns, initialize the DataFrame with a list
193
+ * of Series instead:
194
+ * ```
195
+ * > const data = [pl.Series('col1', [1, 2], pl.Float32), pl.Series('col2', [3, 4], pl.Int64)];
196
+ * > const df2 = pl.DataFrame(series);
197
+ * > console.log(df2.toString());
198
+ * shape: (2, 2)
199
+ * ╭──────┬──────╮
200
+ * │ col1 ┆ col2 │
201
+ * │ --- ┆ --- │
202
+ * │ f32 ┆ i64 │
203
+ * ╞══════╪══════╡
204
+ * │ 1 ┆ 3 │
205
+ * ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤
206
+ * │ 2 ┆ 4 │
207
+ * ╰──────┴──────╯
208
+ * ```
209
+ *
210
+ * Constructing a DataFrame from a list of lists, row orientation inferred:
211
+ * ```
212
+ * > const data = [[1, 2, 3], [4, 5, 6]];
213
+ * > const df4 = pl.DataFrame(data, ['a', 'b', 'c']);
214
+ * > console.log(df4.toString());
215
+ * shape: (2, 3)
216
+ * ╭─────┬─────┬─────╮
217
+ * │ a ┆ b ┆ c │
218
+ * │ --- ┆ --- ┆ --- │
219
+ * │ i64 ┆ i64 ┆ i64 │
220
+ * ╞═════╪═════╪═════╡
221
+ * │ 1 ┆ 2 ┆ 3 │
222
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
223
+ * │ 4 ┆ 5 ┆ 6 │
224
+ * ╰─────┴─────┴─────╯
225
+ * ```
226
+ */
227
+ export interface DataFrame<S extends Schema = any> extends Arithmetic<DataFrame<S>>, Sample<DataFrame<S>>, WriteMethods, Serialize, GroupByOps<RollingGroupBy> {
228
+ /** @ignore */
229
+ _df: any;
230
+ dtypes: DataType[];
231
+ height: number;
232
+ shape: {
233
+ height: number;
234
+ width: number;
235
+ };
236
+ width: number;
237
+ get columns(): string[];
238
+ set columns(cols: string[]);
239
+ [inspect](): string;
240
+ [Symbol.iterator](): Generator<any, void, any>;
241
+ /**
242
+ * Very cheap deep clone.
243
+ */
244
+ clone(): DataFrame<S>;
245
+ /**
246
+ * __Summary statistics for a DataFrame.__
247
+ *
248
+ * Only summarizes numeric datatypes at the moment and returns nulls for non numeric datatypes.
249
+ * ___
250
+ * Example
251
+ * ```
252
+ * > const df = pl.DataFrame({
253
+ * ... 'a': [1.0, 2.8, 3.0],
254
+ * ... 'b': [4, 5, 6],
255
+ * ... "c": [True, False, True]
256
+ * ... });
257
+ * ... df.describe()
258
+ * shape: (5, 4)
259
+ * ╭──────────┬───────┬─────┬──────╮
260
+ * │ describe ┆ a ┆ b ┆ c │
261
+ * │ --- ┆ --- ┆ --- ┆ --- │
262
+ * │ str ┆ f64 ┆ f64 ┆ f64 │
263
+ * ╞══════════╪═══════╪═════╪══════╡
264
+ * │ "mean" ┆ 2.267 ┆ 5 ┆ null │
265
+ * ├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
266
+ * │ "std" ┆ 1.102 ┆ 1 ┆ null │
267
+ * ├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
268
+ * │ "min" ┆ 1 ┆ 4 ┆ 0.0 │
269
+ * ├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
270
+ * │ "max" ┆ 3 ┆ 6 ┆ 1 │
271
+ * ├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
272
+ * │ "median" ┆ 2.8 ┆ 5 ┆ null │
273
+ * ╰──────────┴───────┴─────┴──────╯
274
+ * ```
275
+ */
276
+ describe(): DataFrame;
277
+ /**
278
+ * __Remove column from DataFrame and return as new.__
279
+ * ___
280
+ * @param name
281
+ * @example
282
+ * ```
283
+ * > const df = pl.DataFrame({
284
+ * ... "foo": [1, 2, 3],
285
+ * ... "bar": [6.0, 7.0, 8.0],
286
+ * ... "ham": ['a', 'b', 'c'],
287
+ * ... "apple": ['a', 'b', 'c']
288
+ * ... });
289
+ * // df: pl.DataFrame<{
290
+ * // foo: pl.Series<Float64, "foo">;
291
+ * // bar: pl.Series<Float64, "bar">;
292
+ * // ham: pl.Series<Utf8, "ham">;
293
+ * // apple: pl.Series<Utf8, "apple">;
294
+ * // }>
295
+ * > const df2 = df.drop(['ham', 'apple']);
296
+ * // df2: pl.DataFrame<{
297
+ * // foo: pl.Series<Float64, "foo">;
298
+ * // bar: pl.Series<Float64, "bar">;
299
+ * // }>
300
+ * > console.log(df2.toString());
301
+ * shape: (3, 2)
302
+ * ╭─────┬─────╮
303
+ * │ foo ┆ bar │
304
+ * │ --- ┆ --- │
305
+ * │ i64 ┆ f64 │
306
+ * ╞═════╪═════╡
307
+ * │ 1 ┆ 6 │
308
+ * ├╌╌╌╌╌┼╌╌╌╌╌┤
309
+ * │ 2 ┆ 7 │
310
+ * ├╌╌╌╌╌┼╌╌╌╌╌┤
311
+ * │ 3 ┆ 8 │
312
+ * ╰─────┴─────╯
313
+ * ```
314
+ */
315
+ drop<U extends string>(name: U): DataFrame<Simplify<Omit<S, U>>>;
316
+ drop<const U extends string[]>(names: U): DataFrame<Simplify<Omit<S, U[number]>>>;
317
+ drop<U extends string, const V extends string[]>(name: U, ...names: V): DataFrame<Simplify<Omit<S, U | V[number]>>>;
318
+ /**
319
+ * __Return a new DataFrame where the null values are dropped.__
320
+ *
321
+ * This method only drops nulls row-wise if any single value of the row is null.
322
+ * ___
323
+ * @example
324
+ * ```
325
+ * > const df = pl.DataFrame({
326
+ * ... "foo": [1, 2, 3],
327
+ * ... "bar": [6, null, 8],
328
+ * ... "ham": ['a', 'b', 'c']
329
+ * ... });
330
+ * > console.log(df.dropNulls().toString());
331
+ * shape: (2, 3)
332
+ * ┌─────┬─────┬─────┐
333
+ * │ foo ┆ bar ┆ ham │
334
+ * │ --- ┆ --- ┆ --- │
335
+ * │ i64 ┆ i64 ┆ str │
336
+ * ╞═════╪═════╪═════╡
337
+ * │ 1 ┆ 6 ┆ "a" │
338
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
339
+ * │ 3 ┆ 8 ┆ "c" │
340
+ * └─────┴─────┴─────┘
341
+ * ```
342
+ */
343
+ dropNulls(column: keyof S): DataFrame<S>;
344
+ dropNulls(columns: (keyof S)[]): DataFrame<S>;
345
+ dropNulls(...columns: (keyof S)[]): DataFrame<S>;
346
+ /**
347
+ * __Explode `DataFrame` to long format by exploding a column with Lists.__
348
+ * ___
349
+ * @param columns - column or columns to explode
350
+ * @example
351
+ * ```
352
+ * > const df = pl.DataFrame({
353
+ * ... "letters": ["c", "c", "a", "c", "a", "b"],
354
+ * ... "nrs": [[1, 2], [1, 3], [4, 3], [5, 5, 5], [6], [2, 1, 2]]
355
+ * ... });
356
+ * > console.log(df.toString());
357
+ * shape: (6, 2)
358
+ * ╭─────────┬────────────╮
359
+ * │ letters ┆ nrs │
360
+ * │ --- ┆ --- │
361
+ * │ str ┆ list [i64] │
362
+ * ╞═════════╪════════════╡
363
+ * │ "c" ┆ [1, 2] │
364
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
365
+ * │ "c" ┆ [1, 3] │
366
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
367
+ * │ "a" ┆ [4, 3] │
368
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
369
+ * │ "c" ┆ [5, 5, 5] │
370
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
371
+ * │ "a" ┆ [6] │
372
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
373
+ * │ "b" ┆ [2, 1, 2] │
374
+ * ╰─────────┴────────────╯
375
+ * > df.explode("nrs")
376
+ * shape: (13, 2)
377
+ * ╭─────────┬─────╮
378
+ * │ letters ┆ nrs │
379
+ * │ --- ┆ --- │
380
+ * │ str ┆ i64 │
381
+ * ╞═════════╪═════╡
382
+ * │ "c" ┆ 1 │
383
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
384
+ * │ "c" ┆ 2 │
385
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
386
+ * │ "c" ┆ 1 │
387
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
388
+ * │ "c" ┆ 3 │
389
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
390
+ * │ ... ┆ ... │
391
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
392
+ * │ "c" ┆ 5 │
393
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
394
+ * │ "a" ┆ 6 │
395
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
396
+ * │ "b" ┆ 2 │
397
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
398
+ * │ "b" ┆ 1 │
399
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
400
+ * │ "b" ┆ 2 │
401
+ * ╰─────────┴─────╯
402
+ * ```
403
+ */
404
+ explode(columns: ExprOrString[]): DataFrame;
405
+ explode(column: ExprOrString): DataFrame;
406
+ explode(column: ExprOrString, ...columns: ExprOrString[]): DataFrame;
407
+ /**
408
+ *
409
+ *
410
+ * __Extend the memory backed by this `DataFrame` with the values from `other`.__
411
+ * ___
412
+
413
+ Different from `vstack` which adds the chunks from `other` to the chunks of this `DataFrame`
414
+ `extent` appends the data from `other` to the underlying memory locations and thus may cause a reallocation.
415
+
416
+ If this does not cause a reallocation, the resulting data structure will not have any extra chunks
417
+ and thus will yield faster queries.
418
+
419
+ Prefer `extend` over `vstack` when you want to do a query after a single append. For instance during
420
+ online operations where you add `n` rows and rerun a query.
421
+
422
+ Prefer `vstack` over `extend` when you want to append many times before doing a query. For instance
423
+ when you read in multiple files and when to store them in a single `DataFrame`.
424
+ In the latter case, finish the sequence of `vstack` operations with a `rechunk`.
425
+
426
+ * @param other DataFrame to vertically add.
427
+ */
428
+ extend(other: DataFrame<S>): DataFrame<S>;
429
+ /**
430
+ * Fill null/missing values by a filling strategy
431
+ *
432
+ * @param strategy - One of:
433
+ * - "backward"
434
+ * - "forward"
435
+ * - "mean"
436
+ * - "min'
437
+ * - "max"
438
+ * - "zero"
439
+ * - "one"
440
+ * @returns DataFrame with None replaced with the filling strategy.
441
+ */
442
+ fillNull(strategy: FillNullStrategy): DataFrame<S>;
443
+ /**
444
+ * Filter the rows in the DataFrame based on a predicate expression.
445
+ * ___
446
+ * @param predicate - Expression that evaluates to a boolean Series.
447
+ * @example
448
+ * ```
449
+ * > const df = pl.DataFrame({
450
+ * ... "foo": [1, 2, 3],
451
+ * ... "bar": [6, 7, 8],
452
+ * ... "ham": ['a', 'b', 'c']
453
+ * ... });
454
+ * // Filter on one condition
455
+ * > df.filter(pl.col("foo").lt(3))
456
+ * shape: (2, 3)
457
+ * ┌─────┬─────┬─────┐
458
+ * │ foo ┆ bar ┆ ham │
459
+ * │ --- ┆ --- ┆ --- │
460
+ * │ i64 ┆ i64 ┆ str │
461
+ * ╞═════╪═════╪═════╡
462
+ * │ 1 ┆ 6 ┆ a │
463
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
464
+ * │ 2 ┆ 7 ┆ b │
465
+ * └─────┴─────┴─────┘
466
+ * // Filter on multiple conditions
467
+ * > df.filter(
468
+ * ... pl.col("foo").lt(3)
469
+ * ... .and(pl.col("ham").eq(pl.lit("a")))
470
+ * ... )
471
+ * shape: (1, 3)
472
+ * ┌─────┬─────┬─────┐
473
+ * │ foo ┆ bar ┆ ham │
474
+ * │ --- ┆ --- ┆ --- │
475
+ * │ i64 ┆ i64 ┆ str │
476
+ * ╞═════╪═════╪═════╡
477
+ * │ 1 ┆ 6 ┆ a │
478
+ * └─────┴─────┴─────┘
479
+ * ```
480
+ */
481
+ filter(predicate: any): DataFrame<S>;
482
+ /**
483
+ * Find the index of a column by name.
484
+ * ___
485
+ * @param name -Name of the column to find.
486
+ * @example
487
+ * ```
488
+ * > const df = pl.DataFrame({
489
+ * ... "foo": [1, 2, 3],
490
+ * ... "bar": [6, 7, 8],
491
+ * ... "ham": ['a', 'b', 'c']
492
+ * ... });
493
+ * > df.findIdxByName("ham"))
494
+ * 2
495
+ * ```
496
+ */
497
+ findIdxByName(name: keyof S): number;
498
+ /**
499
+ * __Apply a horizontal reduction on a DataFrame.__
500
+ *
501
+ * This can be used to effectively determine aggregations on a row level,
502
+ * and can be applied to any DataType that can be supercasted (casted to a similar parent type).
503
+ *
504
+ * An example of the supercast rules when applying an arithmetic operation on two DataTypes are for instance:
505
+ * - Int8 + Utf8 = Utf8
506
+ * - Float32 + Int64 = Float32
507
+ * - Float32 + Float64 = Float64
508
+ * ___
509
+ * @param operation - function that takes two `Series` and returns a `Series`.
510
+ * @returns Series
511
+ * @example
512
+ * ```
513
+ * > // A horizontal sum operation
514
+ * > let df = pl.DataFrame({
515
+ * ... "a": [2, 1, 3],
516
+ * ... "b": [1, 2, 3],
517
+ * ... "c": [1.0, 2.0, 3.0]
518
+ * ... });
519
+ * > df.fold((s1, s2) => s1.plus(s2))
520
+ * Series: 'a' [f64]
521
+ * [
522
+ * 4
523
+ * 5
524
+ * 9
525
+ * ]
526
+ * > // A horizontal minimum operation
527
+ * > df = pl.DataFrame({
528
+ * ... "a": [2, 1, 3],
529
+ * ... "b": [1, 2, 3],
530
+ * ... "c": [1.0, 2.0, 3.0]
531
+ * ... });
532
+ * > df.fold((s1, s2) => s1.zipWith(s1.lt(s2), s2))
533
+ * Series: 'a' [f64]
534
+ * [
535
+ * 1
536
+ * 1
537
+ * 3
538
+ * ]
539
+ * > // A horizontal string concatenation
540
+ * > df = pl.DataFrame({
541
+ * ... "a": ["foo", "bar", 2],
542
+ * ... "b": [1, 2, 3],
543
+ * ... "c": [1.0, 2.0, 3.0]
544
+ * ... })
545
+ * > df.fold((s1, s2) => s.plus(s2))
546
+ * Series: '' [f64]
547
+ * [
548
+ * "foo11"
549
+ * "bar22
550
+ * "233"
551
+ * ]
552
+ * ```
553
+ */
554
+ fold<D extends DataType, F extends (s1: SchemaToSeriesRecord<S>[keyof S] | Series<D>, s2: SchemaToSeriesRecord<S>[keyof S]) => Series<D>>(operation: F): Series<D>;
555
+ /**
556
+ * Check if DataFrame is equal to other.
557
+ * ___
558
+ * @param other DataFrame to compare.
559
+ * @param nullEqual Consider null values as equal.
560
+ * @example
561
+ * ```
562
+ * > const df1 = pl.DataFrame({
563
+ * ... "foo": [1, 2, 3],
564
+ * ... "bar": [6.0, 7.0, 8.0],
565
+ * ... "ham": ['a', 'b', 'c']
566
+ * ... })
567
+ * > const df2 = pl.DataFrame({
568
+ * ... "foo": [3, 2, 1],
569
+ * ... "bar": [8.0, 7.0, 6.0],
570
+ * ... "ham": ['c', 'b', 'a']
571
+ * ... })
572
+ * > df1.frameEqual(df1)
573
+ * true
574
+ * > df1.frameEqual(df2)
575
+ * false
576
+ * ```
577
+ */
578
+ frameEqual(other: DataFrame, nullEqual: boolean): boolean;
579
+ frameEqual(other: DataFrame): boolean;
580
+ /**
581
+ * Get a single column as Series by name.
582
+ *
583
+ * ---
584
+ * @example
585
+ * ```
586
+ * > const df = pl.DataFrame({
587
+ * ... foo: [1, 2, 3],
588
+ * ... bar: [6, null, 8],
589
+ * ... ham: ["a", "b", "c"],
590
+ * ... });
591
+ * // df: pl.DataFrame<{
592
+ * // foo: pl.Series<Float64, "foo">;
593
+ * // bar: pl.Series<Float64, "bar">;
594
+ * // ham: pl.Series<Utf8, "ham">;
595
+ * // }>
596
+ * > const column = df.getColumn("foo");
597
+ * // column: pl.Series<Float64, "foo">
598
+ * ```
599
+ */
600
+ getColumn<U extends keyof S>(name: U): SchemaToSeriesRecord<S>[U];
601
+ getColumn(name: string): Series;
602
+ /**
603
+ * Get the DataFrame as an Array of Series.
604
+ * ---
605
+ * @example
606
+ * ```
607
+ * > const df = pl.DataFrame({
608
+ * ... foo: [1, 2, 3],
609
+ * ... bar: [6, null, 8],
610
+ * ... ham: ["a", "b", "c"],
611
+ * ... });
612
+ * // df: pl.DataFrame<{
613
+ * // foo: pl.Series<Float64, "foo">;
614
+ * // bar: pl.Series<Float64, "bar">;
615
+ * // ham: pl.Series<Utf8, "ham">;
616
+ * // }>
617
+ * > const columns = df.getColumns();
618
+ * // columns: (pl.Series<Float64, "foo"> | pl.Series<Float64, "bar"> | pl.Series<Utf8, "ham">)[]
619
+ * ```
620
+ */
621
+ getColumns(): SchemaToSeriesRecord<S>[keyof S][];
622
+ /**
623
+ * Start a groupby operation.
624
+ * ___
625
+ * @param by - Column(s) to group by.
626
+ */
627
+ groupBy(...by: ColumnSelection[]): GroupBy;
628
+ /**
629
+ * Hash and combine the rows in this DataFrame. _(Hash value is UInt64)_
630
+ * @param k0 - seed parameter
631
+ * @param k1 - seed parameter
632
+ * @param k2 - seed parameter
633
+ * @param k3 - seed parameter
634
+ */
635
+ hashRows(k0?: number, k1?: number, k2?: number, k3?: number): Series;
636
+ hashRows(options: {
637
+ k0?: number;
638
+ k1?: number;
639
+ k2?: number;
640
+ k3?: number;
641
+ }): Series;
642
+ /**
643
+ * Get first N rows as DataFrame.
644
+ * ___
645
+ * @param length - Length of the head.
646
+ * @example
647
+ * ```
648
+ * > const df = pl.DataFrame({
649
+ * ... "foo": [1, 2, 3, 4, 5],
650
+ * ... "bar": [6, 7, 8, 9, 10],
651
+ * ... "ham": ['a', 'b', 'c', 'd','e']
652
+ * ... });
653
+ * > df.head(3)
654
+ * shape: (3, 3)
655
+ * ╭─────┬─────┬─────╮
656
+ * │ foo ┆ bar ┆ ham │
657
+ * │ --- ┆ --- ┆ --- │
658
+ * │ i64 ┆ i64 ┆ str │
659
+ * ╞═════╪═════╪═════╡
660
+ * │ 1 ┆ 6 ┆ "a" │
661
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
662
+ * │ 2 ┆ 7 ┆ "b" │
663
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
664
+ * │ 3 ┆ 8 ┆ "c" │
665
+ * ╰─────┴─────┴─────╯
666
+ * ```
667
+ */
668
+ head(length?: number): DataFrame<S>;
669
+ /**
670
+ * Return a new DataFrame grown horizontally by stacking multiple Series to it.
671
+ * @param columns - array of Series or DataFrame to stack
672
+ * @param inPlace - Modify in place
673
+ * @example
674
+ * ```
675
+ * > const df = pl.DataFrame({
676
+ * ... "foo": [1, 2, 3],
677
+ * ... "bar": [6, 7, 8],
678
+ * ... "ham": ['a', 'b', 'c']
679
+ * ... });
680
+ * // df: pl.DataFrame<{
681
+ * // foo: pl.Series<Float64, "foo">;
682
+ * // bar: pl.Series<Float64, "bar">;
683
+ * // ham: pl.Series<Utf8, "ham">;
684
+ * // }>
685
+ * > const x = pl.Series("apple", [10, 20, 30])
686
+ * // x: pl.Series<Float64, "apple">
687
+ * > df.hstack([x])
688
+ * // pl.DataFrame<{
689
+ * // foo: pl.Series<Float64, "foo">;
690
+ * // bar: pl.Series<Float64, "bar">;
691
+ * // ham: pl.Series<Utf8, "ham">;
692
+ * // apple: pl.Series<Float64, "apple">;
693
+ * // }>
694
+ * shape: (3, 4)
695
+ * ╭─────┬─────┬─────┬───────╮
696
+ * │ foo ┆ bar ┆ ham ┆ apple │
697
+ * │ --- ┆ --- ┆ --- ┆ --- │
698
+ * │ i64 ┆ i64 ┆ str ┆ i64 │
699
+ * ╞═════╪═════╪═════╪═══════╡
700
+ * │ 1 ┆ 6 ┆ "a" ┆ 10 │
701
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
702
+ * │ 2 ┆ 7 ┆ "b" ┆ 20 │
703
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
704
+ * │ 3 ┆ 8 ┆ "c" ┆ 30 │
705
+ * ╰─────┴─────┴─────┴───────╯
706
+ * ```
707
+ */
708
+ hstack(columns: Array<Series> | DataFrame, inPlace?: boolean): void;
709
+ hstack<S2 extends Schema = Schema>(columns: DataFrame<S2>): DataFrame<Simplify<S & S2>>;
710
+ hstack<U extends Series[]>(columns: U): DataFrame<Simplify<S & {
711
+ [K in U[number] as K["name"]]: K;
712
+ }>>;
713
+ hstack(columns: Array<Series> | DataFrame, inPlace?: boolean): void;
714
+ /**
715
+ * Insert a Series at a certain column index. This operation is in place.
716
+ * @param index - Column position to insert the new `Series` column.
717
+ * @param series - `Series` to insert
718
+ */
719
+ insertAtIdx(index: number, series: Series): void;
720
+ /**
721
+ * Interpolate intermediate values. The interpolation method is linear.
722
+ */
723
+ interpolate(): DataFrame<S>;
724
+ /**
725
+ * Get a mask of all duplicated rows in this DataFrame.
726
+ */
727
+ isDuplicated(): Series;
728
+ /**
729
+ * Check if the dataframe is empty
730
+ */
731
+ isEmpty(): boolean;
732
+ /**
733
+ * Get a mask of all unique rows in this DataFrame.
734
+ */
735
+ isUnique(): Series;
736
+ /**
737
+ * __SQL like joins.__
738
+ * @param other - DataFrame to join with.
739
+ * @param options
740
+ * @param options.on - Name(s) of the join columns in both DataFrames.
741
+ * @param options.how - Join strategy {'inner', 'left', 'right', 'full', 'semi', 'anti', 'cross'}
742
+ * @param options.suffix - Suffix to append to columns with a duplicate name.
743
+ * @param options.coalesce - Coalescing behavior (merging of join columns). default: undefined
744
+ * - **undefined** - *(Default)* Coalesce unless `how='full'` is specified.
745
+ * - **true** - Always coalesce join columns.
746
+ * - **false** - Never coalesce join columns.
747
+ * @param options.validate - Checks if join is of specified type. default: m:m
748
+ valid options: {'m:m', 'm:1', '1:m', '1:1'}
749
+ * - **m:m** - *(Default)* Many-to-many (default). Does not result in checks.
750
+ * - **1:1** - One-to-one. Checks if join keys are unique in both left and right datasets.
751
+ * - **1:m** - One-to-many. Checks if join keys are unique in left dataset.
752
+ * - **m:1** - Many-to-one. Check if join keys are unique in right dataset.
753
+ * @see {@link SameNameColumnJoinOptions}
754
+ * @example
755
+ * ```
756
+ * > const df = pl.DataFrame({
757
+ * ... "foo": [1, 2, 3],
758
+ * ... "bar": [6.0, 7.0, 8.0],
759
+ * ... "ham": ['a', 'b', 'c']
760
+ * ... });
761
+ * > const otherDF = pl.DataFrame({
762
+ * ... "apple": ['x', 'y', 'z'],
763
+ * ... "ham": ['a', 'b', 'd']
764
+ * ... });
765
+ * > df.join(otherDF, {on: 'ham'})
766
+ * shape: (2, 4)
767
+ * ╭─────┬─────┬─────┬───────╮
768
+ * │ foo ┆ bar ┆ ham ┆ apple │
769
+ * │ --- ┆ --- ┆ --- ┆ --- │
770
+ * │ i64 ┆ f64 ┆ str ┆ str │
771
+ * ╞═════╪═════╪═════╪═══════╡
772
+ * │ 1 ┆ 6 ┆ "a" ┆ "x" │
773
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
774
+ * │ 2 ┆ 7 ┆ "b" ┆ "y" │
775
+ * ╰─────┴─────┴─────┴───────╯
776
+ * ```
777
+ */
778
+ join<S2 extends Schema, const Opts extends SameNameColumnJoinOptions<Extract<keyof S, string>, Extract<keyof S2, string>>>(other: DataFrame<S2>, options: Opts & SameNameColumnJoinOptions): DataFrame<JoinSchemas<S, S2, Opts>>;
779
+ /**
780
+ * __SQL like joins with different names for left and right dataframes.__
781
+ * @param other - DataFrame to join with.
782
+ * @param options
783
+ * @param options.leftOn - Name(s) of the left join column(s).
784
+ * @param options.rightOn - Name(s) of the right join column(s).
785
+ * @param options.how - Join strategy
786
+ * @param options.suffix - Suffix to append to columns with a duplicate name.
787
+ * @param options.coalesce - Coalescing behavior (merging of join columns).
788
+ * @see {@link DifferentNameColumnJoinOptions}
789
+ * @example
790
+ * ```
791
+ * > const df = pl.DataFrame({
792
+ * ... "foo": [1, 2, 3],
793
+ * ... "bar": [6.0, 7.0, 8.0],
794
+ * ... "ham": ['a', 'b', 'c']
795
+ * ... });
796
+ * > const otherDF = pl.DataFrame({
797
+ * ... "apple": ['x', 'y', 'z'],
798
+ * ... "ham": ['a', 'b', 'd']
799
+ * ... });
800
+ * > df.join(otherDF, {leftOn: 'ham', rightOn: 'ham'})
801
+ * shape: (2, 4)
802
+ * ╭─────┬─────┬─────┬───────╮
803
+ * │ foo ┆ bar ┆ ham ┆ apple │
804
+ * │ --- ┆ --- ┆ --- ┆ --- │
805
+ * │ i64 ┆ f64 ┆ str ┆ str │
806
+ * ╞═════╪═════╪═════╪═══════╡
807
+ * │ 1 ┆ 6 ┆ "a" ┆ "x" │
808
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌┤
809
+ * │ 2 ┆ 7 ┆ "b" ┆ "y" │
810
+ * ╰─────┴─────┴─────┴───────╯
811
+ * ```
812
+ */
813
+ join<S2 extends Schema, const Opts extends DifferentNameColumnJoinOptions<Extract<keyof S, string>, Extract<keyof S2, string>>>(other: DataFrame<S2>, options: Opts & DifferentNameColumnJoinOptions): DataFrame<JoinSchemas<S, S2, Opts>>;
814
+ /**
815
+ * __SQL like cross joins.__
816
+ * @param other - DataFrame to join with.
817
+ * @param options
818
+ * @param options.how - Join strategy
819
+ * @param options.suffix - Suffix to append to columns with a duplicate name.
820
+ * @param options.coalesce - Coalescing behavior (merging of join columns).
821
+ * @see {@link CrossJoinOptions}
822
+ * @example
823
+ * ```
824
+ * > const df = pl.DataFrame({
825
+ * ... "foo": [1, 2],
826
+ * ... "bar": [6.0, 7.0],
827
+ * ... "ham": ['a', 'b']
828
+ * ... });
829
+ * > const otherDF = pl.DataFrame({
830
+ * ... "apple": ['x', 'y'],
831
+ * ... "ham": ['a', 'b']
832
+ * ... });
833
+ * > df.join(otherDF, {how: 'cross'})
834
+ * shape: (4, 5)
835
+ * ╭─────┬─────┬─────┬───────┬───────────╮
836
+ * │ foo ┆ bar ┆ ham ┆ apple ┆ ham_right │
837
+ * │ --- ┆ --- ┆ --- ┆ --- ┆ --- │
838
+ * │ f64 ┆ f64 ┆ str ┆ str ┆ str │
839
+ * ╞═════╪═════╪═════╪═══════╪═══════════╡
840
+ * │ 1.0 ┆ 6.0 ┆ a ┆ x ┆ a │
841
+ * │ 1.0 ┆ 6.0 ┆ a ┆ y ┆ b │
842
+ * │ 2.0 ┆ 7.0 ┆ b ┆ x ┆ a │
843
+ * │ 2.0 ┆ 7.0 ┆ b ┆ y ┆ b │
844
+ * ╰─────┴─────┴─────┴───────┴───────────╯
845
+ * ```
846
+ */
847
+ join<S2 extends Schema, const Opts extends CrossJoinOptions>(other: DataFrame<S2>, options: Opts & CrossJoinOptions): DataFrame<JoinSchemas<S, S2, Opts>>;
848
+ /**
849
+ * Perform an asof join. This is similar to a left-join except that we
850
+ * match on nearest key rather than equal keys.
851
+ *
852
+ * Both DataFrames must be sorted by the asofJoin key.
853
+ *
854
+ * For each row in the left DataFrame:
855
+ * - A "backward" search selects the last row in the right DataFrame whose
856
+ * 'on' key is less than or equal to the left's key.
857
+ *
858
+ * - A "forward" search selects the first row in the right DataFrame whose
859
+ * 'on' key is greater than or equal to the left's key.
860
+ *
861
+ * - A "nearest" search selects the last row in the right DataFrame whose value
862
+ * is nearest to the left's key. String keys are not currently supported for a
863
+ * nearest search.
864
+ *
865
+ * The default is "backward".
866
+ *
867
+ * @param other DataFrame to join with.
868
+ * @param options.leftOn Join column of the left DataFrame.
869
+ * @param options.rightOn Join column of the right DataFrame.
870
+ * @param options.on Join column of both DataFrames. If set, `leftOn` and `rightOn` should be undefined.
871
+ * @param options.byLeft join on these columns before doing asof join
872
+ * @param options.byRight join on these columns before doing asof join
873
+ * @param options.strategy One of 'forward', 'backward', 'nearest'
874
+ * @param options.suffix Suffix to append to columns with a duplicate name.
875
+ * @param options.tolerance
876
+ * Numeric tolerance. By setting this the join will only be done if the near keys are within this distance.
877
+ * If an asof join is done on columns of dtype "Date", "Datetime" you
878
+ * use the following string language:
879
+ *
880
+ * - 1ns *(1 nanosecond)*
881
+ * - 1us *(1 microsecond)*
882
+ * - 1ms *(1 millisecond)*
883
+ * - 1s *(1 second)*
884
+ * - 1m *(1 minute)*
885
+ * - 1h *(1 hour)*
886
+ * - 1d *(1 day)*
887
+ * - 1w *(1 week)*
888
+ * - 1mo *(1 calendar month)*
889
+ * - 1y *(1 calendar year)*
890
+ * - 1i *(1 index count)*
891
+ *
892
+ * Or combine them:
893
+ * - "3d12h4m25s" # 3 days, 12 hours, 4 minutes, and 25 seconds
894
+ * @param options.allowParallel Allow the physical plan to optionally evaluate the computation of both DataFrames up to the join in parallel.
895
+ * @param options.forceParallel Force the physical plan to evaluate the computation of both DataFrames up to the join in parallel.
896
+ * @param options.checkSortedness
897
+ * Check the sortedness of the asof keys. If the keys are not sorted Polars
898
+ * will error, or in case of 'by' argument raise a warning. This might become
899
+ * a hard error in the future.
900
+ *
901
+ * @example
902
+ * ```
903
+ * > const gdp = pl.DataFrame({
904
+ * ... date: [
905
+ * ... new Date('2016-01-01'),
906
+ * ... new Date('2017-01-01'),
907
+ * ... new Date('2018-01-01'),
908
+ * ... new Date('2019-01-01'),
909
+ * ... ], // note record date: Jan 1st (sorted!)
910
+ * ... gdp: [4164, 4411, 4566, 4696],
911
+ * ... })
912
+ * > const population = pl.DataFrame({
913
+ * ... date: [
914
+ * ... new Date('2016-05-12'),
915
+ * ... new Date('2017-05-12'),
916
+ * ... new Date('2018-05-12'),
917
+ * ... new Date('2019-05-12'),
918
+ * ... ], // note record date: May 12th (sorted!)
919
+ * ... "population": [82.19, 82.66, 83.12, 83.52],
920
+ * ... })
921
+ * > population.joinAsof(
922
+ * ... gdp,
923
+ * ... {leftOn:"date", rightOn:"date", strategy:"backward"}
924
+ * ... )
925
+ * shape: (4, 3)
926
+ * ┌─────────────────────┬────────────┬──────┐
927
+ * │ date ┆ population ┆ gdp │
928
+ * │ --- ┆ --- ┆ --- │
929
+ * │ datetime[μs] ┆ f64 ┆ i64 │
930
+ * ╞═════════════════════╪════════════╪══════╡
931
+ * │ 2016-05-12 00:00:00 ┆ 82.19 ┆ 4164 │
932
+ * ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
933
+ * │ 2017-05-12 00:00:00 ┆ 82.66 ┆ 4411 │
934
+ * ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
935
+ * │ 2018-05-12 00:00:00 ┆ 83.12 ┆ 4566 │
936
+ * ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
937
+ * │ 2019-05-12 00:00:00 ┆ 83.52 ┆ 4696 │
938
+ * └─────────────────────┴────────────┴──────┘
939
+ * ```
940
+ */
941
+ joinAsof(other: DataFrame, options: {
942
+ leftOn?: string;
943
+ rightOn?: string;
944
+ on?: string;
945
+ byLeft?: string | string[];
946
+ byRight?: string | string[];
947
+ by?: string | string[];
948
+ strategy?: "backward" | "forward" | "nearest";
949
+ suffix?: string;
950
+ tolerance?: number | string;
951
+ allowParallel?: boolean;
952
+ forceParallel?: boolean;
953
+ checkSortedness?: boolean;
954
+ }): DataFrame;
955
+ lazy(): LazyDataFrame<S>;
956
+ /**
957
+ * Get first N rows as DataFrame.
958
+ * @see {@link head}
959
+ */
960
+ limit(length?: number): DataFrame<S>;
961
+ map<ReturnT>(func: (row: any[], i: number, arr: any[][]) => ReturnT): ReturnT[];
962
+ /**
963
+ * Aggregate the columns of this DataFrame to their maximum value.
964
+ * ___
965
+ * @param axis - either 0 or 1
966
+ * @example
967
+ * ```
968
+ * > const df = pl.DataFrame({
969
+ * ... "foo": [1, 2, 3],
970
+ * ... "bar": [6, 7, 8],
971
+ * ... "ham": ['a', 'b', 'c']
972
+ * ... });
973
+ * > df.max()
974
+ * shape: (1, 3)
975
+ * ╭─────┬─────┬──────╮
976
+ * │ foo ┆ bar ┆ ham │
977
+ * │ --- ┆ --- ┆ --- │
978
+ * │ i64 ┆ i64 ┆ str │
979
+ * ╞═════╪═════╪══════╡
980
+ * │ 3 ┆ 8 ┆ null │
981
+ * ╰─────┴─────┴──────╯
982
+ * ```
983
+ */
984
+ max(axis: 0): DataFrame<S>;
985
+ max(axis: 1): Series;
986
+ max(): DataFrame<S>;
987
+ /**
988
+ * Aggregate the columns of this DataFrame to their mean value.
989
+ * ___
990
+ *
991
+ * @param axis - either 0 or 1
992
+ * @param nullStrategy - this argument is only used if axis == 1
993
+ */
994
+ mean(axis: 1, nullStrategy?: "ignore" | "propagate"): Series;
995
+ mean(): DataFrame<S>;
996
+ mean(axis: 0): DataFrame<S>;
997
+ mean(axis: 1): Series;
998
+ /**
999
+ * Aggregate the columns of this DataFrame to their median value.
1000
+ * ___
1001
+ * @example
1002
+ * ```
1003
+ * > const df = pl.DataFrame({
1004
+ * ... "foo": [1, 2, 3],
1005
+ * ... "bar": [6, 7, 8],
1006
+ * ... "ham": ['a', 'b', 'c']
1007
+ * ... });
1008
+ * > df.median();
1009
+ * shape: (1, 3)
1010
+ * ╭─────┬─────┬──────╮
1011
+ * │ foo ┆ bar ┆ ham │
1012
+ * │ --- ┆ --- ┆ --- │
1013
+ * │ f64 ┆ f64 ┆ str │
1014
+ * ╞═════╪═════╪══════╡
1015
+ * │ 2 ┆ 7 ┆ null │
1016
+ * ╰─────┴─────┴──────╯
1017
+ * ```
1018
+ */
1019
+ median(): DataFrame<S>;
1020
+ /**
1021
+ * Unpivot a DataFrame from wide to long format.
1022
+ * ___
1023
+ *
1024
+ * @param idVars - Columns to use as identifier variables.
1025
+ * @param valueVars - Values to use as value variables.
1026
+ * @param options.variableName - Name to give to the `variable` column. Defaults to "variable"
1027
+ * @param options.valueName - Name to give to the `value` column. Defaults to "value"
1028
+ * @example
1029
+ * ```
1030
+ * > const df1 = pl.DataFrame({
1031
+ * ... 'id': [1],
1032
+ * ... 'asset_key_1': ['123'],
1033
+ * ... 'asset_key_2': ['456'],
1034
+ * ... 'asset_key_3': ['abc'],
1035
+ * ... });
1036
+ * > df1.unpivot('id', ['asset_key_1', 'asset_key_2', 'asset_key_3']);
1037
+ * shape: (3, 3)
1038
+ * ┌─────┬─────────────┬───────┐
1039
+ * │ id ┆ variable ┆ value │
1040
+ * │ --- ┆ --- ┆ --- │
1041
+ * │ f64 ┆ str ┆ str │
1042
+ * ╞═════╪═════════════╪═══════╡
1043
+ * │ 1 ┆ asset_key_1 ┆ 123 │
1044
+ * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
1045
+ * │ 1 ┆ asset_key_2 ┆ 456 │
1046
+ * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
1047
+ * │ 1 ┆ asset_key_3 ┆ abc │
1048
+ * └─────┴─────────────┴───────┘
1049
+ * ```
1050
+ */
1051
+ unpivot(idVars: ColumnSelection, valueVars: ColumnSelection, options?: {
1052
+ variableName?: string | null;
1053
+ valueName?: string | null;
1054
+ }): DataFrame;
1055
+ /**
1056
+ * Aggregate the columns of this DataFrame to their minimum value.
1057
+ * ___
1058
+ * @param axis - either 0 or 1
1059
+ * @example
1060
+ * ```
1061
+ * > const df = pl.DataFrame({
1062
+ * ... "foo": [1, 2, 3],
1063
+ * ... "bar": [6, 7, 8],
1064
+ * ... "ham": ['a', 'b', 'c']
1065
+ * ... });
1066
+ * > df.min();
1067
+ * shape: (1, 3)
1068
+ * ╭─────┬─────┬──────╮
1069
+ * │ foo ┆ bar ┆ ham │
1070
+ * │ --- ┆ --- ┆ --- │
1071
+ * │ i64 ┆ i64 ┆ str │
1072
+ * ╞═════╪═════╪══════╡
1073
+ * │ 1 ┆ 6 ┆ null │
1074
+ * ╰─────┴─────┴──────╯
1075
+ * ```
1076
+ */
1077
+ min(axis: 0): DataFrame<S>;
1078
+ min(axis: 1): Series;
1079
+ min(): DataFrame<S>;
1080
+ /**
1081
+ * Get number of chunks used by the ChunkedArrays of this DataFrame.
1082
+ */
1083
+ nChunks(): number;
1084
+ /**
1085
+ * Create a new DataFrame that shows the null counts per column.
1086
+ * ___
1087
+ * @example
1088
+ * ```
1089
+ * > const df = pl.DataFrame({
1090
+ * ... "foo": [1, null, 3],
1091
+ * ... "bar": [6, 7, null],
1092
+ * ... "ham": ['a', 'b', 'c']
1093
+ * ... });
1094
+ * > df.nullCount();
1095
+ * shape: (1, 3)
1096
+ * ┌─────┬─────┬─────┐
1097
+ * │ foo ┆ bar ┆ ham │
1098
+ * │ --- ┆ --- ┆ --- │
1099
+ * │ u32 ┆ u32 ┆ u32 │
1100
+ * ╞═════╪═════╪═════╡
1101
+ * │ 1 ┆ 1 ┆ 0 │
1102
+ * └─────┴─────┴─────┘
1103
+ * ```
1104
+ */
1105
+ nullCount(): DataFrame<{
1106
+ [K in keyof S]: JsToDtype<number>;
1107
+ }>;
1108
+ partitionBy(cols: string | string[], stable?: boolean, includeKey?: boolean): DataFrame<S>[];
1109
+ partitionBy<T>(cols: string | string[], stable: boolean, includeKey: boolean, mapFn: (df: DataFrame) => T): T[];
1110
+ /**
1111
+ * Create a spreadsheet-style pivot table as a DataFrame.
1112
+ *
1113
+ * @param values The existing column(s) of values which will be moved under the new columns from index. If an
1114
+ * aggregation is specified, these are the values on which the aggregation will be computed.
1115
+ * If None, all remaining columns not specified on `on` and `index` will be used.
1116
+ * At least one of `index` and `values` must be specified.
1117
+ * @param options.index The column(s) that remain from the input to the output. The output DataFrame will have one row
1118
+ * for each unique combination of the `index`'s values.
1119
+ * If None, all remaining columns not specified on `on` and `values` will be used. At least one
1120
+ * of `index` and `values` must be specified.
1121
+ * @param options.on The column(s) whose values will be used as the new columns of the output DataFrame.
1122
+ * @param options.aggregateFunc
1123
+ * Any of:
1124
+ * - "sum"
1125
+ * - "max"
1126
+ * - "min"
1127
+ * - "mean"
1128
+ * - "median"
1129
+ * - "first"
1130
+ * - "last"
1131
+ * - "count"
1132
+ * Defaults to "first"
1133
+ * @param options.maintainOrder Sort the grouped keys so that the output order is predictable.
1134
+ * @param options.sortColumns Sort the transposed columns by name. Default is by order of discovery.
1135
+ * @param options.separator Used as separator/delimiter in generated column names.
1136
+ * @example
1137
+ * ```
1138
+ * > const df = pl.DataFrame(
1139
+ * ... {
1140
+ * ... "foo": ["one", "one", "one", "two", "two", "two"],
1141
+ * ... "bar": ["A", "B", "C", "A", "B", "C"],
1142
+ * ... "baz": [1, 2, 3, 4, 5, 6],
1143
+ * ... }
1144
+ * ... );
1145
+ * > df.pivot("baz", {index:"foo", on:"bar"});
1146
+ * shape: (2, 4)
1147
+ * ┌─────┬─────┬─────┬─────┐
1148
+ * │ foo ┆ A ┆ B ┆ C │
1149
+ * │ --- ┆ --- ┆ --- ┆ --- │
1150
+ * │ str ┆ f64 ┆ f64 ┆ f64 │
1151
+ * ╞═════╪═════╪═════╪═════╡
1152
+ * │ one ┆ 1 ┆ 2 ┆ 3 │
1153
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
1154
+ * │ two ┆ 4 ┆ 5 ┆ 6 │
1155
+ * └─────┴─────┴─────┴─────┘
1156
+ * ```
1157
+ */
1158
+ pivot(values: string | string[], options: {
1159
+ index: string | string[];
1160
+ on: string | string[];
1161
+ aggregateFunc?: "sum" | "max" | "min" | "mean" | "median" | "first" | "last" | "count" | Expr;
1162
+ maintainOrder?: boolean;
1163
+ sortColumns?: boolean;
1164
+ separator?: string;
1165
+ }): DataFrame;
1166
+ pivot(options: {
1167
+ values: string | string[];
1168
+ index: string | string[];
1169
+ on: string | string[];
1170
+ aggregateFunc?: "sum" | "max" | "min" | "mean" | "median" | "first" | "last" | "count" | Expr;
1171
+ maintainOrder?: boolean;
1172
+ sortColumns?: boolean;
1173
+ separator?: string;
1174
+ }): DataFrame;
1175
+ /**
1176
+ * Aggregate the columns of this DataFrame to their quantile value.
1177
+ * @example
1178
+ * ```
1179
+ * > const df = pl.DataFrame({
1180
+ * ... "foo": [1, 2, 3],
1181
+ * ... "bar": [6, 7, 8],
1182
+ * ... "ham": ['a', 'b', 'c']
1183
+ * ... });
1184
+ * > df.quantile(0.5);
1185
+ * shape: (1, 3)
1186
+ * ╭─────┬─────┬──────╮
1187
+ * │ foo ┆ bar ┆ ham │
1188
+ * │ --- ┆ --- ┆ --- │
1189
+ * │ i64 ┆ i64 ┆ str │
1190
+ * ╞═════╪═════╪══════╡
1191
+ * │ 2 ┆ 7 ┆ null │
1192
+ * ╰─────┴─────┴──────╯
1193
+ * ```
1194
+ */
1195
+ quantile(quantile: number): DataFrame<S>;
1196
+ /**
1197
+ * __Rechunk the data in this DataFrame to a contiguous allocation.__
1198
+ *
1199
+ * This will make sure all subsequent operations have optimal and predictable performance.
1200
+ */
1201
+ rechunk(): DataFrame<S>;
1202
+ /**
1203
+ * __Rename column names.__
1204
+ * ___
1205
+ *
1206
+ * @param mapping - Key value pairs that map from old name to new name.
1207
+ * @example
1208
+ * ```
1209
+ * > const df = pl.DataFrame({
1210
+ * ... "foo": [1, 2, 3],
1211
+ * ... "bar": [6, 7, 8],
1212
+ * ... "ham": ['a', 'b', 'c']
1213
+ * ... });
1214
+ * // df: pl.DataFrame<{
1215
+ * // foo: pl.Series<Float64, "foo">;
1216
+ * // bar: pl.Series<Float64, "bar">;
1217
+ * // ham: pl.Series<Utf8, "ham">;
1218
+ * // }>
1219
+ * > df.rename({"foo": "apple"});
1220
+ * ╭───────┬─────┬─────╮
1221
+ * │ apple ┆ bar ┆ ham │
1222
+ * │ --- ┆ --- ┆ --- │
1223
+ * │ i64 ┆ i64 ┆ str │
1224
+ * ╞═══════╪═════╪═════╡
1225
+ * │ 1 ┆ 6 ┆ "a" │
1226
+ * ├╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
1227
+ * │ 2 ┆ 7 ┆ "b" │
1228
+ * ├╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
1229
+ * │ 3 ┆ 8 ┆ "c" │
1230
+ * ╰───────┴─────┴─────╯
1231
+ * ```
1232
+ */
1233
+ rename<const U extends Partial<Record<keyof S, string>>>(mapping: U): DataFrame<{
1234
+ [K in keyof S as U[K] extends string ? U[K] : K]: S[K];
1235
+ }>;
1236
+ rename(mapping: Record<string, string>): DataFrame;
1237
+ /**
1238
+ * Replace a column at an index location.
1239
+ *
1240
+ * Warning: typescript cannot encode type mutation,
1241
+ * so the type of the DataFrame will be incorrect. cast the type of dataframe manually.
1242
+ * ___
1243
+ * @param index - Column index
1244
+ * @param newColumn - New column to insert
1245
+ * @example
1246
+ * ```
1247
+ * > const df: pl.DataFrame = pl.DataFrame({
1248
+ * ... "foo": [1, 2, 3],
1249
+ * ... "bar": [6, 7, 8],
1250
+ * ... "ham": ['a', 'b', 'c']
1251
+ * ... });
1252
+ * // df: pl.DataFrame<{
1253
+ * // foo: pl.Series<Float64, "foo">;
1254
+ * // bar: pl.Series<Float64, "bar">;
1255
+ * // ham: pl.Series<Utf8, "ham">;
1256
+ * // }>
1257
+ * > const x = pl.Series("apple", [10, 20, 30]);
1258
+ * // x: pl.Series<Float64, "apple">
1259
+ * > df.replaceAtIdx(0, x);
1260
+ * // df: pl.DataFrame<{
1261
+ * // foo: pl.Series<Float64, "foo">; <- notice how the type is still the same!
1262
+ * // bar: pl.Series<Float64, "bar">;
1263
+ * // ham: pl.Series<Utf8, "ham">;
1264
+ * // }>
1265
+ * shape: (3, 3)
1266
+ * ╭───────┬─────┬─────╮
1267
+ * │ apple ┆ bar ┆ ham │
1268
+ * │ --- ┆ --- ┆ --- │
1269
+ * │ i64 ┆ i64 ┆ str │
1270
+ * ╞═══════╪═════╪═════╡
1271
+ * │ 10 ┆ 6 ┆ "a" │
1272
+ * ├╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
1273
+ * │ 20 ┆ 7 ┆ "b" │
1274
+ * ├╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
1275
+ * │ 30 ┆ 8 ┆ "c" │
1276
+ * ╰───────┴─────┴─────╯
1277
+ * ```
1278
+ */
1279
+ replaceAtIdx(index: number, newColumn: Series): void;
1280
+ /**
1281
+ * Get a row as Array
1282
+ * @param index - row index
1283
+ * @example
1284
+ * ```
1285
+ * > const df = pl.DataFrame({
1286
+ * ... "foo": [1, 2, 3],
1287
+ * ... "bar": [6, 7, 8],
1288
+ * ... "ham": ['a', 'b', 'c']
1289
+ * ... });
1290
+ * > df.row(2)
1291
+ * [3, 8, 'c']
1292
+ * ```
1293
+ */
1294
+ row(index: number): Array<any>;
1295
+ /**
1296
+ * Convert columnar data to rows as arrays
1297
+ */
1298
+ rows(): Array<Array<any>>;
1299
+ /**
1300
+ * @example
1301
+ * ```
1302
+ * > const df: pl.DataFrame = pl.DataFrame({
1303
+ * ... "foo": [1, 2, 3],
1304
+ * ... "bar": [6, 7, 8],
1305
+ * ... "ham": ['a', 'b', 'c']
1306
+ * ... });
1307
+ * // df: pl.DataFrame<{
1308
+ * // foo: pl.Series<Float64, "foo">;
1309
+ * // bar: pl.Series<Float64, "bar">;
1310
+ * // ham: pl.Series<Utf8, "ham">;
1311
+ * // }>
1312
+ * > df.schema
1313
+ * // {
1314
+ * // foo: Float64;
1315
+ * // bar: Float64;
1316
+ * // ham: Utf8;
1317
+ * // }
1318
+ * ```
1319
+ */
1320
+ get schema(): S;
1321
+ /**
1322
+ * Select columns from this DataFrame.
1323
+ * ___
1324
+ * @param columns - Column or columns to select.
1325
+ * @example
1326
+ * ```
1327
+ * > const df = pl.DataFrame({
1328
+ * ... "foo": [1, 2, 3],
1329
+ * ... "bar": [6, 7, 8],
1330
+ * ... "ham": ['a', 'b', 'c']
1331
+ * ... });
1332
+ * // df: pl.DataFrame<{
1333
+ * // foo: pl.Series<Float64, "foo">;
1334
+ * // bar: pl.Series<Float64, "bar">;
1335
+ * // ham: pl.Series<Utf8, "ham">;
1336
+ * // }>
1337
+ * > df.select('foo');
1338
+ * // pl.DataFrame<{
1339
+ * // foo: pl.Series<Float64, "foo">;
1340
+ * // }>
1341
+ * shape: (3, 1)
1342
+ * ┌─────┐
1343
+ * │ foo │
1344
+ * │ --- │
1345
+ * │ i64 │
1346
+ * ╞═════╡
1347
+ * │ 1 │
1348
+ * ├╌╌╌╌╌┤
1349
+ * │ 2 │
1350
+ * ├╌╌╌╌╌┤
1351
+ * │ 3 │
1352
+ * └─────┘
1353
+ * ```
1354
+ */
1355
+ select<U extends keyof S>(...columns: U[]): DataFrame<{
1356
+ [P in U]: S[P];
1357
+ }>;
1358
+ select(...columns: ExprOrString[]): DataFrame<S>;
1359
+ /**
1360
+ * Shift the values by a given period and fill the parts that will be empty due to this operation
1361
+ * with `Nones`.
1362
+ * ___
1363
+ * @param periods - Number of places to shift (may be negative).
1364
+ * @example
1365
+ * ```
1366
+ * > const df = pl.DataFrame({
1367
+ * ... "foo": [1, 2, 3],
1368
+ * ... "bar": [6, 7, 8],
1369
+ * ... "ham": ['a', 'b', 'c']
1370
+ * ... });
1371
+ * > df.shift(1);
1372
+ * shape: (3, 3)
1373
+ * ┌──────┬──────┬──────┐
1374
+ * │ foo ┆ bar ┆ ham │
1375
+ * │ --- ┆ --- ┆ --- │
1376
+ * │ i64 ┆ i64 ┆ str │
1377
+ * ╞══════╪══════╪══════╡
1378
+ * │ null ┆ null ┆ null │
1379
+ * ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
1380
+ * │ 1 ┆ 6 ┆ "a" │
1381
+ * ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
1382
+ * │ 2 ┆ 7 ┆ "b" │
1383
+ * └──────┴──────┴──────┘
1384
+ * > df.shift(-1)
1385
+ * shape: (3, 3)
1386
+ * ┌──────┬──────┬──────┐
1387
+ * │ foo ┆ bar ┆ ham │
1388
+ * │ --- ┆ --- ┆ --- │
1389
+ * │ i64 ┆ i64 ┆ str │
1390
+ * ╞══════╪══════╪══════╡
1391
+ * │ 2 ┆ 7 ┆ "b" │
1392
+ * ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
1393
+ * │ 3 ┆ 8 ┆ "c" │
1394
+ * ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
1395
+ * │ null ┆ null ┆ null │
1396
+ * └──────┴──────┴──────┘
1397
+ * ```
1398
+ */
1399
+ shift(periods: number): DataFrame<S>;
1400
+ shift({ periods }: {
1401
+ periods: number;
1402
+ }): DataFrame<S>;
1403
+ /**
1404
+ * Shift the values by a given period and fill the parts that will be empty due to this operation
1405
+ * with the result of the `fill_value` expression.
1406
+ * ___
1407
+ * @param n - Number of places to shift (may be negative).
1408
+ * @param fillValue - fill null values with this value.
1409
+ * @example
1410
+ * ```
1411
+ * > const df = pl.DataFrame({
1412
+ * ... "foo": [1, 2, 3],
1413
+ * ... "bar": [6, 7, 8],
1414
+ * ... "ham": ['a', 'b', 'c']
1415
+ * ... });
1416
+ * > df.shiftAndFill({n:1, fill_value:0});
1417
+ * shape: (3, 3)
1418
+ * ┌─────┬─────┬─────┐
1419
+ * │ foo ┆ bar ┆ ham │
1420
+ * │ --- ┆ --- ┆ --- │
1421
+ * │ i64 ┆ i64 ┆ str │
1422
+ * ╞═════╪═════╪═════╡
1423
+ * │ 0 ┆ 0 ┆ "0" │
1424
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
1425
+ * │ 1 ┆ 6 ┆ "a" │
1426
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
1427
+ * │ 2 ┆ 7 ┆ "b" │
1428
+ * └─────┴─────┴─────┘
1429
+ * ```
1430
+ */
1431
+ shiftAndFill(n: number, fillValue: number): DataFrame<S>;
1432
+ shiftAndFill({ n, fillValue, }: {
1433
+ n: number;
1434
+ fillValue: number;
1435
+ }): DataFrame<S>;
1436
+ /**
1437
+ * Shrink memory usage of this DataFrame to fit the exact capacity needed to hold the data.
1438
+ */
1439
+ shrinkToFit(): DataFrame<S>;
1440
+ shrinkToFit(inPlace: true): void;
1441
+ shrinkToFit({ inPlace }: {
1442
+ inPlace: true;
1443
+ }): void;
1444
+ /**
1445
+ * Slice this DataFrame over the rows direction.
1446
+ * ___
1447
+ * @param opts
1448
+ * @param opts.offset - Offset index.
1449
+ * @param opts.length - Length of the slice
1450
+ * @example
1451
+ * ```
1452
+ * > const df = pl.DataFrame({
1453
+ * ... "foo": [1, 2, 3],
1454
+ * ... "bar": [6.0, 7.0, 8.0],
1455
+ * ... "ham": ['a', 'b', 'c']
1456
+ * ... });
1457
+ * > df.slice(1, 2); // Alternatively `df.slice({offset:1, length:2})`
1458
+ * shape: (2, 3)
1459
+ * ┌─────┬─────┬─────┐
1460
+ * │ foo ┆ bar ┆ ham │
1461
+ * │ --- ┆ --- ┆ --- │
1462
+ * │ i64 ┆ i64 ┆ str │
1463
+ * ╞═════╪═════╪═════╡
1464
+ * │ 2 ┆ 7 ┆ "b" │
1465
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
1466
+ * │ 3 ┆ 8 ┆ "c" │
1467
+ * └─────┴─────┴─────┘
1468
+ * ```
1469
+ */
1470
+ slice({ offset, length }: {
1471
+ offset: number;
1472
+ length: number;
1473
+ }): DataFrame<S>;
1474
+ slice(offset: number, length: number): DataFrame<S>;
1475
+ /**
1476
+ * Sort the DataFrame by column.
1477
+ * ___
1478
+ * @param by - Column(s) to sort by. Accepts expression input, including selectors. Strings are parsed as column names.
1479
+ * @param descending - Sort in descending order. When sorting by multiple columns, can be specified per column by passing a sequence of booleans.
1480
+ * @param nullsLast - Place null values last; can specify a single boolean applying to all columns or a sequence of booleans for per-column control.
1481
+ * @param maintainOrder - Whether the order should be maintained if elements are equal.
1482
+ */
1483
+ sort(by: ColumnsOrExpr, descending?: boolean, nullsLast?: boolean, maintainOrder?: boolean): DataFrame<S>;
1484
+ sort({ by, descending, maintainOrder, }: {
1485
+ by: ColumnsOrExpr;
1486
+ descending?: boolean;
1487
+ nullsLast?: boolean;
1488
+ maintainOrder?: boolean;
1489
+ }): DataFrame<S>;
1490
+ /**
1491
+ * Aggregate the columns of this DataFrame to their standard deviation value.
1492
+ * ___
1493
+ * @example
1494
+ * ```
1495
+ * > const df = pl.DataFrame({
1496
+ * ... "foo": [1, 2, 3],
1497
+ * ... "bar": [6, 7, 8],
1498
+ * ... "ham": ['a', 'b', 'c']
1499
+ * ... });
1500
+ * > df.std();
1501
+ * shape: (1, 3)
1502
+ * ╭─────┬─────┬──────╮
1503
+ * │ foo ┆ bar ┆ ham │
1504
+ * │ --- ┆ --- ┆ --- │
1505
+ * │ f64 ┆ f64 ┆ str │
1506
+ * ╞═════╪═════╪══════╡
1507
+ * │ 1 ┆ 1 ┆ null │
1508
+ * ╰─────┴─────┴──────╯
1509
+ * ```
1510
+ */
1511
+ std(): DataFrame<S>;
1512
+ /**
1513
+ * Aggregate the columns of this DataFrame to their mean value.
1514
+ * ___
1515
+ *
1516
+ * @param axis - either 0 or 1
1517
+ * @param nullStrategy - this argument is only used if axis == 1
1518
+ */
1519
+ sum(axis: 1, nullStrategy?: "ignore" | "propagate"): Series;
1520
+ sum(): DataFrame<S>;
1521
+ sum(axis: 0): DataFrame<S>;
1522
+ sum(axis: 1): Series;
1523
+ /**
1524
+ * @example
1525
+ * ```
1526
+ * > const df = pl.DataFrame({
1527
+ * ... "letters": ["c", "c", "a", "c", "a", "b"],
1528
+ * ... "nrs": [1, 2, 3, 4, 5, 6]
1529
+ * ... });
1530
+ * > console.log(df.toString());
1531
+ * shape: (6, 2)
1532
+ * ╭─────────┬─────╮
1533
+ * │ letters ┆ nrs │
1534
+ * │ --- ┆ --- │
1535
+ * │ str ┆ i64 │
1536
+ * ╞═════════╪═════╡
1537
+ * │ "c" ┆ 1 │
1538
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
1539
+ * │ "c" ┆ 2 │
1540
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
1541
+ * │ "a" ┆ 3 │
1542
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
1543
+ * │ "c" ┆ 4 │
1544
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
1545
+ * │ "a" ┆ 5 │
1546
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
1547
+ * │ "b" ┆ 6 │
1548
+ * ╰─────────┴─────╯
1549
+ * > df.groupby("letters")
1550
+ * ... .tail(2)
1551
+ * ... .sort("letters")
1552
+ * shape: (5, 2)
1553
+ * ╭─────────┬─────╮
1554
+ * │ letters ┆ nrs │
1555
+ * │ --- ┆ --- │
1556
+ * │ str ┆ i64 │
1557
+ * ╞═════════╪═════╡
1558
+ * │ "a" ┆ 3 │
1559
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
1560
+ * │ "a" ┆ 5 │
1561
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
1562
+ * │ "b" ┆ 6 │
1563
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
1564
+ * │ "c" ┆ 2 │
1565
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
1566
+ * │ "c" ┆ 4 │
1567
+ * ╰─────────┴─────╯
1568
+ * ```
1569
+ */
1570
+ tail(length?: number): DataFrame<S>;
1571
+ /**
1572
+ * Converts dataframe object into row oriented javascript objects
1573
+ * @example
1574
+ * ```
1575
+ * > df.toRecords()
1576
+ * [
1577
+ * {"foo":1.0,"bar":"a"},
1578
+ * {"foo":2.0,"bar":"b"},
1579
+ * {"foo":3.0,"bar":"c"}
1580
+ * ]
1581
+ * ```
1582
+ * @category IO
1583
+ */
1584
+ toRecords(): {
1585
+ [K in keyof S]: DTypeToJs<S[K]> | null;
1586
+ }[];
1587
+ /**
1588
+ * Converts dataframe object into a {@link TabularDataResource}
1589
+ */
1590
+ toDataResource(): TabularDataResource;
1591
+ /**
1592
+ * Converts dataframe object into HTML
1593
+ */
1594
+ toHTML(): string;
1595
+ /**
1596
+ * Converts dataframe object into column oriented javascript objects
1597
+ * @example
1598
+ * ```
1599
+ * > df.toObject()
1600
+ * {
1601
+ * "foo": [1,2,3],
1602
+ * "bar": ["a", "b", "c"]
1603
+ * }
1604
+ * ```
1605
+ * @category IO
1606
+ */
1607
+ toObject(): {
1608
+ [K in keyof S]: DTypeToJs<S[K] | null>[];
1609
+ };
1610
+ toSeries(index?: number): SchemaToSeriesRecord<S>[keyof S];
1611
+ toString(): string;
1612
+ /**
1613
+ * Convert a ``DataFrame`` to a ``Series`` of type ``Struct``
1614
+ * @param name Name for the struct Series
1615
+ * @example
1616
+ * ```
1617
+ * > const df = pl.DataFrame({
1618
+ * ... "a": [1, 2, 3, 4, 5],
1619
+ * ... "b": ["one", "two", "three", "four", "five"],
1620
+ * ... });
1621
+ * > df.toStruct("nums");
1622
+ * shape: (5,)
1623
+ * Series: 'nums' [struct[2]{'a': i64, 'b': str}]
1624
+ * [
1625
+ * {1,"one"}
1626
+ * {2,"two"}
1627
+ * {3,"three"}
1628
+ * {4,"four"}
1629
+ * {5,"five"}
1630
+ * ]
1631
+ * ```
1632
+ */
1633
+ toStruct(name: string): Series;
1634
+ /**
1635
+ * Transpose a DataFrame over the diagonal.
1636
+ *
1637
+ * @remarks This is a very expensive operation. Perhaps you can do it differently.
1638
+ * @param options
1639
+ * @param options.includeHeader If set, the column names will be added as first column.
1640
+ * @param options.headerName If `includeHeader` is set, this determines the name of the column that will be inserted
1641
+ * @param options.columnNames Optional generator/iterator that yields column names. Will be used to replace the columns in the DataFrame.
1642
+ *
1643
+ * @example
1644
+ * > const df = pl.DataFrame({"a": [1, 2, 3], "b": [1, 2, 3]});
1645
+ * > df.transpose({includeHeader:true})
1646
+ * shape: (2, 4)
1647
+ * ┌────────┬──────────┬──────────┬──────────┐
1648
+ * │ column ┆ column_0 ┆ column_1 ┆ column_2 │
1649
+ * │ --- ┆ --- ┆ --- ┆ --- │
1650
+ * │ str ┆ i64 ┆ i64 ┆ i64 │
1651
+ * ╞════════╪══════════╪══════════╪══════════╡
1652
+ * │ a ┆ 1 ┆ 2 ┆ 3 │
1653
+ * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
1654
+ * │ b ┆ 1 ┆ 2 ┆ 3 │
1655
+ * └────────┴──────────┴──────────┴──────────┘
1656
+ * // replace the auto generated column names with a list
1657
+ * > df.transpose({includeHeader:false, columnNames:["a", "b", "c"]})
1658
+ * shape: (2, 3)
1659
+ * ┌─────┬─────┬─────┐
1660
+ * │ a ┆ b ┆ c │
1661
+ * │ --- ┆ --- ┆ --- │
1662
+ * │ i64 ┆ i64 ┆ i64 │
1663
+ * ╞═════╪═════╪═════╡
1664
+ * │ 1 ┆ 2 ┆ 3 │
1665
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
1666
+ * │ 1 ┆ 2 ┆ 3 │
1667
+ * └─────┴─────┴─────┘
1668
+ *
1669
+ * // Include the header as a separate column
1670
+ * > df.transpose({
1671
+ * ... includeHeader:true,
1672
+ * ... headerName:"foo",
1673
+ * ... columnNames:["a", "b", "c"]
1674
+ * ... })
1675
+ * shape: (2, 4)
1676
+ * ┌─────┬─────┬─────┬─────┐
1677
+ * │ foo ┆ a ┆ b ┆ c │
1678
+ * │ --- ┆ --- ┆ --- ┆ --- │
1679
+ * │ str ┆ i64 ┆ i64 ┆ i64 │
1680
+ * ╞═════╪═════╪═════╪═════╡
1681
+ * │ a ┆ 1 ┆ 2 ┆ 3 │
1682
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
1683
+ * │ b ┆ 1 ┆ 2 ┆ 3 │
1684
+ * └─────┴─────┴─────┴─────┘
1685
+ *
1686
+ * // Replace the auto generated column with column names from a generator function
1687
+ * > function *namesGenerator() {
1688
+ * ... const baseName = "my_column_";
1689
+ * ... let count = 0;
1690
+ * ... let name = `${baseName}_${count}`;
1691
+ * ... count++;
1692
+ * ... yield name;
1693
+ * ... }
1694
+ * > df.transpose({includeHeader:false, columnNames:namesGenerator})
1695
+ * shape: (2, 3)
1696
+ * ┌─────────────┬─────────────┬─────────────┐
1697
+ * │ my_column_0 ┆ my_column_1 ┆ my_column_2 │
1698
+ * │ --- ┆ --- ┆ --- │
1699
+ * │ i64 ┆ i64 ┆ i64 │
1700
+ * ╞═════════════╪═════════════╪═════════════╡
1701
+ * │ 1 ┆ 2 ┆ 3 │
1702
+ * ├╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤
1703
+ * │ 1 ┆ 2 ┆ 3 │
1704
+ * └─────────────┴─────────────┴─────────────┘
1705
+ */
1706
+ transpose(options?: {
1707
+ includeHeader?: boolean;
1708
+ headerName?: string;
1709
+ columnNames?: Iterable<string>;
1710
+ }): DataFrame;
1711
+ /**
1712
+ * Drop duplicate rows from this DataFrame.
1713
+ * Note that this fails if there is a column of type `List` in the DataFrame.
1714
+ * @param subset Column name(s), selector(s) to consider when identifying duplicate rows. If set to `None` (default), all columns are considered.
1715
+ * @param keep : 'first', 'last', 'any', 'none'
1716
+ * Which of the duplicate rows to keep.
1717
+ * 'any': Defaut, does not give any guarantee of which row is kept. This allows more optimizations.
1718
+ * 'none': Don't keep duplicate rows.
1719
+ * 'first': Keep the first unique row.
1720
+ * 'last': Keep the last unique row.
1721
+ * @param maintainOrder Keep the same order as the original DataFrame. This is more expensive to compute. Default: false
1722
+ * @returns DataFrame with unique rows.
1723
+ * @example
1724
+ * const df = pl.DataFrame({
1725
+ foo: [1, 2, 2, 3],
1726
+ bar: [1, 2, 2, 4],
1727
+ ham: ["a", "d", "d", "c"],
1728
+ });
1729
+ > df.unique();
1730
+ By default, all columns are considered when determining which rows are unique:
1731
+ shape: (3, 3)
1732
+ ┌─────┬─────┬─────┐
1733
+ │ foo ┆ bar ┆ ham │
1734
+ │ --- ┆ --- ┆ --- │
1735
+ │ f64 ┆ f64 ┆ str │
1736
+ ╞═════╪═════╪═════╡
1737
+ │ 3.0 ┆ 4.0 ┆ c │
1738
+ │ 1.0 ┆ 1.0 ┆ a │
1739
+ │ 2.0 ┆ 2.0 ┆ d │
1740
+ └─────┴─────┴─────┘
1741
+ > df.unique("foo");
1742
+ shape: (3, 3)
1743
+ ┌─────┬─────┬─────┐
1744
+ │ foo ┆ bar ┆ ham │
1745
+ │ --- ┆ --- ┆ --- │
1746
+ │ f64 ┆ f64 ┆ str │
1747
+ ╞═════╪═════╪═════╡
1748
+ │ 3.0 ┆ 4.0 ┆ c │
1749
+ │ 1.0 ┆ 1.0 ┆ a │
1750
+ │ 2.0 ┆ 2.0 ┆ d │
1751
+ └─────┴─────┴─────┘
1752
+ > df.unique(["foo", "ham"], "first", true); or df.unique({ subset: ["foo", "ham"], keep: "first", maintainOrder: true });
1753
+ shape: (3, 3)
1754
+ ┌─────┬─────┬─────┐
1755
+ │ foo ┆ bar ┆ ham │
1756
+ │ --- ┆ --- ┆ --- │
1757
+ │ f64 ┆ f64 ┆ str │
1758
+ ╞═════╪═════╪═════╡
1759
+ │ 1.0 ┆ 1.0 ┆ a │
1760
+ │ 2.0 ┆ 2.0 ┆ d │
1761
+ │ 3.0 ┆ 4.0 ┆ c │
1762
+ └─────┴─────┴─────┘
1763
+ */
1764
+ unique(subset?: ColumnSelection, keep?: "first" | "last" | "any" | "none", maintainOrder?: boolean): DataFrame<S>;
1765
+ unique(opts: {
1766
+ subset?: ColumnSelection;
1767
+ keep?: "first" | "last" | "any" | "none";
1768
+ maintainOrder?: boolean;
1769
+ }): DataFrame<S>;
1770
+ /**
1771
+ Decompose struct columns into separate columns for each of their fields.
1772
+ The new columns will be inserted into the DataFrame at the location of the struct column.
1773
+ @param columns Name of the struct column(s) that should be unnested.
1774
+ @param separator Rename output column names as combination of the struct column name, name separator and field name.
1775
+ @example
1776
+ ```
1777
+ > const df = pl.DataFrame({
1778
+ ... "int": [1, 2],
1779
+ ... "str": ["a", "b"],
1780
+ ... "bool": [true, null],
1781
+ ... "list": [[1, 2], [3]],
1782
+ ... })
1783
+ ... .toStruct("my_struct")
1784
+ ... .toFrame();
1785
+ > df
1786
+ shape: (2, 1)
1787
+ ┌─────────────────────────────┐
1788
+ │ my_struct │
1789
+ │ --- │
1790
+ │ struct[4]{'int',...,'list'} │
1791
+ ╞═════════════════════════════╡
1792
+ │ {1,"a",true,[1, 2]} │
1793
+ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
1794
+ │ {2,"b",null,[3]} │
1795
+ └─────────────────────────────┘
1796
+ > df.unnest("my_struct")
1797
+ shape: (2, 4)
1798
+ ┌─────┬─────┬──────┬────────────┐
1799
+ │ int ┆ str ┆ bool ┆ list │
1800
+ │ --- ┆ --- ┆ --- ┆ --- │
1801
+ │ i64 ┆ str ┆ bool ┆ list [i64] │
1802
+ ╞═════╪═════╪══════╪════════════╡
1803
+ │ 1 ┆ a ┆ true ┆ [1, 2] │
1804
+ ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
1805
+ │ 2 ┆ b ┆ null ┆ [3] │
1806
+ └─────┴─────┴──────┴────────────┘
1807
+ ```
1808
+ */
1809
+ unnest(columns: string | string[], separator?: string): DataFrame;
1810
+ /**
1811
+ * Aggregate the columns of this DataFrame to their variance value.
1812
+ * @example
1813
+ * ```
1814
+ * > const df = pl.DataFrame({
1815
+ * > "foo": [1, 2, 3],
1816
+ * > "bar": [6, 7, 8],
1817
+ * > "ham": ['a', 'b', 'c']
1818
+ * > });
1819
+ * > df.var()
1820
+ * shape: (1, 3)
1821
+ * ╭─────┬─────┬──────╮
1822
+ * │ foo ┆ bar ┆ ham │
1823
+ * │ --- ┆ --- ┆ --- │
1824
+ * │ f64 ┆ f64 ┆ str │
1825
+ * ╞═════╪═════╪══════╡
1826
+ * │ 1 ┆ 1 ┆ null │
1827
+ * ╰─────┴─────┴──────╯
1828
+ * ```
1829
+ */
1830
+ var(): DataFrame<S>;
1831
+ /**
1832
+ * Grow this DataFrame vertically by stacking a DataFrame to it.
1833
+ * @param df - DataFrame to stack.
1834
+ * @example
1835
+ * ```
1836
+ * > const df1 = pl.DataFrame({
1837
+ * ... "foo": [1, 2],
1838
+ * ... "bar": [6, 7],
1839
+ * ... "ham": ['a', 'b']
1840
+ * ... });
1841
+ * > const df2 = pl.DataFrame({
1842
+ * ... "foo": [3, 4],
1843
+ * ... "bar": [8 , 9],
1844
+ * ... "ham": ['c', 'd']
1845
+ * ... });
1846
+ * > df1.vstack(df2);
1847
+ * shape: (4, 3)
1848
+ * ╭─────┬─────┬─────╮
1849
+ * │ foo ┆ bar ┆ ham │
1850
+ * │ --- ┆ --- ┆ --- │
1851
+ * │ i64 ┆ i64 ┆ str │
1852
+ * ╞═════╪═════╪═════╡
1853
+ * │ 1 ┆ 6 ┆ "a" │
1854
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
1855
+ * │ 2 ┆ 7 ┆ "b" │
1856
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
1857
+ * │ 3 ┆ 8 ┆ "c" │
1858
+ * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
1859
+ * │ 4 ┆ 9 ┆ "d" │
1860
+ * ╰─────┴─────┴─────╯
1861
+ * ```
1862
+ */
1863
+ vstack(df: DataFrame<S>): DataFrame<S>;
1864
+ /**
1865
+ * Return a new DataFrame with the column added or replaced.
1866
+ * @param column - Series, where the name of the Series refers to the column in the DataFrame.
1867
+ */
1868
+ withColumn<SeriesTypeT extends DataType, SeriesNameT extends string>(column: Series<SeriesTypeT, SeriesNameT>): DataFrame<Simplify<S & {
1869
+ [K in SeriesNameT]: SeriesTypeT;
1870
+ }>>;
1871
+ withColumn(column: Series | Expr): DataFrame;
1872
+ withColumns(...columns: (Expr | Series)[]): DataFrame;
1873
+ /**
1874
+ * Return a new DataFrame with the column renamed.
1875
+ * @param existingName
1876
+ * @param replacement
1877
+ */
1878
+ withColumnRenamed<Existing extends keyof S, New extends string>(existingName: Existing, replacement: New): DataFrame<{
1879
+ [K in keyof S as K extends Existing ? New : K]: S[K];
1880
+ }>;
1881
+ withColumnRenamed(existing: string, replacement: string): DataFrame;
1882
+ withColumnRenamed<Existing extends keyof S, New extends string>(opts: {
1883
+ existingName: Existing;
1884
+ replacement: New;
1885
+ }): DataFrame<{
1886
+ [K in keyof S as K extends Existing ? New : K]: S[K];
1887
+ }>;
1888
+ withColumnRenamed(opts: {
1889
+ existing: string;
1890
+ replacement: string;
1891
+ }): DataFrame;
1892
+ /**
1893
+ * Add a column at index 0 that counts the rows.
1894
+ * @param name - name of the column to add
1895
+ * @deprecated - *since 0.23.0 use withRowIndex instead
1896
+ */
1897
+ withRowCount(name?: string): DataFrame;
1898
+ /**
1899
+ * Add a row index as the first column in the DataFrame.
1900
+ * @param name Name of the index column.
1901
+ * @param offset Start the index at this offset. Cannot be negative.
1902
+ * @example
1903
+ *
1904
+ * >>> df = pl.DataFrame(
1905
+ ... {
1906
+ ... "a": [1, 3, 5],
1907
+ ... "b": [2, 4, 6],
1908
+ ... }
1909
+ ... )
1910
+ >>> df.withRowIndex()
1911
+ shape: (3, 3)
1912
+ ┌───────┬─────┬─────┐
1913
+ │ index ┆ a ┆ b │
1914
+ │ --- ┆ --- ┆ --- │
1915
+ │ u32 ┆ i64 ┆ i64 │
1916
+ ╞═══════╪═════╪═════╡
1917
+ │ 0 ┆ 1 ┆ 2 │
1918
+ │ 1 ┆ 3 ┆ 4 │
1919
+ │ 2 ┆ 5 ┆ 6 │
1920
+ └───────┴─────┴─────┘
1921
+ >>> df.withRowIndex("id", offset=1000)
1922
+ shape: (3, 3)
1923
+ ┌──────┬─────┬─────┐
1924
+ │ id ┆ a ┆ b │
1925
+ │ --- ┆ --- ┆ --- │
1926
+ │ u32 ┆ i64 ┆ i64 │
1927
+ ╞══════╪═════╪═════╡
1928
+ │ 1000 ┆ 1 ┆ 2 │
1929
+ │ 1001 ┆ 3 ┆ 4 │
1930
+ │ 1002 ┆ 5 ┆ 6 │
1931
+ └──────┴─────┴─────┘
1932
+ */
1933
+ withRowIndex(name?: string, offset?: number): DataFrame;
1934
+ /** @see {@link filter} */
1935
+ where(predicate: any): DataFrame<S>;
1936
+ /**
1937
+ Upsample a DataFrame at a regular frequency.
1938
+
1939
+ The `every` and `offset` arguments are created with the following string language:
1940
+ - 1ns (1 nanosecond)
1941
+ - 1us (1 microsecond)
1942
+ - 1ms (1 millisecond)
1943
+ - 1s (1 second)
1944
+ - 1m (1 minute)
1945
+ - 1h (1 hour)
1946
+ - 1d (1 calendar day)
1947
+ - 1w (1 calendar week)
1948
+ - 1mo (1 calendar month)
1949
+ - 1q (1 calendar quarter)
1950
+ - 1y (1 calendar year)
1951
+ - 1i (1 index count)
1952
+
1953
+ Or combine them:
1954
+ - "3d12h4m25s" # 3 days, 12 hours, 4 minutes, and 25 seconds
1955
+
1956
+ By "calendar day", we mean the corresponding time on the next day (which may not be 24 hours, due to daylight savings).
1957
+ Similarly for "calendar week", "calendar month", "calendar quarter", and "calendar year".
1958
+
1959
+ Parameters
1960
+ ----------
1961
+ @param timeColumn Time column will be used to determine a date range.
1962
+ Note that this column has to be sorted for the output to make sense.
1963
+ @param every Interval will start 'every' duration.
1964
+ @param by First group by these columns and then upsample for every group.
1965
+ @param maintainOrder Keep the ordering predictable. This is slower.
1966
+
1967
+ Returns
1968
+ -------
1969
+ DataFrame
1970
+ Result will be sorted by `timeColumn` (but note that if `by` columns are passed, it will only be sorted within each `by` group).
1971
+
1972
+ Examples
1973
+ --------
1974
+ Upsample a DataFrame by a certain interval.
1975
+
1976
+ >>> const df = pl.DataFrame({
1977
+ "date": [
1978
+ new Date(2024, 1, 1),
1979
+ new Date(2024, 3, 1),
1980
+ new Date(2024, 4, 1),
1981
+ new Date(2024, 5, 1),
1982
+ ],
1983
+ "groups": ["A", "B", "A", "B"],
1984
+ "values": [0, 1, 2, 3],
1985
+ })
1986
+ .withColumn(pl.col("date").cast(pl.Date).alias("date"))
1987
+ .sort("date");
1988
+
1989
+ >>> df.upsample({timeColumn: "date", every: "1mo", by: "groups", maintainOrder: true})
1990
+ .select(pl.col("*").forwardFill());
1991
+ shape: (7, 3)
1992
+ ┌────────────┬────────┬────────┐
1993
+ │ date ┆ groups ┆ values │
1994
+ │ --- ┆ --- ┆ --- │
1995
+ │ date ┆ str ┆ f64 │
1996
+ ╞════════════╪════════╪════════╡
1997
+ │ 2024-02-01 ┆ A ┆ 0.0 │
1998
+ │ 2024-03-01 ┆ A ┆ 0.0 │
1999
+ │ 2024-04-01 ┆ A ┆ 0.0 │
2000
+ │ 2024-05-01 ┆ A ┆ 2.0 │
2001
+ │ 2024-04-01 ┆ B ┆ 1.0 │
2002
+ │ 2024-05-01 ┆ B ┆ 1.0 │
2003
+ │ 2024-06-01 ┆ B ┆ 3.0 │
2004
+ └────────────┴────────┴────────┘
2005
+ */
2006
+ upsample(timeColumn: string, every: string, by?: string | string[], maintainOrder?: boolean): DataFrame<S>;
2007
+ upsample(opts: {
2008
+ timeColumn: string;
2009
+ every: string;
2010
+ by?: string | string[];
2011
+ maintainOrder?: boolean;
2012
+ }): DataFrame<S>;
2013
+ }
2014
+ type DataResourceField = {
2015
+ name: string;
2016
+ type: string;
2017
+ };
2018
+ /**
2019
+ * Tabular Data Resource from https://specs.frictionlessdata.io/schemas/tabular-data-resource.json,
2020
+ */
2021
+ type TabularDataResource = {
2022
+ data: any[];
2023
+ schema: {
2024
+ fields: DataResourceField[];
2025
+ };
2026
+ };
2027
+ /** @ignore */
2028
+ export declare const _DataFrame: <S extends Schema>(_df: any) => DataFrame<S>;
2029
+ interface DataFrameOptions<S extends Schema = Schema, O extends Partial<S> = any> {
2030
+ columns?: any[];
2031
+ orient?: "row" | "col";
2032
+ schema?: S;
2033
+ schemaOverrides?: O;
2034
+ inferSchemaLength?: number;
2035
+ }
2036
+ /**
2037
+ * DataFrame constructor
2038
+ */
2039
+ export interface DataFrameConstructor extends Deserialize<DataFrame> {
2040
+ /**
2041
+ * Create an empty DataFrame
2042
+ */
2043
+ (): DataFrame;
2044
+ /**
2045
+ * Create a DataFrame from a JavaScript object
2046
+ *
2047
+ * @param data - object or array of data
2048
+ * @param options - options
2049
+ * @param options.columns - column names
2050
+ * @param options.orient - orientation of the data [row, col]
2051
+ * Whether to interpret two-dimensional data as columns or as rows. If None, the orientation is inferred by matching the columns and data dimensions. If this does not yield conclusive results, column orientation is used.
2052
+ * @param options.schema - The schema of the resulting DataFrame. The schema may be declared in several ways:
2053
+ * - As a dict of {name:type} pairs; if type is None, it will be auto-inferred.
2054
+ * - As a list of column names; in this case types are automatically inferred.
2055
+ * - As a list of (name,type) pairs; this is equivalent to the dictionary form.
2056
+ * If you supply a list of column names that does not match the names in the underlying data, the names given here will overwrite them. The number of names given in the schema should match the underlying data dimensions.
2057
+ *
2058
+ * If set to null (default), the schema is inferred from the data.
2059
+ * @param options.schemaOverrides - Support type specification or override of one or more columns; note that any dtypes inferred from the schema param will be overridden.
2060
+ *
2061
+ * @param options.inferSchemaLength - The maximum number of rows to scan for schema inference. If set to None, the full data may be scanned (this can be slow). This parameter only applies if the input data is a sequence or generator of rows; other input is read as-is.
2062
+ * The number of entries in the schema should match the underlying data dimensions, unless a sequence of dictionaries is being passed, in which case a partial schema can be declared to prevent specific fields from being loaded.
2063
+ *
2064
+ * @example
2065
+ * ```
2066
+ * > pl.DataFrame({ a: [1, 2, 3], b: ["a", "b", "c"] });
2067
+ shape: (3, 2)
2068
+ ┌─────┬─────┐
2069
+ │ a ┆ b │
2070
+ │ --- ┆ --- │
2071
+ │ f64 ┆ str │
2072
+ ╞═════╪═════╡
2073
+ │ 1.0 ┆ a │
2074
+ │ 2.0 ┆ b │
2075
+ │ 3.0 ┆ c │
2076
+ └─────┴─────┘
2077
+
2078
+ * To specify a more detailed/specific frame schema you can supply the `schema` parameter with a dictionary of (name,dtype) pairs...
2079
+ * > const data = {col1: [0, 2], col2: [3, 7]}
2080
+ * > pl.DataFrame(data, { schema: { "col1": pl.Float32, "col2": pl.Int64}} );
2081
+ shape: (2, 2)
2082
+ ┌──────┬──────┐
2083
+ │ col1 ┆ col2 │
2084
+ │ --- ┆ --- │
2085
+ │ f32 ┆ i64 │
2086
+ ╞══════╪══════╡
2087
+ │ 0.0 ┆ 3 │
2088
+ │ 2.0 ┆ 7 │
2089
+ └──────┴──────┘
2090
+
2091
+ * Constructing a DataFrame from a list of lists, row orientation and columns specified
2092
+ * > const data = [[1, 2, 3], [4, 5, 6]];
2093
+ * > pl.DataFrame(data, { columns: ["a", "b", "c"], orient: "row" });
2094
+ shape: (2, 3)
2095
+ ┌─────┬─────┬─────┐
2096
+ │ a ┆ b ┆ c │
2097
+ │ --- ┆ --- ┆ --- │
2098
+ │ f64 ┆ f64 ┆ f64 │
2099
+ ╞═════╪═════╪═════╡
2100
+ │ 1.0 ┆ 2.0 ┆ 3.0 │
2101
+ │ 4.0 ┆ 5.0 ┆ 6.0 │
2102
+ └─────┴─────┴─────┘
2103
+
2104
+ * Constructing an empty DataFrame with a schema
2105
+ * > const schema = {
2106
+ s: pl.String,
2107
+ b: pl.Bool,
2108
+ i: pl.Int32,
2109
+ d: pl.Datetime("ms"),
2110
+ a: pl.Struct([
2111
+ new pl.Field("b", pl.Bool),
2112
+ new pl.Field("bb", pl.Bool),
2113
+ new pl.Field("s", pl.String),
2114
+ new pl.Field("x", pl.Float64),
2115
+ ]),
2116
+ };
2117
+ * > pl.DataFrame({}, { schema }) or pl.DataFrame(null, { schema }) or pl.DataFrame(underfined, { schema });
2118
+ shape: (0, 5)
2119
+ ┌─────┬──────┬─────┬──────────────┬───────────┐
2120
+ │ s ┆ b ┆ i ┆ d ┆ a │
2121
+ │ --- ┆ --- ┆ --- ┆ --- ┆ --- │
2122
+ │ str ┆ bool ┆ i32 ┆ datetime[ms] ┆ struct[0] │
2123
+ ╞═════╪══════╪═════╪══════════════╪═══════════╡
2124
+ └─────┴──────┴─────┴──────────────┴───────────┘
2125
+ * ```
2126
+ */
2127
+ <T1 extends ArrayLike<Series>>(data: T1, options?: DataFrameOptions): DataFrame<{
2128
+ [K in T1[number] as K["name"]]: K["dtype"];
2129
+ }>;
2130
+ <RecordInput extends Record<string, ArrayLike<any>> = any, S extends Simplify<ArrayLikeLooseRecordToSchema<RecordInput>> = Simplify<ArrayLikeLooseRecordToSchema<RecordInput>>>(data: RecordInput, options?: DataFrameOptions<S>): DataFrame<S>;
2131
+ (data: any, options?: DataFrameOptions): DataFrame;
2132
+ isDataFrame(arg: any): arg is DataFrame;
2133
+ }
2134
+ export declare const DataFrame: DataFrameConstructor;
2135
+ export {};