@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,700 @@
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.Series = void 0;
7
+ exports._Series = _Series;
8
+ const dataframe_1 = require("../dataframe");
9
+ const datatypes_1 = require("../datatypes");
10
+ const error_1 = require("../error");
11
+ const construction_1 = require("../internals/construction");
12
+ const polars_internal_1 = __importDefault(require("../internals/polars_internal"));
13
+ const functions_1 = require("../lazy/functions");
14
+ const datetime_1 = require("./datetime");
15
+ const list_1 = require("./list");
16
+ const string_1 = require("./string");
17
+ const struct_1 = require("./struct");
18
+ const inspect = Symbol.for("nodejs.util.inspect.custom");
19
+ function _Series(_s) {
20
+ const unwrap = (method, ...args) => {
21
+ return _s[method](...args);
22
+ };
23
+ const wrap = (method, ...args) => {
24
+ return _Series(unwrap(method, ...args));
25
+ };
26
+ const dtypeWrap = (method, ...args) => {
27
+ const dtype = _s.dtype;
28
+ const dt = datatypes_1.DTYPE_TO_FFINAME[dtype];
29
+ const internalMethod = `series${method}${dt}`;
30
+ return _Series(polars_internal_1.default[internalMethod](_s, ...args));
31
+ };
32
+ const dtypeUnwrap = (method, ...args) => {
33
+ const dtype = _s.dtype;
34
+ const dt = datatypes_1.DTYPE_TO_FFINAME[dtype];
35
+ const internalMethod = `series${method}${dt}`;
36
+ return polars_internal_1.default[internalMethod](_s, ...args);
37
+ };
38
+ const expr_op = (method, ...args) => {
39
+ return _Series(_s)
40
+ .toFrame()
41
+ .select((0, functions_1.col)(_s.name)[method](...args))
42
+ .getColumn(_s.name);
43
+ };
44
+ const numberOrSeriesFunc = (other, numFunc, srFunc) => {
45
+ if (typeof other === "number")
46
+ return dtypeWrap(numFunc, other);
47
+ if (exports.Series.isSeries(other)) {
48
+ return wrap(srFunc ?? numFunc.toLowerCase(), other._s);
49
+ }
50
+ throw new Error("Not a number nor a series");
51
+ };
52
+ const series = {
53
+ _s,
54
+ [inspect]() {
55
+ return _s.toString();
56
+ },
57
+ *[Symbol.iterator]() {
58
+ let start = 0;
59
+ const len = _s.len();
60
+ while (start < len) {
61
+ const v = _s.getIdx(start);
62
+ start++;
63
+ yield v;
64
+ }
65
+ },
66
+ toString() {
67
+ return _s.toString();
68
+ },
69
+ serialize(format) {
70
+ return _s.serialize(format);
71
+ },
72
+ [Symbol.toStringTag]() {
73
+ return "Series";
74
+ },
75
+ get dtype() {
76
+ return datatypes_1.DataType.deserialize(_s.dtype);
77
+ },
78
+ get name() {
79
+ return _s.name;
80
+ },
81
+ get length() {
82
+ return _s.len();
83
+ },
84
+ get str() {
85
+ return (0, string_1.SeriesStringFunctions)(_s);
86
+ },
87
+ get lst() {
88
+ return (0, list_1.SeriesListFunctions)(_s);
89
+ },
90
+ get list() {
91
+ return (0, list_1.SeriesListFunctions)(_s);
92
+ },
93
+ get date() {
94
+ return (0, datetime_1.SeriesDateFunctions)(_s);
95
+ },
96
+ get dt() {
97
+ return (0, datetime_1.SeriesDateFunctions)(_s);
98
+ },
99
+ get struct() {
100
+ return (0, struct_1.SeriesStructFunctions)(_s);
101
+ },
102
+ abs() {
103
+ return wrap("abs");
104
+ },
105
+ add(other) {
106
+ return numberOrSeriesFunc(other, "Add");
107
+ },
108
+ alias(name) {
109
+ const s = _s.clone();
110
+ s.rename(name);
111
+ return _Series(s);
112
+ },
113
+ append(other) {
114
+ _s.append(other.inner());
115
+ },
116
+ argMax() {
117
+ return _s.argMax();
118
+ },
119
+ argMin() {
120
+ return _s.argMin();
121
+ },
122
+ argSort(descending = false, nullsLast = true, multithreaded = true, maintainOrder = false) {
123
+ if (typeof descending === "boolean") {
124
+ return _Series(_s.argsort(descending, nullsLast, multithreaded, maintainOrder));
125
+ }
126
+ return _Series(_s.argsort(descending.descending ?? false, descending.nullsLast ?? nullsLast, descending.multithreaded ?? multithreaded, descending.maintainOrder ?? maintainOrder));
127
+ },
128
+ argTrue() {
129
+ return _Series(this.toFrame()
130
+ ._df.lazy()
131
+ .select([polars_internal_1.default.argWhere(polars_internal_1.default.col(this.name))])
132
+ .collectSync()
133
+ .column(this.name));
134
+ },
135
+ argUnique() {
136
+ return _Series(_s.argUnique());
137
+ },
138
+ as(name) {
139
+ return this.alias(name);
140
+ },
141
+ bitand(other) {
142
+ return _Series(_s.bitand(other._s));
143
+ },
144
+ bitor(other) {
145
+ return _Series(_s.bitor(other._s));
146
+ },
147
+ bitxor(other) {
148
+ return _Series(_s.bitxor(other._s));
149
+ },
150
+ cast(dtype, strict = false) {
151
+ return _Series(_s.cast(dtype, strict));
152
+ },
153
+ chunkLengths() {
154
+ return _s.chunkLengths();
155
+ },
156
+ clone() {
157
+ return _Series(_s.clone());
158
+ },
159
+ concat(other) {
160
+ const s = _s.clone();
161
+ s.append(other.inner());
162
+ return _Series(s);
163
+ },
164
+ cumCount(reverse) {
165
+ return expr_op("cumCount", reverse);
166
+ },
167
+ cumSum(reverse) {
168
+ return _Series(_s.cumSum(reverse));
169
+ },
170
+ cumMax(reverse) {
171
+ return _Series(_s.cumMax(reverse));
172
+ },
173
+ cumMin(reverse) {
174
+ return _Series(_s.cumMin(reverse));
175
+ },
176
+ cumProd(reverse) {
177
+ return _Series(_s.cumProd(reverse));
178
+ },
179
+ describe() {
180
+ let s = this.clone();
181
+ let stats = {};
182
+ if (!this.length) {
183
+ throw new RangeError("Series must contain at least one value");
184
+ }
185
+ if (this.isNumeric()) {
186
+ s = s.cast(datatypes_1.DataType.Float64);
187
+ stats = {
188
+ min: s.min(),
189
+ max: s.max(),
190
+ null_count: s.nullCount(),
191
+ mean: s.mean(),
192
+ count: s.len(),
193
+ };
194
+ }
195
+ else if (s.isBoolean()) {
196
+ stats = {
197
+ sum: s.sum(),
198
+ null_count: s.nullCount(),
199
+ count: s.len(),
200
+ };
201
+ }
202
+ else if (s.isString()) {
203
+ stats = {
204
+ unique: s.nUnique(),
205
+ null_count: s.nullCount(),
206
+ count: s.len(),
207
+ };
208
+ }
209
+ else {
210
+ throw new error_1.InvalidOperationError("describe", s.dtype);
211
+ }
212
+ return (0, dataframe_1.DataFrame)({
213
+ statistic: Object.keys(stats),
214
+ value: Object.values(stats),
215
+ });
216
+ },
217
+ diff(n = 1, nullBehavior = "ignore") {
218
+ return typeof n === "number"
219
+ ? _Series(_s.diff(n, nullBehavior))
220
+ : _Series(_s.diff(n?.n ?? 1, n.nullBehavior ?? nullBehavior));
221
+ },
222
+ div(other) {
223
+ return numberOrSeriesFunc(other, "Div");
224
+ },
225
+ divideBy(field) {
226
+ return this.div(field);
227
+ },
228
+ dot(other) {
229
+ return wrap("dot", other._s);
230
+ },
231
+ dropNulls() {
232
+ return wrap("dropNulls");
233
+ },
234
+ eq(other) {
235
+ return numberOrSeriesFunc(other, "Eq");
236
+ },
237
+ equals(field) {
238
+ return this.eq(field);
239
+ },
240
+ ewmMean(...args) {
241
+ return expr_op("ewmMean", ...args);
242
+ },
243
+ ewmStd(...args) {
244
+ return expr_op("ewmStd", ...args);
245
+ },
246
+ ewmVar(...args) {
247
+ return expr_op("ewmVar", ...args);
248
+ },
249
+ explode() {
250
+ return wrap("explode");
251
+ },
252
+ extendConstant(o, n) {
253
+ if (n !== null && typeof n === "number")
254
+ return wrap("extendConstant", o, n);
255
+ return wrap("extendConstant", o.value, o.n);
256
+ },
257
+ fillNull(strategy) {
258
+ return typeof strategy === "string"
259
+ ? wrap("fillNull", strategy)
260
+ : wrap("fillNull", strategy.strategy);
261
+ },
262
+ filter(predicate) {
263
+ return exports.Series.isSeries(predicate)
264
+ ? wrap("filter", predicate._s)
265
+ : wrap("filter", SeriesConstructor("", predicate)._s);
266
+ },
267
+ get(field) {
268
+ return dtypeUnwrap("Get", field);
269
+ },
270
+ getIndex(idx) {
271
+ return _s.getIdx(idx);
272
+ },
273
+ gt(other) {
274
+ return numberOrSeriesFunc(other, "Gt");
275
+ },
276
+ greaterThan(field) {
277
+ return this.gt(field);
278
+ },
279
+ gtEq(other) {
280
+ return numberOrSeriesFunc(other, "GtEq", "gtEq");
281
+ },
282
+ greaterThanEquals(field) {
283
+ return this.gtEq(field);
284
+ },
285
+ hash(obj = 0n, k1 = 1n, k2 = 2n, k3 = 3n) {
286
+ if (typeof obj === "number" || typeof obj === "bigint") {
287
+ return wrap("hash", BigInt(obj), BigInt(k1), BigInt(k2), BigInt(k3));
288
+ }
289
+ const o = { k0: obj, k1: k1, k2: k2, k3: k3, ...obj };
290
+ return wrap("hash", BigInt(o.k0), BigInt(o.k1), BigInt(o.k2), BigInt(o.k3));
291
+ },
292
+ hasNulls() {
293
+ return _s.hasNulls();
294
+ },
295
+ hasValidity() {
296
+ return _s.hasNulls();
297
+ },
298
+ head(length = 5) {
299
+ return wrap("head", length);
300
+ },
301
+ inner() {
302
+ return _s;
303
+ },
304
+ interpolate() {
305
+ return expr_op("interpolate");
306
+ },
307
+ isBoolean() {
308
+ const dtype = this.dtype;
309
+ return dtype.equals(datatypes_1.DataType.Bool);
310
+ },
311
+ isDateTime() {
312
+ const dtype = this.dtype;
313
+ return [datatypes_1.DataType.Date.variant, "Datetime"].includes(dtype.variant);
314
+ },
315
+ isDuplicated() {
316
+ return wrap("isDuplicated");
317
+ },
318
+ isFinite() {
319
+ const dtype = this.dtype;
320
+ if (![datatypes_1.DataType.Float32.variant, datatypes_1.DataType.Float64.variant].includes(dtype.variant)) {
321
+ throw new error_1.InvalidOperationError("isFinite", dtype);
322
+ }
323
+ return wrap("isFinite");
324
+ },
325
+ isFirstDistinct() {
326
+ return wrap("isFirstDistinct");
327
+ },
328
+ isFloat() {
329
+ return [datatypes_1.DataType.Float32.variant, datatypes_1.DataType.Float64.variant].includes(this.dtype.variant);
330
+ },
331
+ isIn(other, nullsEquals = false) {
332
+ return exports.Series.isSeries(other)
333
+ ? wrap("isIn", other._s, nullsEquals)
334
+ : wrap("isIn", (0, exports.Series)("", other)._s, nullsEquals);
335
+ },
336
+ isInfinite() {
337
+ const dtype = this.dtype;
338
+ if (![datatypes_1.DataType.Float32.variant, datatypes_1.DataType.Float64.variant].includes(dtype.variant)) {
339
+ throw new error_1.InvalidOperationError("isFinite", dtype);
340
+ }
341
+ return wrap("isInfinite");
342
+ },
343
+ implode() {
344
+ return wrap("implode");
345
+ },
346
+ isNotNull() {
347
+ return wrap("isNotNull");
348
+ },
349
+ isNull() {
350
+ return wrap("isNull");
351
+ },
352
+ isNaN() {
353
+ return wrap("isNan");
354
+ },
355
+ isNotNaN() {
356
+ return wrap("isNotNan");
357
+ },
358
+ isNumeric() {
359
+ const dtype = this.dtype;
360
+ const numericTypes = [
361
+ datatypes_1.DataType.Int8.variant,
362
+ datatypes_1.DataType.Int16.variant,
363
+ datatypes_1.DataType.Int32.variant,
364
+ datatypes_1.DataType.Int64.variant,
365
+ datatypes_1.DataType.UInt8.variant,
366
+ datatypes_1.DataType.UInt16.variant,
367
+ datatypes_1.DataType.UInt32.variant,
368
+ datatypes_1.DataType.UInt64.variant,
369
+ datatypes_1.DataType.Float32.variant,
370
+ datatypes_1.DataType.Float64.variant,
371
+ ];
372
+ return numericTypes.includes(dtype.variant);
373
+ },
374
+ isUnique() {
375
+ return wrap("isUnique");
376
+ },
377
+ isString() {
378
+ return this.dtype.equals(datatypes_1.DataType.String);
379
+ },
380
+ kurtosis(fisher = true, bias = true) {
381
+ if (typeof fisher === "boolean") {
382
+ return _s.kurtosis(fisher, bias);
383
+ }
384
+ const d = {
385
+ fisher: true,
386
+ bias,
387
+ ...fisher,
388
+ };
389
+ return _s.kurtosis(d.fisher, d.bias);
390
+ },
391
+ len() {
392
+ return this.length;
393
+ },
394
+ lt(other) {
395
+ return numberOrSeriesFunc(other, "Lt");
396
+ },
397
+ lessThan(other) {
398
+ return numberOrSeriesFunc(other, "Lt");
399
+ },
400
+ ltEq(other) {
401
+ return numberOrSeriesFunc(other, "LtEq", "ltEq");
402
+ },
403
+ lessThanEquals(other) {
404
+ return numberOrSeriesFunc(other, "LtEq", "ltEq");
405
+ },
406
+ limit(n = 10) {
407
+ return wrap("limit", n);
408
+ },
409
+ max() {
410
+ return _s.max();
411
+ },
412
+ mean() {
413
+ return _s.mean();
414
+ },
415
+ median() {
416
+ return _s.median();
417
+ },
418
+ min() {
419
+ return _s.min();
420
+ },
421
+ mode() {
422
+ return wrap("mode");
423
+ },
424
+ minus(other) {
425
+ return numberOrSeriesFunc(other, "Sub");
426
+ },
427
+ mul(other) {
428
+ return numberOrSeriesFunc(other, "Mul");
429
+ },
430
+ nChunks() {
431
+ return _s.nChunks();
432
+ },
433
+ neq(other) {
434
+ return numberOrSeriesFunc(other, "Neq");
435
+ },
436
+ notEquals(other) {
437
+ return this.neq(other);
438
+ },
439
+ nullCount() {
440
+ return _s.nullCount();
441
+ },
442
+ nUnique() {
443
+ return _s.nUnique();
444
+ },
445
+ peakMax() {
446
+ return expr_op("peakMax");
447
+ },
448
+ peakMin() {
449
+ return expr_op("peakMin");
450
+ },
451
+ plus(other) {
452
+ return numberOrSeriesFunc(other, "Add");
453
+ },
454
+ quantile(quantile, interpolation = "nearest") {
455
+ return _s.quantile(quantile, interpolation);
456
+ },
457
+ rank(method = "average", descending = false) {
458
+ return wrap("rank", method, descending);
459
+ },
460
+ rechunk(inPlace = false) {
461
+ return wrap("rechunk", inPlace);
462
+ },
463
+ reinterpret(signed = true) {
464
+ const dtype = this.dtype;
465
+ if ([datatypes_1.DataType.UInt64.variant, datatypes_1.DataType.Int64.variant].includes(dtype.variant)) {
466
+ return wrap("reinterpret", signed);
467
+ }
468
+ throw new error_1.InvalidOperationError("reinterpret", dtype);
469
+ },
470
+ rem(other) {
471
+ return numberOrSeriesFunc(other, "Rem");
472
+ },
473
+ modulo(field) {
474
+ return this.rem(field);
475
+ },
476
+ rename(obj, inPlace = false) {
477
+ if (obj?.inPlace ?? inPlace) {
478
+ _s.rename(obj?.name ?? obj);
479
+ }
480
+ else {
481
+ return this.alias(obj?.name ?? obj);
482
+ }
483
+ },
484
+ rollingMax(...args) {
485
+ return expr_op("rollingMax", ...args);
486
+ },
487
+ rollingMean(...args) {
488
+ return expr_op("rollingMean", ...args);
489
+ },
490
+ rollingMin(...args) {
491
+ return expr_op("rollingMin", ...args);
492
+ },
493
+ rollingSum(...args) {
494
+ return expr_op("rollingSum", ...args);
495
+ },
496
+ rollingStd(...args) {
497
+ return expr_op("rollingStd", ...args);
498
+ },
499
+ rollingVar(...args) {
500
+ return expr_op("rollingVar", ...args);
501
+ },
502
+ rollingMedian(...args) {
503
+ return expr_op("rollingMedian", ...args);
504
+ },
505
+ rollingQuantile(...args) {
506
+ return expr_op("rollingQuantile", ...args);
507
+ },
508
+ rollingSkew(...args) {
509
+ return expr_op("rollingSkew", ...args);
510
+ },
511
+ floor() {
512
+ return wrap("floor");
513
+ },
514
+ ceil() {
515
+ return wrap("ceil");
516
+ },
517
+ round(opt, mode) {
518
+ if (!this.isNumeric()) {
519
+ throw new error_1.InvalidOperationError("round", this.dtype);
520
+ }
521
+ if (typeof opt === "number") {
522
+ return wrap("round", opt, mode ?? "halftoeven");
523
+ }
524
+ return wrap("round", opt.decimals, opt.mode ?? "halftoeven");
525
+ },
526
+ clip(...args) {
527
+ return expr_op("clip", ...args);
528
+ },
529
+ scatter(indices, value) {
530
+ indices = exports.Series.isSeries(indices)
531
+ ? indices.cast(datatypes_1.DataType.UInt32)
532
+ : (0, exports.Series)(indices);
533
+ if (!exports.Series.isSeries(value)) {
534
+ if (!Array.isArray(value)) {
535
+ value = [value];
536
+ }
537
+ value = (0, exports.Series)(value);
538
+ }
539
+ if (indices.length > 0) {
540
+ value = value.extendConstant(value[0], indices.length - 1);
541
+ }
542
+ _s.scatter(indices._s, value._s);
543
+ },
544
+ set(mask, value) {
545
+ mask = exports.Series.isSeries(mask) ? mask : exports.Series.from(mask);
546
+ return dtypeWrap("SetWithMask", mask.inner(), value);
547
+ },
548
+ sample(opts, frac, withReplacement = false, seed) {
549
+ if (arguments.length === 0) {
550
+ return wrap("sampleN", 1, withReplacement, false, seed);
551
+ }
552
+ if (opts?.n !== undefined || opts?.frac !== undefined) {
553
+ return this.sample(opts.n, opts.frac, opts.withReplacement, seed);
554
+ }
555
+ if (typeof opts === "number") {
556
+ return wrap("sampleN", opts, withReplacement, false, seed);
557
+ }
558
+ if (typeof frac === "number") {
559
+ return wrap("sampleFrac", frac, withReplacement, false, seed);
560
+ }
561
+ throw new TypeError("must specify either 'frac' or 'n'");
562
+ },
563
+ seriesEqual(other, nullEqual = true, strict = false) {
564
+ return _s.seriesEqual(other._s, nullEqual, strict);
565
+ },
566
+ shift(periods = 1) {
567
+ return wrap("shift", periods);
568
+ },
569
+ shiftAndFill(...args) {
570
+ return expr_op("shiftAndFill", ...args);
571
+ },
572
+ shrinkToFit(inPlace) {
573
+ if (inPlace) {
574
+ _s.shrinkToFit();
575
+ return _s;
576
+ }
577
+ else {
578
+ const s = this.clone();
579
+ s.shrinkToFit(true);
580
+ return s;
581
+ }
582
+ },
583
+ skew(bias = true) {
584
+ if (typeof bias === "boolean") {
585
+ return _s.skew(bias);
586
+ }
587
+ return _s.skew(bias?.bias ?? true);
588
+ },
589
+ slice(offset, length) {
590
+ if (typeof offset === "number") {
591
+ return wrap("slice", offset, length);
592
+ }
593
+ return wrap("slice", offset.offset, offset.length);
594
+ },
595
+ sort(options) {
596
+ options = { descending: false, nullsLast: false, ...(options ?? {}) };
597
+ return wrap("sort", options.descending ?? false, options.nullsLast);
598
+ },
599
+ sub(other) {
600
+ return numberOrSeriesFunc(other, "Sub");
601
+ },
602
+ sum() {
603
+ return _s.sum();
604
+ },
605
+ tail(length = 5) {
606
+ return wrap("tail", length);
607
+ },
608
+ gather(indices) {
609
+ return wrap("take", indices);
610
+ },
611
+ gatherEvery(n, offset) {
612
+ return wrap("gatherEvery", n, offset ?? 0);
613
+ },
614
+ multiplyBy(field) {
615
+ return this.mul(field);
616
+ },
617
+ toArray() {
618
+ return _s.toArray();
619
+ },
620
+ toTypedArray() {
621
+ if (!this.hasNulls() || this.nullCount() === 0) {
622
+ return _s.toTypedArray();
623
+ }
624
+ throw new Error("data contains nulls, unable to convert to TypedArray");
625
+ },
626
+ toDummies(separator = "_", dropFirst = false, dropNulls = false) {
627
+ return (0, dataframe_1._DataFrame)(_s.toDummies(separator, dropFirst, dropNulls));
628
+ },
629
+ toFrame() {
630
+ return (0, dataframe_1._DataFrame)((0, construction_1.jsDataFrameFromSeries)([_s]));
631
+ },
632
+ toJSON(...args) {
633
+ // this is passed by `JSON.stringify` when calling `toJSON()`
634
+ if (args[0] === "") {
635
+ return _s.toJs();
636
+ }
637
+ return _s.serialize("json").toString();
638
+ },
639
+ toObject() {
640
+ return _s.toJs();
641
+ },
642
+ unique(maintainOrder) {
643
+ return maintainOrder ? wrap("uniqueStable") : wrap("unique");
644
+ },
645
+ valueCounts(sort, parallel, name, normalize) {
646
+ name = name ?? (normalize ? "proportion" : "count");
647
+ return (0, dataframe_1._DataFrame)(unwrap("valueCounts", sort ?? false, parallel ?? false, name, normalize ?? false));
648
+ },
649
+ values() {
650
+ return this[Symbol.iterator]();
651
+ },
652
+ zipWith(mask, other) {
653
+ return wrap("zipWith", mask._s, other._s);
654
+ },
655
+ };
656
+ return new Proxy(series, {
657
+ get: (target, prop, receiver) => {
658
+ if (typeof prop !== "symbol" && !Number.isNaN(Number(prop))) {
659
+ return target.get(Number(prop));
660
+ }
661
+ return Reflect.get(target, prop, receiver);
662
+ },
663
+ set: (series, prop, input) => {
664
+ if (typeof prop !== "symbol" && !Number.isNaN(Number(prop))) {
665
+ series.scatter([Number(prop)], input);
666
+ return true;
667
+ }
668
+ },
669
+ });
670
+ }
671
+ const SeriesConstructor = (arg0, arg1, dtype) => {
672
+ if (typeof arg0 === "string") {
673
+ const _s = (0, construction_1.arrayToJsSeries)(arg0, arg1, dtype);
674
+ return _Series(_s);
675
+ }
676
+ return SeriesConstructor("", arg0);
677
+ };
678
+ const isSeries = (anyVal) => {
679
+ try {
680
+ return anyVal?.[Symbol.toStringTag]?.() === "Series";
681
+ }
682
+ catch (_err) {
683
+ return false;
684
+ }
685
+ };
686
+ const from = (name, values) => {
687
+ if (Array.isArray(name)) {
688
+ return SeriesConstructor("", name);
689
+ }
690
+ return SeriesConstructor(name, values);
691
+ };
692
+ const of = (values) => {
693
+ return exports.Series.from(values);
694
+ };
695
+ exports.Series = Object.assign(SeriesConstructor, {
696
+ isSeries,
697
+ from,
698
+ of,
699
+ deserialize: (buf, fmt) => _Series(polars_internal_1.default.JsSeries.deserialize(buf, fmt)),
700
+ });
@@ -0,0 +1,8 @@
1
+ import type { ListFunctions } from "../shared_traits";
2
+ import { type Series } from ".";
3
+ /**
4
+ * List functions for Series
5
+ */
6
+ export interface SeriesListFunctions extends ListFunctions<Series> {
7
+ }
8
+ export declare const SeriesListFunctions: (_s: any) => SeriesListFunctions;