@ohos-ports/nodejs-polars 0.23.4-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +217 -0
- package/bin/cfg.d.ts +156 -0
- package/bin/cfg.js +52 -0
- package/bin/dataframe.d.ts +2135 -0
- package/bin/dataframe.js +783 -0
- package/bin/datatypes/conversion.d.ts +2 -0
- package/bin/datatypes/conversion.js +2 -0
- package/bin/datatypes/datatype.d.ts +285 -0
- package/bin/datatypes/datatype.js +430 -0
- package/bin/datatypes/field.d.ts +26 -0
- package/bin/datatypes/field.js +36 -0
- package/bin/datatypes/index.d.ts +43 -0
- package/bin/datatypes/index.js +120 -0
- package/bin/error.d.ts +7 -0
- package/bin/error.js +17 -0
- package/bin/functions.d.ts +26 -0
- package/bin/functions.js +208 -0
- package/bin/groupby.d.ts +212 -0
- package/bin/groupby.js +156 -0
- package/bin/html.d.ts +4 -0
- package/bin/html.js +18 -0
- package/bin/index.d.ts +256 -0
- package/bin/index.js +267 -0
- package/bin/internals/construction.d.ts +7 -0
- package/bin/internals/construction.js +256 -0
- package/bin/internals/polars_internal.d.ts +2 -0
- package/bin/internals/polars_internal.js +7 -0
- package/bin/io.d.ts +433 -0
- package/bin/io.js +344 -0
- package/bin/lazy/dataframe.d.ts +785 -0
- package/bin/lazy/dataframe.js +427 -0
- package/bin/lazy/expr/datetime.d.ts +8 -0
- package/bin/lazy/expr/datetime.js +27 -0
- package/bin/lazy/expr/index.d.ts +1152 -0
- package/bin/lazy/expr/index.js +632 -0
- package/bin/lazy/expr/list.d.ts +8 -0
- package/bin/lazy/expr/list.js +115 -0
- package/bin/lazy/expr/string.d.ts +534 -0
- package/bin/lazy/expr/string.js +131 -0
- package/bin/lazy/expr/struct.d.ts +126 -0
- package/bin/lazy/expr/struct.js +26 -0
- package/bin/lazy/functions.d.ts +612 -0
- package/bin/lazy/functions.js +687 -0
- package/bin/lazy/groupby.d.ts +29 -0
- package/bin/lazy/groupby.js +30 -0
- package/bin/lazy/index.d.ts +4 -0
- package/bin/lazy/index.js +20 -0
- package/bin/lazy/whenthen.d.ts +67 -0
- package/bin/lazy/whenthen.js +81 -0
- package/bin/native-polars.d.ts +2 -0
- package/bin/native-polars.js +267 -0
- package/bin/series/datetime.d.ts +8 -0
- package/bin/series/datetime.js +34 -0
- package/bin/series/index.d.ts +1135 -0
- package/bin/series/index.js +700 -0
- package/bin/series/list.d.ts +8 -0
- package/bin/series/list.js +87 -0
- package/bin/series/string.d.ts +300 -0
- package/bin/series/string.js +125 -0
- package/bin/series/struct.d.ts +36 -0
- package/bin/series/struct.js +35 -0
- package/bin/shared_traits.d.ts +1458 -0
- package/bin/shared_traits.js +2 -0
- package/bin/sql.d.ts +244 -0
- package/bin/sql.js +63 -0
- package/bin/types.d.ts +287 -0
- package/bin/types.js +2 -0
- package/bin/utils.d.ts +38 -0
- package/bin/utils.js +69 -0
- package/package.json +45 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SeriesListFunctions = void 0;
|
|
4
|
+
const functions_1 = require("../lazy/functions");
|
|
5
|
+
const _1 = require(".");
|
|
6
|
+
const SeriesListFunctions = (_s) => {
|
|
7
|
+
const wrap = (method, ...args) => {
|
|
8
|
+
const s = (0, _1._Series)(_s);
|
|
9
|
+
return s
|
|
10
|
+
.toFrame()
|
|
11
|
+
.select((0, functions_1.col)(s.name)
|
|
12
|
+
.lst[method](...args)
|
|
13
|
+
.as(s.name))
|
|
14
|
+
.getColumn(s.name);
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
argMax() {
|
|
18
|
+
return wrap("argMax");
|
|
19
|
+
},
|
|
20
|
+
argMin() {
|
|
21
|
+
return wrap("argMin");
|
|
22
|
+
},
|
|
23
|
+
concat(other) {
|
|
24
|
+
return wrap("concat", other);
|
|
25
|
+
},
|
|
26
|
+
contains(item) {
|
|
27
|
+
return wrap("contains", item);
|
|
28
|
+
},
|
|
29
|
+
diff(n, nullBehavior) {
|
|
30
|
+
return wrap("diff", n, nullBehavior);
|
|
31
|
+
},
|
|
32
|
+
get(index) {
|
|
33
|
+
return wrap("get", index);
|
|
34
|
+
},
|
|
35
|
+
eval(expr) {
|
|
36
|
+
return wrap("eval", expr);
|
|
37
|
+
},
|
|
38
|
+
first() {
|
|
39
|
+
return wrap("get", 0);
|
|
40
|
+
},
|
|
41
|
+
head(n = 5) {
|
|
42
|
+
return this.slice(0, n);
|
|
43
|
+
},
|
|
44
|
+
tail(n = 5) {
|
|
45
|
+
return this.slice(-n, n);
|
|
46
|
+
},
|
|
47
|
+
join(options) {
|
|
48
|
+
return wrap("join", options);
|
|
49
|
+
},
|
|
50
|
+
last() {
|
|
51
|
+
return wrap("get", -1);
|
|
52
|
+
},
|
|
53
|
+
lengths() {
|
|
54
|
+
return wrap("lengths");
|
|
55
|
+
},
|
|
56
|
+
max() {
|
|
57
|
+
return wrap("max");
|
|
58
|
+
},
|
|
59
|
+
mean() {
|
|
60
|
+
return wrap("mean");
|
|
61
|
+
},
|
|
62
|
+
min() {
|
|
63
|
+
return wrap("min");
|
|
64
|
+
},
|
|
65
|
+
reverse() {
|
|
66
|
+
return wrap("reverse");
|
|
67
|
+
},
|
|
68
|
+
shift(n) {
|
|
69
|
+
return wrap("shift", n);
|
|
70
|
+
},
|
|
71
|
+
slice(offset, length) {
|
|
72
|
+
return wrap("slice", offset, length);
|
|
73
|
+
},
|
|
74
|
+
sort(descending = false) {
|
|
75
|
+
return typeof descending === "boolean"
|
|
76
|
+
? wrap("sort", descending)
|
|
77
|
+
: wrap("sort", descending.descending ?? false);
|
|
78
|
+
},
|
|
79
|
+
sum() {
|
|
80
|
+
return wrap("sum");
|
|
81
|
+
},
|
|
82
|
+
unique() {
|
|
83
|
+
return wrap("unique");
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
exports.SeriesListFunctions = SeriesListFunctions;
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import type { DataType } from "../datatypes";
|
|
2
|
+
import type { Expr } from "./../lazy/expr/index";
|
|
3
|
+
import type { StringFunctions } from "../shared_traits";
|
|
4
|
+
import { type Series } from ".";
|
|
5
|
+
/**
|
|
6
|
+
* String functions for Series
|
|
7
|
+
*/
|
|
8
|
+
export interface SeriesStringFunctions extends StringFunctions<Series> {
|
|
9
|
+
/**
|
|
10
|
+
* Vertically concat the values in the Series to a single string value.
|
|
11
|
+
* @example
|
|
12
|
+
* ```
|
|
13
|
+
* > pl.Series([1, null, 2]).str.concat("-")[0]
|
|
14
|
+
* '1-null-2'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
concat(delimiter: string, ignoreNulls?: boolean): Series;
|
|
18
|
+
/**
|
|
19
|
+
* Check if strings in Series contain a substring that matches a pattern.
|
|
20
|
+
* @param pat A valid regular expression pattern, compatible with the `regex crate
|
|
21
|
+
* @param literal Treat `pattern` as a literal string, not as a regular expression.
|
|
22
|
+
* @param strict Raise an error if the underlying pattern is not a valid regex, otherwise mask out with a null value.
|
|
23
|
+
* @returns Boolean mask
|
|
24
|
+
* @example
|
|
25
|
+
* ```
|
|
26
|
+
* > pl.Series(["Crab", "cat and dog", "rab$bit", null]).str.contains("cat|bit")
|
|
27
|
+
* shape: (4,)
|
|
28
|
+
* Series: '' [bool]
|
|
29
|
+
* [
|
|
30
|
+
false
|
|
31
|
+
true
|
|
32
|
+
true
|
|
33
|
+
null
|
|
34
|
+
* ]
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
contains(pat: string | RegExp, literal?: boolean, strict?: boolean): Series;
|
|
38
|
+
/**
|
|
39
|
+
* Decodes a value in Series using the provided encoding
|
|
40
|
+
* @param encoding - hex | base64
|
|
41
|
+
* @param strict - how to handle invalid inputs
|
|
42
|
+
*
|
|
43
|
+
* - true: method will throw error if unable to decode a value
|
|
44
|
+
* - false: unhandled values will be replaced with `null`
|
|
45
|
+
* @example
|
|
46
|
+
* ```
|
|
47
|
+
* s = pl.Series("strings", ["666f6f", "626172", null])
|
|
48
|
+
* s.str.decode("hex")
|
|
49
|
+
* shape: (3,)
|
|
50
|
+
* Series: 'strings' [str]
|
|
51
|
+
* [
|
|
52
|
+
* "foo",
|
|
53
|
+
* "bar",
|
|
54
|
+
* null
|
|
55
|
+
* ]
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
decode(encoding: "hex" | "base64", strict?: boolean): Series;
|
|
59
|
+
decode(options: {
|
|
60
|
+
encoding: "hex" | "base64";
|
|
61
|
+
strict?: boolean;
|
|
62
|
+
}): Series;
|
|
63
|
+
/**
|
|
64
|
+
* Encodes a value in Series using the provided encoding
|
|
65
|
+
* @param encoding - hex | base64
|
|
66
|
+
* @example
|
|
67
|
+
* ```
|
|
68
|
+
* s = pl.Series("strings", ["foo", "bar", null])
|
|
69
|
+
* s.str.encode("hex")
|
|
70
|
+
* shape: (3,)
|
|
71
|
+
* Series: 'strings' [str]
|
|
72
|
+
* [
|
|
73
|
+
* "666f6f",
|
|
74
|
+
* "626172",
|
|
75
|
+
* null
|
|
76
|
+
* ]
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
encode(encoding: "hex" | "base64"): Series;
|
|
80
|
+
/**
|
|
81
|
+
* Extract the target capture group from provided patterns.
|
|
82
|
+
* @param pattern A valid regex pattern
|
|
83
|
+
* @param groupIndex Index of the targeted capture group.
|
|
84
|
+
* Group 0 mean the whole pattern, first group begin at index 1
|
|
85
|
+
* Default to the first capture group
|
|
86
|
+
* @returns Utf8 array. Contain null if original value is null or regex capture nothing.
|
|
87
|
+
* @example
|
|
88
|
+
* ```
|
|
89
|
+
* > df = pl.DataFrame({
|
|
90
|
+
* ... 'a': [
|
|
91
|
+
* ... 'http://vote.com/ballon_dor?candidate=messi&ref=polars',
|
|
92
|
+
* ... 'http://vote.com/ballon_dor?candidat=jorginho&ref=polars',
|
|
93
|
+
* ... 'http://vote.com/ballon_dor?candidate=ronaldo&ref=polars'
|
|
94
|
+
* ... ]})
|
|
95
|
+
* > df.getColumn("a").str.extract(/candidate=(\w+)/, 1)
|
|
96
|
+
* shape: (3, 1)
|
|
97
|
+
* ┌─────────┐
|
|
98
|
+
* │ a │
|
|
99
|
+
* │ --- │
|
|
100
|
+
* │ str │
|
|
101
|
+
* ╞═════════╡
|
|
102
|
+
* │ messi │
|
|
103
|
+
* ├╌╌╌╌╌╌╌╌╌┤
|
|
104
|
+
* │ null │
|
|
105
|
+
* ├╌╌╌╌╌╌╌╌╌┤
|
|
106
|
+
* │ ronaldo │
|
|
107
|
+
* └─────────┘
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
extract(pattern: string | RegExp, groupIndex: number): Series;
|
|
111
|
+
/***
|
|
112
|
+
* Parse string values in Series as JSON.
|
|
113
|
+
* @returns Utf8 array. Contain null if original value is null or the `jsonPath` return nothing.
|
|
114
|
+
* @example
|
|
115
|
+
* s = pl.Series("json", ['{"a":1, "b": true}', null, '{"a":2, "b": false}']);
|
|
116
|
+
* s.str.jsonDecode().as("json");
|
|
117
|
+
* shape: (3,)
|
|
118
|
+
* Series: 'json' [struct[2]]
|
|
119
|
+
* [
|
|
120
|
+
* {1,true}
|
|
121
|
+
* {null,null}
|
|
122
|
+
* {2,false}
|
|
123
|
+
* ]
|
|
124
|
+
*/
|
|
125
|
+
jsonDecode(dtype?: DataType, inferSchemaLength?: number): Series;
|
|
126
|
+
/**
|
|
127
|
+
* Extract the first match of json string in Series with provided JSONPath expression.
|
|
128
|
+
* Throw errors if encounter invalid json strings.
|
|
129
|
+
* All return value will be casted to Utf8 regardless of the original value.
|
|
130
|
+
* @see https://goessner.net/articles/JsonPath/
|
|
131
|
+
* @param jsonPath - A valid JSON path query string
|
|
132
|
+
* @returns Utf8 array. Contain null if original value is null or the `jsonPath` return nothing.
|
|
133
|
+
* @example
|
|
134
|
+
* ```
|
|
135
|
+
* > s = pl.Series('json_val', [
|
|
136
|
+
* ... '{"a":"1"}',
|
|
137
|
+
* ... null,
|
|
138
|
+
* ... '{"a":2}',
|
|
139
|
+
* ... '{"a":2.1}',
|
|
140
|
+
* ... '{"a":true}'
|
|
141
|
+
* ... ])
|
|
142
|
+
* > s.str.jsonPathMatch('$.a')
|
|
143
|
+
* shape: (5,)
|
|
144
|
+
* Series: 'json_val' [str]
|
|
145
|
+
* [
|
|
146
|
+
* "1"
|
|
147
|
+
* null
|
|
148
|
+
* "2"
|
|
149
|
+
* "2.1"
|
|
150
|
+
* "true"
|
|
151
|
+
* ]
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
jsonPathMatch(jsonPath: string): Series;
|
|
155
|
+
/** Get number of chars of the string values in Series.
|
|
156
|
+
* df = pl.Series(["Café", "345", "東京", null])
|
|
157
|
+
* .str.lengths().alias("n_chars")
|
|
158
|
+
* shape: (4,)
|
|
159
|
+
* Series: 'n_chars' [u32]
|
|
160
|
+
* [
|
|
161
|
+
* 4
|
|
162
|
+
* 3
|
|
163
|
+
* 2
|
|
164
|
+
* null
|
|
165
|
+
* ]
|
|
166
|
+
*/
|
|
167
|
+
lengths(): Series;
|
|
168
|
+
/** Remove leading whitespace of the string values in Series. */
|
|
169
|
+
lstrip(): Series;
|
|
170
|
+
/**
|
|
171
|
+
* Add a leading fillChar to a string in Series until string length is reached.
|
|
172
|
+
* If string is longer or equal to given length no modifications will be done
|
|
173
|
+
* @param {number} length - of the final string
|
|
174
|
+
* @param {string} fillChar - that will fill the string.
|
|
175
|
+
* If a string longer than 1 character is provided only the first character will be used
|
|
176
|
+
* @example
|
|
177
|
+
* ```
|
|
178
|
+
* > df = pl.DataFrame({
|
|
179
|
+
* ... 'foo': [
|
|
180
|
+
* ... "a",
|
|
181
|
+
* ... "b",
|
|
182
|
+
* ... "LONG_WORD",
|
|
183
|
+
* ... "cow"
|
|
184
|
+
* ... ]})
|
|
185
|
+
* > df.select(pl.col('foo').str.padStart("_", 3)
|
|
186
|
+
* shape: (4, 1)
|
|
187
|
+
* ┌──────────┐
|
|
188
|
+
* │ a │
|
|
189
|
+
* │ -------- │
|
|
190
|
+
* │ str │
|
|
191
|
+
* ╞══════════╡
|
|
192
|
+
* │ __a │
|
|
193
|
+
* ├╌╌╌╌╌╌╌╌╌╌┤
|
|
194
|
+
* │ __b │
|
|
195
|
+
* ├╌╌╌╌╌╌╌╌╌╌┤
|
|
196
|
+
* │ LONG_WORD│
|
|
197
|
+
* ├╌╌╌╌╌╌╌╌╌╌┤
|
|
198
|
+
* │ cow │
|
|
199
|
+
* └──────────┘
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
padStart(length: number, fillChar: string): Series;
|
|
203
|
+
/**
|
|
204
|
+
* Add a leading '0' to a string until string length is reached.
|
|
205
|
+
* If string is longer or equal to given length no modifications will be done
|
|
206
|
+
* @param {number} length - of the final string
|
|
207
|
+
* @example
|
|
208
|
+
* ```
|
|
209
|
+
* > df = pl.DataFrame({
|
|
210
|
+
* ... 'foo': [
|
|
211
|
+
* ... "a",
|
|
212
|
+
* ... "b",
|
|
213
|
+
* ... "LONG_WORD",
|
|
214
|
+
* ... "cow"
|
|
215
|
+
* ... ]})
|
|
216
|
+
* > df.select(pl.col('foo').str.padStart(3)
|
|
217
|
+
* shape: (4, 1)
|
|
218
|
+
* ┌──────────┐
|
|
219
|
+
* │ a │
|
|
220
|
+
* │ -------- │
|
|
221
|
+
* │ str │
|
|
222
|
+
* ╞══════════╡
|
|
223
|
+
* │ 00a │
|
|
224
|
+
* ├╌╌╌╌╌╌╌╌╌╌┤
|
|
225
|
+
* │ 00b │
|
|
226
|
+
* ├╌╌╌╌╌╌╌╌╌╌┤
|
|
227
|
+
* │ LONG_WORD│
|
|
228
|
+
* ├╌╌╌╌╌╌╌╌╌╌┤
|
|
229
|
+
* │ cow │
|
|
230
|
+
* └──────────┘
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
zFill(length: number | Expr): Series;
|
|
234
|
+
/** Add trailing zeros */
|
|
235
|
+
padEnd(length: number, fillChar: string): Series;
|
|
236
|
+
/**
|
|
237
|
+
* Replace first regex match with a string value in Series.
|
|
238
|
+
* @param pattern A valid regex pattern or string
|
|
239
|
+
* @param value Substring to replace.
|
|
240
|
+
* @example
|
|
241
|
+
* ```
|
|
242
|
+
* df = pl.Series(["#12.34", "#56.78"]).str.replace(/#(\d+)/, "$$$1")
|
|
243
|
+
* shape: (2,)
|
|
244
|
+
* Series: '' [str]
|
|
245
|
+
* [
|
|
246
|
+
* "$12.34"
|
|
247
|
+
* "$56.78"
|
|
248
|
+
* ]
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
replace(pattern: string | RegExp, value: string): Series;
|
|
252
|
+
/**
|
|
253
|
+
* Replace all regex matches with a string value in Series.
|
|
254
|
+
* @param pattern - A valid regex pattern or string
|
|
255
|
+
* @param value Substring to replace.
|
|
256
|
+
* @example
|
|
257
|
+
* ```
|
|
258
|
+
* df = pl.Series(["abcabc", "123a123"]).str.replaceAll("a", "-");
|
|
259
|
+
* shape: (2,)
|
|
260
|
+
* Series: '' [str]
|
|
261
|
+
* [
|
|
262
|
+
* "-bc-bc"
|
|
263
|
+
* "123-123"
|
|
264
|
+
* ]
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
replaceAll(pattern: string | RegExp, value: string): Series;
|
|
268
|
+
/** Modify the strings to their lowercase equivalent. */
|
|
269
|
+
toLowerCase(): Series;
|
|
270
|
+
/** Modify the strings to their uppercase equivalent. */
|
|
271
|
+
toUpperCase(): Series;
|
|
272
|
+
/** Remove trailing whitespace. */
|
|
273
|
+
rstrip(): Series;
|
|
274
|
+
/** Remove leading and trailing whitespace. */
|
|
275
|
+
strip(): Series;
|
|
276
|
+
/**
|
|
277
|
+
* Create subslices of the string values of a Utf8 Series.
|
|
278
|
+
* @param start - Start of the slice (negative indexing may be used).
|
|
279
|
+
* @param length - Optional length of the slice.
|
|
280
|
+
*/
|
|
281
|
+
slice(start: number | Expr, length?: number | Expr): Series;
|
|
282
|
+
/**
|
|
283
|
+
* Split a string into substrings using the specified separator.
|
|
284
|
+
* The return type will by of type List<Utf8>
|
|
285
|
+
* @param separator — A string that identifies character or characters to use in separating the string.
|
|
286
|
+
* @param options.inclusive Include the split character/string in the results
|
|
287
|
+
*/
|
|
288
|
+
split(separator: string, options?: {
|
|
289
|
+
inclusive?: boolean;
|
|
290
|
+
} | boolean): Series;
|
|
291
|
+
/**
|
|
292
|
+
* Parse a Series of dtype Utf8 to a Date/Datetime Series.
|
|
293
|
+
* @param datatype Date or Datetime.
|
|
294
|
+
* @param fmt formatting syntax. [Read more](https://docs.rs/chrono/0.4.19/chrono/format/strptime/index.html)
|
|
295
|
+
*/
|
|
296
|
+
strptime(datatype: DataType.Date, fmt?: string): Series<DataType.Date>;
|
|
297
|
+
strptime(datatype: DataType.Datetime, fmt?: string): Series<DataType.Datetime>;
|
|
298
|
+
strptime(datatype: typeof DataType.Datetime, fmt?: string): Series;
|
|
299
|
+
}
|
|
300
|
+
export declare const SeriesStringFunctions: (_s: any) => SeriesStringFunctions;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SeriesStringFunctions = void 0;
|
|
4
|
+
const functions_1 = require("../lazy/functions");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const _1 = require(".");
|
|
7
|
+
const SeriesStringFunctions = (_s) => {
|
|
8
|
+
const wrap = (method, ...args) => {
|
|
9
|
+
const ret = _s[method](...args);
|
|
10
|
+
return (0, _1._Series)(ret);
|
|
11
|
+
};
|
|
12
|
+
const handleDecode = (encoding, strict) => {
|
|
13
|
+
switch (encoding) {
|
|
14
|
+
case "hex":
|
|
15
|
+
return wrap("strHexDecode", strict);
|
|
16
|
+
case "base64":
|
|
17
|
+
return wrap("strBase64Decode", strict);
|
|
18
|
+
default:
|
|
19
|
+
throw new RangeError("supported encodings are 'hex' and 'base64'");
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
concat(delimiter, ignoreNulls = true) {
|
|
24
|
+
return (0, _1._Series)(_s)
|
|
25
|
+
.toFrame()
|
|
26
|
+
.select((0, functions_1.col)(_s.name).str.concat(delimiter, ignoreNulls).as(_s.name))
|
|
27
|
+
.getColumn(_s.name);
|
|
28
|
+
},
|
|
29
|
+
contains(pat, literal = false, strict = true) {
|
|
30
|
+
return wrap("strContains", (0, utils_1.regexToString)(pat), literal, strict);
|
|
31
|
+
},
|
|
32
|
+
decode(arg, strict = false) {
|
|
33
|
+
if (typeof arg === "string") {
|
|
34
|
+
return handleDecode(arg, strict);
|
|
35
|
+
}
|
|
36
|
+
return handleDecode(arg.encoding, arg.strict);
|
|
37
|
+
},
|
|
38
|
+
encode(encoding) {
|
|
39
|
+
switch (encoding) {
|
|
40
|
+
case "hex":
|
|
41
|
+
return wrap("strHexEncode");
|
|
42
|
+
case "base64":
|
|
43
|
+
return wrap("strBase64Encode");
|
|
44
|
+
default:
|
|
45
|
+
throw new RangeError("supported encodings are 'hex' and 'base64'");
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
extract(pat, groupIndex) {
|
|
49
|
+
const s = (0, _1._Series)(_s);
|
|
50
|
+
return s
|
|
51
|
+
.toFrame()
|
|
52
|
+
.select((0, functions_1.col)(s.name).str.extract(pat, groupIndex).as(s.name))
|
|
53
|
+
.getColumn(s.name);
|
|
54
|
+
},
|
|
55
|
+
jsonDecode(dtype, inferSchemaLength) {
|
|
56
|
+
return wrap("strJsonDecode", dtype, inferSchemaLength);
|
|
57
|
+
},
|
|
58
|
+
jsonPathMatch(pat) {
|
|
59
|
+
return wrap("strJsonPathMatch", [pat]);
|
|
60
|
+
},
|
|
61
|
+
lengths() {
|
|
62
|
+
return wrap("strLengths");
|
|
63
|
+
},
|
|
64
|
+
lstrip() {
|
|
65
|
+
return wrap("strReplace", /^\s*/.source, "");
|
|
66
|
+
},
|
|
67
|
+
padStart(length, fillChar) {
|
|
68
|
+
return wrap("strPadStart", [length], fillChar);
|
|
69
|
+
},
|
|
70
|
+
zFill(length) {
|
|
71
|
+
return (0, _1._Series)(_s)
|
|
72
|
+
.toFrame()
|
|
73
|
+
.select((0, functions_1.col)(_s.name).str.zFill(length).as(_s.name))
|
|
74
|
+
.getColumn(_s.name);
|
|
75
|
+
},
|
|
76
|
+
padEnd(length, fillChar) {
|
|
77
|
+
return wrap("strPadEnd", [length], fillChar);
|
|
78
|
+
},
|
|
79
|
+
replace(pat, val) {
|
|
80
|
+
return wrap("strReplace", (0, utils_1.regexToString)(pat), val);
|
|
81
|
+
},
|
|
82
|
+
replaceAll(pat, val) {
|
|
83
|
+
return wrap("strReplaceAll", (0, utils_1.regexToString)(pat), val);
|
|
84
|
+
},
|
|
85
|
+
rstrip() {
|
|
86
|
+
return wrap("strReplace", /[ \t]+$/.source, "");
|
|
87
|
+
},
|
|
88
|
+
slice(start, length) {
|
|
89
|
+
const s = (0, _1._Series)(_s);
|
|
90
|
+
return s
|
|
91
|
+
.toFrame()
|
|
92
|
+
.select((0, functions_1.col)(s.name).str.slice(start, length).as(s.name))
|
|
93
|
+
.getColumn(s.name);
|
|
94
|
+
},
|
|
95
|
+
split(by, options) {
|
|
96
|
+
const inclusive = typeof options === "boolean" ? options : options?.inclusive;
|
|
97
|
+
const s = (0, _1._Series)(_s);
|
|
98
|
+
return s
|
|
99
|
+
.toFrame()
|
|
100
|
+
.select((0, functions_1.col)(s.name).str.split(by, inclusive).as(s.name))
|
|
101
|
+
.getColumn(s.name);
|
|
102
|
+
},
|
|
103
|
+
strip() {
|
|
104
|
+
const s = (0, _1._Series)(_s);
|
|
105
|
+
return s
|
|
106
|
+
.toFrame()
|
|
107
|
+
.select((0, functions_1.col)(s.name).str.strip().as(s.name))
|
|
108
|
+
.getColumn(s.name);
|
|
109
|
+
},
|
|
110
|
+
strptime(dtype, fmt) {
|
|
111
|
+
const s = (0, _1._Series)(_s);
|
|
112
|
+
return s
|
|
113
|
+
.toFrame()
|
|
114
|
+
.select((0, functions_1.col)(s.name).str.strptime(dtype, fmt).as(s.name))
|
|
115
|
+
.getColumn(s.name);
|
|
116
|
+
},
|
|
117
|
+
toLowerCase() {
|
|
118
|
+
return wrap("strToLowercase");
|
|
119
|
+
},
|
|
120
|
+
toUpperCase() {
|
|
121
|
+
return wrap("strToUppercase");
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
exports.SeriesStringFunctions = SeriesStringFunctions;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DataFrame } from "../dataframe";
|
|
2
|
+
import type { Series } from ".";
|
|
3
|
+
/**
|
|
4
|
+
* Struct Functions for Series
|
|
5
|
+
*/
|
|
6
|
+
export interface SeriesStructFunctions {
|
|
7
|
+
/**
|
|
8
|
+
* List of fields of the struct
|
|
9
|
+
* @return Array of field names
|
|
10
|
+
*/
|
|
11
|
+
fields: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Convert series of struct into dataframe
|
|
14
|
+
* @return A new dataframe
|
|
15
|
+
*/
|
|
16
|
+
toFrame(): DataFrame;
|
|
17
|
+
/**
|
|
18
|
+
* Access a field by name
|
|
19
|
+
* @param name - name of the field
|
|
20
|
+
* @return A new series containing the values of struct's field
|
|
21
|
+
*/
|
|
22
|
+
field(name: string): Series;
|
|
23
|
+
/**
|
|
24
|
+
* Rename the fields of a struct
|
|
25
|
+
* @param names - new names of the fields
|
|
26
|
+
* @return A new series containing the struct with new field names
|
|
27
|
+
*/
|
|
28
|
+
renameFields(names: string[]): Series;
|
|
29
|
+
/**
|
|
30
|
+
* Access a field by index (zero based index)
|
|
31
|
+
* @param index - index of the field (starts at 0)
|
|
32
|
+
* @return A new series containing the values of struct's field index
|
|
33
|
+
*/
|
|
34
|
+
nth(index: number): Series;
|
|
35
|
+
}
|
|
36
|
+
export declare const SeriesStructFunctions: (_s: any) => SeriesStructFunctions;
|
|
@@ -0,0 +1,35 @@
|
|
|
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.SeriesStructFunctions = void 0;
|
|
7
|
+
const dataframe_1 = require("../dataframe");
|
|
8
|
+
const polars_internal_1 = __importDefault(require("../internals/polars_internal"));
|
|
9
|
+
const expr_1 = require("../lazy/expr");
|
|
10
|
+
const SeriesStructFunctions = (_s) => {
|
|
11
|
+
return {
|
|
12
|
+
get fields() {
|
|
13
|
+
return _s.structFields();
|
|
14
|
+
},
|
|
15
|
+
toFrame() {
|
|
16
|
+
return (0, dataframe_1._DataFrame)(_s.structToFrame());
|
|
17
|
+
},
|
|
18
|
+
field(name) {
|
|
19
|
+
return (0, dataframe_1.DataFrame)({})
|
|
20
|
+
.select((0, expr_1._Expr)(polars_internal_1.default.litSeries(_s).structFieldByName(name)))
|
|
21
|
+
.toSeries();
|
|
22
|
+
},
|
|
23
|
+
renameFields(names) {
|
|
24
|
+
return (0, dataframe_1.DataFrame)({})
|
|
25
|
+
.select((0, expr_1._Expr)(polars_internal_1.default.litSeries(_s).structRenameFields(names)))
|
|
26
|
+
.toSeries();
|
|
27
|
+
},
|
|
28
|
+
nth(index) {
|
|
29
|
+
return (0, dataframe_1.DataFrame)({})
|
|
30
|
+
.select((0, expr_1._Expr)(polars_internal_1.default.litSeries(_s).structFieldByIndex(index)))
|
|
31
|
+
.toSeries();
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.SeriesStructFunctions = SeriesStructFunctions;
|