@ohos-ports/nodejs-polars 0.22.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +2008 -0
  6. package/bin/dataframe.js +771 -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 +252 -0
  10. package/bin/datatypes/datatype.js +386 -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 +42 -0
  14. package/bin/datatypes/index.js +119 -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 +173 -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 +252 -0
  24. package/bin/index.js +265 -0
  25. package/bin/internals/construction.d.ts +7 -0
  26. package/bin/internals/construction.js +237 -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 +421 -0
  30. package/bin/io.js +332 -0
  31. package/bin/lazy/dataframe.d.ts +693 -0
  32. package/bin/lazy/dataframe.js +421 -0
  33. package/bin/lazy/expr/datetime.d.ts +8 -0
  34. package/bin/lazy/expr/datetime.js +25 -0
  35. package/bin/lazy/expr/index.d.ts +1155 -0
  36. package/bin/lazy/expr/index.js +629 -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 +620 -0
  44. package/bin/lazy/functions.js +691 -0
  45. package/bin/lazy/groupby.d.ts +24 -0
  46. package/bin/lazy/groupby.js +22 -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 +25 -0
  55. package/bin/series/index.d.ts +1116 -0
  56. package/bin/series/index.js +689 -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 +1325 -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 +284 -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 +51 -0
@@ -0,0 +1,42 @@
1
+ export * from "./conversion";
2
+ export * from "./datatype";
3
+ export { Field } from "./field";
4
+ import { type DataType } from "./datatype";
5
+ /** @ignore */
6
+ export type TypedArray = Int8Array | Int16Array | Int32Array | BigInt64Array | Uint8Array | Uint16Array | Uint32Array | BigInt64Array | Float32Array | Float64Array;
7
+ /**
8
+ * @ignore
9
+ */
10
+ export type Optional<T> = T | undefined | null;
11
+ /**
12
+ * @ignore
13
+ */
14
+ export type JsDataFrame = any;
15
+ export type NullValues = string | Array<string> | Record<string, string>;
16
+ /**
17
+ * @ignore
18
+ */
19
+ export declare const DTYPE_TO_FFINAME: {
20
+ Int8: string;
21
+ Int16: string;
22
+ Int32: string;
23
+ Int64: string;
24
+ UInt8: string;
25
+ UInt16: string;
26
+ UInt32: string;
27
+ UInt64: string;
28
+ Float32: string;
29
+ Float64: string;
30
+ Bool: string;
31
+ Utf8: string;
32
+ String: string;
33
+ List: string;
34
+ Date: string;
35
+ Datetime: string;
36
+ Time: string;
37
+ Object: string;
38
+ Categorical: string;
39
+ Struct: string;
40
+ };
41
+ /** @ignore */
42
+ export declare const polarsTypeToConstructor: (dtype: DataType) => CallableFunction;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.polarsTypeToConstructor = exports.DTYPE_TO_FFINAME = exports.Field = void 0;
21
+ __exportStar(require("./conversion"), exports);
22
+ __exportStar(require("./datatype"), exports);
23
+ var field_1 = require("./field");
24
+ Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return field_1.Field; } });
25
+ const polars_internal_1 = __importDefault(require("../internals/polars_internal"));
26
+ const datatype_1 = require("./datatype");
27
+ /**
28
+ * @ignore
29
+ */
30
+ exports.DTYPE_TO_FFINAME = {
31
+ Int8: "I8",
32
+ Int16: "I16",
33
+ Int32: "I32",
34
+ Int64: "I64",
35
+ UInt8: "U8",
36
+ UInt16: "U16",
37
+ UInt32: "U32",
38
+ UInt64: "U64",
39
+ Float32: "F32",
40
+ Float64: "F64",
41
+ Bool: "Bool",
42
+ Utf8: "Str",
43
+ String: "Str",
44
+ List: "List",
45
+ Date: "Date",
46
+ Datetime: "Datetime",
47
+ Time: "Time",
48
+ Object: "Object",
49
+ Categorical: "Categorical",
50
+ Struct: "Struct",
51
+ };
52
+ const POLARS_TYPE_TO_CONSTRUCTOR = {
53
+ Float32(name, values) {
54
+ return polars_internal_1.default.JsSeries.newOptF64(name, values);
55
+ },
56
+ Float64(name, values) {
57
+ return polars_internal_1.default.JsSeries.newOptF64(name, values);
58
+ },
59
+ Int8(name, values) {
60
+ return polars_internal_1.default.JsSeries.newOptI32(name, values);
61
+ },
62
+ Int16(name, values) {
63
+ return polars_internal_1.default.JsSeries.newOptI32(name, values);
64
+ },
65
+ Int32(name, values) {
66
+ return polars_internal_1.default.JsSeries.newOptI32(name, values);
67
+ },
68
+ Int64(name, values) {
69
+ return polars_internal_1.default.JsSeries.newOptI64(name, values);
70
+ },
71
+ UInt8(name, values) {
72
+ return polars_internal_1.default.JsSeries.newOptU32(name, values);
73
+ },
74
+ UInt16(name, values) {
75
+ return polars_internal_1.default.JsSeries.newOptU32(name, values);
76
+ },
77
+ UInt32(name, values) {
78
+ return polars_internal_1.default.JsSeries.newOptU32(name, values);
79
+ },
80
+ UInt64(name, values) {
81
+ return polars_internal_1.default.JsSeries.newOptU64(name, values);
82
+ },
83
+ Date(name, values) {
84
+ return polars_internal_1.default.JsSeries.newOptI64(name, values);
85
+ },
86
+ Datetime(name, values) {
87
+ return polars_internal_1.default.JsSeries.newOptI64(name, values);
88
+ },
89
+ Time(name, values) {
90
+ return polars_internal_1.default.JsSeries.newAnyValue(name, values, datatype_1.Time);
91
+ },
92
+ Bool(name, values) {
93
+ return polars_internal_1.default.JsSeries.newOptBool(name, values);
94
+ },
95
+ Utf8(name, values) {
96
+ return polars_internal_1.default.JsSeries.newOptStr(name, values);
97
+ },
98
+ String(name, values) {
99
+ return polars_internal_1.default.JsSeries.newOptStr(name, values);
100
+ },
101
+ Categorical(name, values) {
102
+ return polars_internal_1.default.JsSeries.newOptStr(name, values);
103
+ },
104
+ List(name, values, dtype) {
105
+ return polars_internal_1.default.JsSeries.newList(name, values, dtype);
106
+ },
107
+ FixedSizeList(name, values, dtype) {
108
+ return polars_internal_1.default.JsSeries.newList(name, values, dtype);
109
+ },
110
+ };
111
+ /** @ignore */
112
+ const polarsTypeToConstructor = (dtype) => {
113
+ const ctor = POLARS_TYPE_TO_CONSTRUCTOR[dtype.variant];
114
+ if (!ctor) {
115
+ throw new Error(`Cannot construct Series for type ${dtype.variant}.`);
116
+ }
117
+ return ctor;
118
+ };
119
+ exports.polarsTypeToConstructor = polarsTypeToConstructor;
package/bin/error.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export declare class InvalidOperationError extends RangeError {
2
+ constructor(method: any, dtype: any);
3
+ }
4
+ export declare class NotImplemented extends Error {
5
+ constructor(method: any, dtype: any);
6
+ }
7
+ export declare const todo: () => Error;
package/bin/error.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.todo = exports.NotImplemented = exports.InvalidOperationError = void 0;
4
+ class InvalidOperationError extends RangeError {
5
+ constructor(method, dtype) {
6
+ super(`Invalid operation: ${method} is not supported for ${dtype}`);
7
+ }
8
+ }
9
+ exports.InvalidOperationError = InvalidOperationError;
10
+ class NotImplemented extends Error {
11
+ constructor(method, dtype) {
12
+ super(`Invalid operation: ${method} is not supported for ${dtype}`);
13
+ }
14
+ }
15
+ exports.NotImplemented = NotImplemented;
16
+ const todo = () => new Error("not yet implemented");
17
+ exports.todo = todo;
@@ -0,0 +1,26 @@
1
+ import { type DataFrame } from "./dataframe";
2
+ import { type LazyDataFrame } from "./lazy/dataframe";
3
+ import { type Series } from "./series";
4
+ import type { ConcatOptions } from "./types";
5
+ /**
6
+ * _Repeat a single value n times and collect into a Series._
7
+ * @param value - Value to repeat.
8
+ * @param n - Number of repeats
9
+ * @param name - Optional name of the Series
10
+ * @example
11
+ *
12
+ * ```
13
+ *
14
+ * > const s = pl.repeat("a", 5)
15
+ * > s.toArray()
16
+ * ["a", "a", "a", "a", "a"]
17
+ *
18
+ * ```
19
+ */
20
+ export declare function repeat<V>(value: V, n: number, name?: string): Series;
21
+ export declare function concat(items: Array<DataFrame>, options?: ConcatOptions): DataFrame;
22
+ export declare function concat(items: Array<Series>, options?: {
23
+ rechunk: boolean;
24
+ parallel: boolean;
25
+ }): Series;
26
+ export declare function concat(items: Array<LazyDataFrame>, options?: ConcatOptions): LazyDataFrame;
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.repeat = repeat;
7
+ exports.concat = concat;
8
+ const dataframe_1 = require("./dataframe");
9
+ const construction_1 = require("./internals/construction");
10
+ const polars_internal_1 = __importDefault(require("./internals/polars_internal"));
11
+ const dataframe_2 = require("./lazy/dataframe");
12
+ const series_1 = require("./series");
13
+ const utils_1 = require("./utils");
14
+ /**
15
+ * _Repeat a single value n times and collect into a Series._
16
+ * @param value - Value to repeat.
17
+ * @param n - Number of repeats
18
+ * @param name - Optional name of the Series
19
+ * @example
20
+ *
21
+ * ```
22
+ *
23
+ * > const s = pl.repeat("a", 5)
24
+ * > s.toArray()
25
+ * ["a", "a", "a", "a", "a"]
26
+ *
27
+ * ```
28
+ */
29
+ function repeat(value, n, name = "") {
30
+ const dtype = (0, construction_1.jsTypeToPolarsType)(value);
31
+ const s = polars_internal_1.default.JsSeries.repeat(name, value, n, dtype);
32
+ return (0, series_1._Series)(s);
33
+ }
34
+ /**
35
+ * Aggregate all the Dataframes/Series in a List of DataFrames/Series to a single DataFrame/Series.
36
+ * @param items DataFrames/Series/LazyFrames to concatenate.
37
+ * @param options.rechunk Make sure that the result data is in contiguous memory.
38
+ * @param options.how Only used if the items are DataFrames. *Defaults to 'vertical'*
39
+ * - vertical: Applies multiple `vstack` operations.
40
+ * - verticalRelaxed: Same as `vertical`, but additionally coerces columns to their common supertype *if* they are mismatched (eg: Int32 → Int64).
41
+ * - horizontal: Stacks Series horizontally and fills with nulls if the lengths don't match.
42
+ * - diagonal: Finds a union between the column schemas and fills missing column values with ``null``.
43
+ * - diagonalRelaxed: Same as `diagonal`, but additionally coerces columns to their common supertype *if* they are mismatched (eg: Int32 → Int64).
44
+ * - align, alignFull, alignLeft, alignRight: Combines frames horizontally,
45
+ * auto-determining the common key columns and aligning rows using the same
46
+ * logic as `alignFrames` (note that "align" is an alias for "alignFull").
47
+ * The "align" strategy determines the type of join used to align the frames,
48
+ * equivalent to the "how" parameter on `alignFrames`. Note that the common join columns are automatically coalesced, but other column collisions
49
+ * will raise an error (if you need more control over this you should use a suitable `join` method directly).
50
+ * @param options.parallel - Only relevant for LazyFrames. This determines if the concatenated lazy computations may be executed in parallel.
51
+ * @example
52
+ * > const df1 = pl.DataFrame({"a": [1], "b": [3]});
53
+ * > const df2 = pl.DataFrame({"a": [2], "b": [4]});
54
+ * > pl.concat([df1, df2]);
55
+ * shape: (2, 2)
56
+ * ┌─────┬─────┐
57
+ * │ a ┆ b │
58
+ * │ --- ┆ --- │
59
+ * │ i64 ┆ i64 │
60
+ * ╞═════╪═════╡
61
+ * │ 1 ┆ 3 │
62
+ * ├╌╌╌╌╌┼╌╌╌╌╌┤
63
+ * │ 2 ┆ 4 │
64
+ * └─────┴─────┘
65
+ *
66
+ * > const a = pl.DataFrame({ a: ["a", "b"], b: [1, 2] });
67
+ * > const b = pl.DataFrame({ c: [5, 6], d: [7, 8], e: [9, 10]});
68
+ * > pl.concat([a, b], { how: "horizontal" });
69
+ *
70
+ * shape: (2, 5)
71
+ * ┌─────┬─────┬─────┬─────┬──────┐
72
+ * │ a ┆ b ┆ c ┆ d ┆ e │
73
+ * │ --- ┆ --- ┆ --- ┆ --- ┆ --- │
74
+ * │ str ┆ f64 ┆ f64 ┆ f64 ┆ f64 │
75
+ * ╞═════╪═════╪═════╪═════╪══════╡
76
+ * │ a ┆ 1.0 ┆ 5.0 ┆ 7.0 ┆ 9.0 │
77
+ * │ b ┆ 2.0 ┆ 6.0 ┆ 8.0 ┆ 10.0 │
78
+ * └─────┴─────┴─────┴─────┴──────┘
79
+ *
80
+ * > const df_d1 = pl.DataFrame({"a": [1], "b": [3]});
81
+ * > const df_d2 = pl.DataFrame({"a": [2], "c": [4]});
82
+ * > pl.concat([df_d1, df_d2], { how: "diagonal" });
83
+ *
84
+ * shape: (2, 3)
85
+ * ┌─────┬──────┬──────┐
86
+ * │ a ┆ b ┆ c │
87
+ * │ --- ┆ --- ┆ --- │
88
+ * │ i64 ┆ i64 ┆ i64 │
89
+ * ╞═════╪══════╪══════╡
90
+ * │ 1 ┆ 3 ┆ null │
91
+ * │ 2 ┆ null ┆ 4 │
92
+ * └─────┴──────┴──────┘
93
+ *
94
+ * The "align" strategies require at least one common column to align on:
95
+
96
+ >>> const df1 = pl.DataFrame({"id": [1, 2], "x": [3, 4]});
97
+ >>> const df2 = pl.DataFrame({"id": [2, 3], "y": [5, 6]});
98
+ >>> const df3 = pl.DataFrame({"id": [1, 3], "z": [7, 8]});
99
+ >>> pl.concat([df1, df2, df3], how="align"); // equivalent to "alignFull"
100
+ shape: (3, 4)
101
+ ┌─────┬──────┬──────┬──────┐
102
+ │ id ┆ x ┆ y ┆ z │
103
+ │ --- ┆ --- ┆ --- ┆ --- │
104
+ │ i64 ┆ i64 ┆ i64 ┆ i64 │
105
+ ╞═════╪══════╪══════╪══════╡
106
+ │ 1 ┆ 3 ┆ null ┆ 7 │
107
+ │ 2 ┆ 4 ┆ 5 ┆ null │
108
+ │ 3 ┆ null ┆ 6 ┆ 8 │
109
+ └─────┴──────┴──────┴──────┘
110
+ >>> pl.concat([df1, df2, df3], how="alignLeft");
111
+ shape: (2, 4)
112
+ ┌─────┬─────┬──────┬──────┐
113
+ │ id ┆ x ┆ y ┆ z │
114
+ │ --- ┆ --- ┆ --- ┆ --- │
115
+ │ i64 ┆ i64 ┆ i64 ┆ i64 │
116
+ ╞═════╪═════╪══════╪══════╡
117
+ │ 1 ┆ 3 ┆ null ┆ 7 │
118
+ │ 2 ┆ 4 ┆ 5 ┆ null │
119
+ └─────┴─────┴──────┴──────┘
120
+ >>> pl.concat([df1, df2, df3], how="alignRight");
121
+ shape: (2, 4)
122
+ ┌─────┬──────┬──────┬─────┐
123
+ │ id ┆ x ┆ y ┆ z │
124
+ │ --- ┆ --- ┆ --- ┆ --- │
125
+ │ i64 ┆ i64 ┆ i64 ┆ i64 │
126
+ ╞═════╪══════╪══════╪═════╡
127
+ │ 1 ┆ null ┆ null ┆ 7 │
128
+ │ 3 ┆ null ┆ 6 ┆ 8 │
129
+ └─────┴──────┴──────┴─────┘
130
+ >>> pl.concat([df1, df2, df3], how="alignInner");
131
+ shape: (0, 4)
132
+ ┌─────┬─────┬─────┬─────┐
133
+ │ id ┆ x ┆ y ┆ z │
134
+ │ --- ┆ --- ┆ --- ┆ --- │
135
+ │ i64 ┆ i64 ┆ i64 ┆ i64 │
136
+ ╞═════╪═════╪═════╪═════╡
137
+ └─────┴─────┴─────┴─────┘
138
+ */
139
+ const computeAlignParams = (items, how) => {
140
+ const commonCols = (0, utils_1.commonValue)(...items.map((c) => c.columns));
141
+ const uniqueCols = [...new Set(items.flatMap((c) => c.columns))].sort();
142
+ // Join methods allowed: "full" | "left" | "inner" | "semi" | "anti" | undefined
143
+ const joinMethod = how === "align"
144
+ ? "full"
145
+ : how.replace("align", "").toLocaleLowerCase();
146
+ return { commonCols, uniqueCols, joinMethod };
147
+ };
148
+ function concat(items, options = { rechunk: true, parallel: true, how: "vertical" }) {
149
+ const { rechunk, how, parallel } = options;
150
+ if (!items.length) {
151
+ throw new RangeError("cannot concat empty list");
152
+ }
153
+ // short-circuit common single-item cases early for all types
154
+ if (items.length === 1)
155
+ return items[0];
156
+ if ((0, utils_1.isDataFrameArray)(items)) {
157
+ let df;
158
+ switch (how) {
159
+ case "align":
160
+ case "alignFull":
161
+ case "alignInner":
162
+ case "alignLeft":
163
+ case "alignRight": {
164
+ const { commonCols, uniqueCols, joinMethod } = computeAlignParams(items, how);
165
+ df = (0, dataframe_1._DataFrame)(items.reduce((acc, curr) => acc.join(curr, { on: commonCols, how: joinMethod, coalesce: true })))
166
+ ._df.sort(commonCols)
167
+ .select(uniqueCols);
168
+ break;
169
+ }
170
+ case "vertical":
171
+ df = items.reduce((acc, curr) => acc.vstack(curr));
172
+ break;
173
+ case "verticalRelaxed":
174
+ case "diagonalRelaxed":
175
+ df = (0, dataframe_2._LazyDataFrame)(polars_internal_1.default.concatLf(items.map((i) => i.inner().lazy()), how, rechunk ?? false, parallel ?? true, true, // to_supertypes
176
+ true)).collectSync();
177
+ break;
178
+ case "horizontal":
179
+ df = (0, dataframe_1._DataFrame)(polars_internal_1.default.horizontalConcat(items.map((i) => i.inner())));
180
+ break;
181
+ case "diagonal":
182
+ df = (0, dataframe_1._DataFrame)(polars_internal_1.default.diagonalConcat(items.map((i) => i.inner())));
183
+ break;
184
+ default:
185
+ throw new TypeError("unknown concat how option");
186
+ }
187
+ return rechunk ? df.rechunk() : df;
188
+ }
189
+ if ((0, utils_1.isLazyDataFrameArray)(items)) {
190
+ let df;
191
+ if (how?.startsWith("align")) {
192
+ const { commonCols, uniqueCols, joinMethod } = computeAlignParams(items, how);
193
+ df = (0, dataframe_2._LazyDataFrame)(items.reduce((acc, curr) => acc.join(curr, { on: commonCols, how: joinMethod, coalesce: true })))
194
+ ._ldf.sort(commonCols)
195
+ .select(uniqueCols);
196
+ }
197
+ else {
198
+ df = (0, dataframe_2._LazyDataFrame)(polars_internal_1.default.concatLf(items.map((i) => i.inner()), how, rechunk ?? false, parallel ?? true, true, // to_supertypes
199
+ true));
200
+ }
201
+ return df;
202
+ }
203
+ if ((0, utils_1.isSeriesArray)(items)) {
204
+ const s = items.reduce((acc, curr) => acc.concat(curr));
205
+ return rechunk ? s.rechunk() : s;
206
+ }
207
+ throw new TypeError("can only concat series and dataframes");
208
+ }
@@ -0,0 +1,173 @@
1
+ import { type DataFrame } from "./dataframe";
2
+ import type { Expr } from "./lazy/expr";
3
+ import type { ColumnsOrExpr, StartBy } from "./utils";
4
+ declare const inspect: unique symbol;
5
+ /**
6
+ * Starts a new GroupBy operation.
7
+ */
8
+ export interface GroupBy {
9
+ [inspect](): string;
10
+ /**
11
+ * Aggregate the groups into Series.
12
+ */
13
+ aggList(): DataFrame;
14
+ /**
15
+ * __Use multiple aggregations on columns.__
16
+ * This can be combined with complete lazy API and is considered idiomatic polars.
17
+ * ___
18
+ * @param columns - map of 'col' -> 'agg'
19
+ *
20
+ * - using lazy API (recommended): `[col('foo').sum(), col('bar').min()]`
21
+ * - using multiple aggs per column: `{'foo': ['sum', 'numUnique'], 'bar': ['min'] }`
22
+ * - using single agg per column: `{'foo': ['sum'], 'bar': 'min' }`
23
+ * @example
24
+ * ```
25
+ * // use lazy api rest parameter style
26
+ * > df.groupBy('foo', 'bar')
27
+ * > .agg(pl.sum('ham'), col('spam').tail(4).sum())
28
+ *
29
+ * // use lazy api array style
30
+ * > df.groupBy('foo', 'bar')
31
+ * > .agg([pl.sum('ham'), col('spam').tail(4).sum()])
32
+ *
33
+ * // use a mapping
34
+ * > df.groupBy('foo', 'bar')
35
+ * > .agg({'spam': ['sum', 'min']})
36
+ *
37
+ * ```
38
+ */
39
+ agg(...columns: Expr[]): DataFrame;
40
+ agg(columns: Record<string, keyof Expr | (keyof Expr)[]>): DataFrame;
41
+ /**
42
+ * Return the number of rows in each group.
43
+ */
44
+ len(): DataFrame;
45
+ /**
46
+ * Aggregate the first values in the group.
47
+ */
48
+ first(): DataFrame;
49
+ /**
50
+ * Return a `DataFrame` with:
51
+ * - the groupby keys
52
+ * - the group indexes aggregated as lists
53
+ */
54
+ groups(): DataFrame;
55
+ /**
56
+ * Return first n rows of each group.
57
+ * @param n -Number of values of the group to select
58
+ * @example
59
+ * ```
60
+ * > df = pl.DataFrame({
61
+ * > "letters": ["c", "c", "a", "c", "a", "b"],
62
+ * > "nrs": [1, 2, 3, 4, 5, 6]
63
+ * > })
64
+ * > df
65
+ * shape: (6, 2)
66
+ * ╭─────────┬─────╮
67
+ * │ letters ┆ nrs │
68
+ * │ --- ┆ --- │
69
+ * │ str ┆ i64 │
70
+ * ╞═════════╪═════╡
71
+ * │ "c" ┆ 1 │
72
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
73
+ * │ "c" ┆ 2 │
74
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
75
+ * │ "a" ┆ 3 │
76
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
77
+ * │ "c" ┆ 4 │
78
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
79
+ * │ "a" ┆ 5 │
80
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
81
+ * │ "b" ┆ 6 │
82
+ * ╰─────────┴─────╯
83
+ * > df.groupby("letters")
84
+ * > .head(2)
85
+ * > .sort("letters");
86
+ * > >>
87
+ * shape: (5, 2)
88
+ * ╭─────────┬─────╮
89
+ * │ letters ┆ nrs │
90
+ * │ --- ┆ --- │
91
+ * │ str ┆ i64 │
92
+ * ╞═════════╪═════╡
93
+ * │ "a" ┆ 3 │
94
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
95
+ * │ "a" ┆ 5 │
96
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
97
+ * │ "b" ┆ 6 │
98
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
99
+ * │ "c" ┆ 1 │
100
+ * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
101
+ * │ "c" ┆ 2 │
102
+ * ╰─────────┴─────╯
103
+ * ```
104
+ */
105
+ head(n?: number): DataFrame;
106
+ /**
107
+ * Aggregate the last values in the group.
108
+ */
109
+ last(): DataFrame;
110
+ /**
111
+ * Reduce the groups to the maximal value.
112
+ */
113
+ max(): DataFrame;
114
+ /**
115
+ * Reduce the groups to the mean values.
116
+ */
117
+ mean(): DataFrame;
118
+ /**
119
+ * Return the median per group.
120
+ */
121
+ median(): DataFrame;
122
+ /**
123
+ * Reduce the groups to the minimal value.
124
+ */
125
+ min(): DataFrame;
126
+ /**
127
+ * Count the unique values per group.
128
+ */
129
+ nUnique(): DataFrame;
130
+ /**
131
+ * Do a pivot operation based on the group key, a pivot column and an aggregation function on the values column.
132
+ * @param pivotCol - Column to pivot.
133
+ * @param valuesCol - Column that will be aggregated.
134
+ *
135
+ */
136
+ pivot(pivotCol: string, valuesCol: string): PivotOps;
137
+ pivot({ pivotCol, valuesCol, }: {
138
+ pivotCol: string;
139
+ valuesCol: string;
140
+ }): PivotOps;
141
+ /**
142
+ * Compute the quantile per group.
143
+ */
144
+ quantile(quantile: number): DataFrame;
145
+ /**
146
+ * Reduce the groups to the sum.
147
+ */
148
+ sum(): DataFrame;
149
+ tail(n?: number): DataFrame;
150
+ toString(): string;
151
+ }
152
+ export type PivotOps = Pick<GroupBy, "len" | "first" | "max" | "mean" | "median" | "min" | "sum"> & {
153
+ [inspect](): string;
154
+ };
155
+ /** @ignore */
156
+ export declare function _GroupBy(df: any, by: string[], maintainOrder?: boolean): GroupBy;
157
+ /**
158
+ * intermediate state of a rolling groupby
159
+ */
160
+ export interface RollingGroupBy {
161
+ agg(column: ColumnsOrExpr, ...columns: ColumnsOrExpr[]): DataFrame;
162
+ }
163
+ /** @ignore */
164
+ export declare function RollingGroupBy(df: any, indexColumn: ColumnsOrExpr, period: string, offset?: string, closed?: any, by?: ColumnsOrExpr): RollingGroupBy;
165
+ /**
166
+ * intermediate state of a dynamic groupby
167
+ */
168
+ export interface DynamicGroupBy {
169
+ agg(column: ColumnsOrExpr, ...columns: ColumnsOrExpr[]): DataFrame;
170
+ }
171
+ /** @ignore */
172
+ export declare function DynamicGroupBy(df: any, indexColumn: string, every: string, period?: string, offset?: string, label?: string, includeBoundaries?: boolean, closed?: string, by?: ColumnsOrExpr, startBy?: StartBy): DynamicGroupBy;
173
+ export {};