@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,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExprStringFunctions = void 0;
4
+ const datatypes_1 = require("../../datatypes");
5
+ const expr_1 = require("../expr");
6
+ const functions_1 = require("../functions");
7
+ const ExprStringFunctions = (_expr) => {
8
+ const wrap = (method, ...args) => {
9
+ return (0, expr_1._Expr)(_expr[method](...args));
10
+ };
11
+ const handleDecode = (encoding, strict) => {
12
+ switch (encoding) {
13
+ case "hex":
14
+ return wrap("strHexDecode", strict);
15
+ case "base64":
16
+ return wrap("strBase64Decode", strict);
17
+ default:
18
+ throw new RangeError("supported encodings are 'hex' and 'base64'");
19
+ }
20
+ };
21
+ return {
22
+ concat(delimiter, ignoreNulls = true) {
23
+ return wrap("strConcat", delimiter, ignoreNulls);
24
+ },
25
+ contains(pat, literal = false, strict = true) {
26
+ return wrap("strContains", (0, expr_1.exprToLitOrExpr)(pat)._expr, literal, strict);
27
+ },
28
+ decode(arg, strict = false) {
29
+ if (typeof arg === "string") {
30
+ return handleDecode(arg, strict);
31
+ }
32
+ return handleDecode(arg.encoding, arg.strict);
33
+ },
34
+ encode(encoding) {
35
+ switch (encoding) {
36
+ case "hex":
37
+ return wrap("strHexEncode");
38
+ case "base64":
39
+ return wrap("strBase64Encode");
40
+ default:
41
+ throw new RangeError("supported encodings are 'hex' and 'base64'");
42
+ }
43
+ },
44
+ endsWith(suffix) {
45
+ return wrap("strEndsWith", (0, expr_1.exprToLitOrExpr)(suffix)._expr);
46
+ },
47
+ extract(pattern, groupIndex) {
48
+ return wrap("strExtract", (0, expr_1.exprToLitOrExpr)(pattern, true)._expr, groupIndex);
49
+ },
50
+ jsonDecode(dtype) {
51
+ if (!dtype)
52
+ throw new Error("`Expr.str.json_decode` needs an explicitly given `dtype` otherwise Polars is not able to determine the output type. If you want to eagerly infer datatype you can use `Series.str.json_decode`.");
53
+ return wrap("strJsonDecode", dtype);
54
+ },
55
+ jsonPathMatch(pat) {
56
+ return wrap("strJsonPathMatch", [pat]);
57
+ },
58
+ lengths() {
59
+ return wrap("strLengths");
60
+ },
61
+ lstrip() {
62
+ return wrap("strLstrip");
63
+ },
64
+ replace(pat, val, literal = false, n = 1) {
65
+ return wrap("strReplace", (0, expr_1.exprToLitOrExpr)(pat)._expr, (0, expr_1.exprToLitOrExpr)(val)._expr, literal, n);
66
+ },
67
+ replaceAll(pat, val, literal = false) {
68
+ return wrap("strReplaceAll", (0, expr_1.exprToLitOrExpr)(pat)._expr, (0, expr_1.exprToLitOrExpr)(val)._expr, literal);
69
+ },
70
+ rstrip() {
71
+ return wrap("strRstrip");
72
+ },
73
+ padStart(length, fillChar) {
74
+ return wrap("strPadStart", (0, functions_1.lit)(length)._expr, fillChar);
75
+ },
76
+ zFill(length) {
77
+ if (!expr_1.Expr.isExpr(length)) {
78
+ length = (0, functions_1.lit)(length)._expr;
79
+ }
80
+ return wrap("zfill", length);
81
+ },
82
+ padEnd(length, fillChar) {
83
+ return wrap("strPadEnd", (0, functions_1.lit)(length)._expr, fillChar);
84
+ },
85
+ slice(start, length) {
86
+ if (!expr_1.Expr.isExpr(start)) {
87
+ start = (0, functions_1.lit)(start)._expr;
88
+ }
89
+ if (!expr_1.Expr.isExpr(length)) {
90
+ length = (0, functions_1.lit)(length)._expr;
91
+ }
92
+ return wrap("strSlice", start, length);
93
+ },
94
+ split(by, options) {
95
+ const inclusive = typeof options === "boolean" ? options : options?.inclusive;
96
+ return wrap("strSplit", (0, expr_1.exprToLitOrExpr)(by)._expr, inclusive);
97
+ },
98
+ startsWith(prefix) {
99
+ return wrap("strStartsWith", (0, expr_1.exprToLitOrExpr)(prefix)._expr);
100
+ },
101
+ strip() {
102
+ return wrap("strStrip");
103
+ },
104
+ stripChars(pattern) {
105
+ return wrap("strStripChars", (0, expr_1.exprToLitOrExpr)(pattern)._expr, true, true);
106
+ },
107
+ stripCharsEnd(pattern) {
108
+ return wrap("strStripChars", (0, expr_1.exprToLitOrExpr)(pattern)._expr, false, true);
109
+ },
110
+ stripCharsStart(pattern) {
111
+ return wrap("strStripChars", (0, expr_1.exprToLitOrExpr)(pattern)._expr, true, false);
112
+ },
113
+ strptime(dtype, format) {
114
+ const dt = dtype instanceof datatypes_1.DataType ? dtype : dtype();
115
+ if (dt.equals(datatypes_1.DataType.Date)) {
116
+ return wrap("strToDate", format, false, false, false);
117
+ }
118
+ if (dt.equals(datatypes_1.DataType.Datetime("ms"))) {
119
+ return wrap("strToDatetime", format, undefined, undefined, false, false, false, undefined);
120
+ }
121
+ throw new Error(`only "DataType.Date" and "DataType.Datetime" are supported`);
122
+ },
123
+ toLowerCase() {
124
+ return wrap("strToLowercase");
125
+ },
126
+ toUpperCase() {
127
+ return wrap("strToUppercase");
128
+ },
129
+ };
130
+ };
131
+ exports.ExprStringFunctions = ExprStringFunctions;
@@ -0,0 +1,126 @@
1
+ import { type Expr } from "../expr";
2
+ /**
3
+ * Struct functions for Lazy datatframes
4
+ */
5
+ export interface ExprStruct {
6
+ /**
7
+ * Access a field by name
8
+ * @param name - name of the field
9
+ * @example
10
+ * pl.DataFrame({
11
+ objs: [
12
+ { a: 1, b: 2.0, c: "abc" },
13
+ { a: 10, b: 20.0, c: "def" },
14
+ ],
15
+ }).select(
16
+ col("objs").struct.field("b"),
17
+ col("objs").struct.field("c").as("last")
18
+ );
19
+ >>shape: (2, 2)
20
+ ┌──────┬──────┐
21
+ │ b ┆ last │
22
+ │ --- ┆ --- │
23
+ │ f64 ┆ str │
24
+ ╞══════╪══════╡
25
+ │ 2.0 ┆ abc │
26
+ │ 20.0 ┆ def │
27
+ └──────┴──────┘
28
+ */
29
+ field(name: string): Expr;
30
+ /**
31
+ * Access a field by index (zero based index)
32
+ * @param index - index of the field (starts at 0)
33
+ *
34
+ * @example
35
+ * pl.DataFrame({
36
+ objs: [
37
+ { a: 1, b: 2.0, c: "abc" },
38
+ { a: 10, b: 20.0, c: "def" },
39
+ ],
40
+ }).select(
41
+ col("objs").struct.nth(1),
42
+ col("objs").struct.nth(2).as("last"),
43
+ );
44
+ >>shape: (2, 2)
45
+ ┌──────┬──────┐
46
+ │ b ┆ last │
47
+ │ --- ┆ --- │
48
+ │ f64 ┆ str │
49
+ ╞══════╪══════╡
50
+ │ 2.0 ┆ abc │
51
+ │ 20.0 ┆ def │
52
+ └──────┴──────┘
53
+ */
54
+ nth(index: number): Expr;
55
+ /**
56
+ * Rename the fields of a struct
57
+ * @param names - new names of the fields
58
+ *
59
+ * @example
60
+ * pl.DataFrame({
61
+ objs: [
62
+ { a: 1, b: 2.0, c: "abc" },
63
+ { a: 10, b: 20.0, c: "def" },
64
+ ]}).select(col("objs").struct.renameFields(["a", "b", "c"]));
65
+ >>shape: (2, 1)
66
+ ┌───────────────────┐
67
+ │ objs │
68
+ │ --- │
69
+ │ struct[3] │
70
+ ╞═══════════════════╡
71
+ │ {1.0,2.0,"abc"} │
72
+ │ {10.0,20.0,"def"} │
73
+ └───────────────────┘
74
+ */
75
+ renameFields(names: string[]): Expr;
76
+ /**
77
+ * Add/replace fields in a struct
78
+ * @param fields - array of expressions for new fields
79
+ *
80
+ * @example
81
+ * pl.DataFrame({
82
+ objs: [
83
+ { a: 1, b: 2.0, c: "abc" },
84
+ { a: 10, b: 20.0, c: "def" },
85
+ ],
86
+ more: ["text1", "text2"],
87
+ final: [100, null],
88
+ }).select(
89
+ col("objs").struct.withFields([
90
+ pl.lit(null).alias("d"),
91
+ pl.lit("text").alias("e"),
92
+ ]),
93
+ col("objs")
94
+ .struct.withFields([col("more"), col("final")])
95
+ .alias("new"),
96
+ );
97
+ shape: (2, 2)
98
+ ┌───────────────────────────────┬────────────────────────────────┐
99
+ │ objs ┆ new │
100
+ │ --- ┆ --- │
101
+ │ struct[5] ┆ struct[5] │
102
+ ╞═══════════════════════════════╪════════════════════════════════╡
103
+ │ {1.0,2.0,"abc",null,"text"} ┆ {1.0,2.0,"abc","text1",100.0} │
104
+ │ {10.0,20.0,"def",null,"text"} ┆ {10.0,20.0,"def","text2",null} │
105
+ └───────────────────────────────┴────────────────────────────────┘
106
+ */
107
+ withFields(fields: Expr[]): Expr;
108
+ /**
109
+ * Convert this struct to a string column with json values.
110
+ *
111
+ * @example
112
+ * pl.DataFrame( {"a": [{"a": [1, 2], "b": [45]}, {"a": [9, 1, 3], "b": null}]}
113
+ ).withColumn(pl.col("a").struct.jsonEncode().alias("encoded"))
114
+ shape: (2, 2)
115
+ ┌──────────────────┬────────────────────────┐
116
+ │ a ┆ encoded │
117
+ │ --- ┆ --- │
118
+ │ struct[2] ┆ str │
119
+ ╞══════════════════╪════════════════════════╡
120
+ │ {[1, 2],[45]} ┆ {"a":[1,2],"b":[45]} │
121
+ │ {[9, 1, 3],null} ┆ {"a":[9,1,3],"b":null} │
122
+ └──────────────────┴────────────────────────┘
123
+ */
124
+ jsonEncode(): Expr;
125
+ }
126
+ export declare const ExprStructFunctions: (_expr: any) => ExprStruct;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExprStructFunctions = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const expr_1 = require("../expr");
6
+ const ExprStructFunctions = (_expr) => {
7
+ return {
8
+ field(name) {
9
+ return (0, expr_1._Expr)(_expr.structFieldByName(name));
10
+ },
11
+ nth(index) {
12
+ return (0, expr_1._Expr)(_expr.structFieldByIndex(index));
13
+ },
14
+ renameFields(names) {
15
+ return (0, expr_1._Expr)(_expr.structRenameFields(names));
16
+ },
17
+ withFields(fields) {
18
+ fields = (0, utils_1.selectionToExprList)(fields, false);
19
+ return (0, expr_1._Expr)(_expr.structWithFields(fields));
20
+ },
21
+ jsonEncode() {
22
+ return (0, expr_1._Expr)(_expr.structJsonEncode());
23
+ },
24
+ };
25
+ };
26
+ exports.ExprStructFunctions = ExprStructFunctions;