df-script 1.5.0 → 1.6.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 (133) hide show
  1. package/README.md +124 -8
  2. package/dist/api.d.ts +1 -1
  3. package/dist/columnExpressions/ColumnExpr.d.ts +2 -2
  4. package/dist/columnExpressions/functions/coalesce.d.ts +2 -2
  5. package/dist/columnExpressions/functions/element.d.ts +1 -1
  6. package/dist/columnExpressions/functions/when.d.ts +2 -2
  7. package/dist/columnExpressions/index.d.ts +1 -1
  8. package/dist/columnExpressions/mixins/AggregationExpr.d.ts +2 -2
  9. package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +11 -10
  10. package/dist/columnExpressions/mixins/ArrayExpr.d.ts +39 -0
  11. package/dist/columnExpressions/mixins/ListExpr.d.ts +2 -2
  12. package/dist/columnExpressions/mixins/StringExpr.d.ts +2 -2
  13. package/dist/columnExpressions/types.d.ts +1 -0
  14. package/dist/constants.d.ts +11 -0
  15. package/dist/dataframe/dataframe.d.ts +1 -1
  16. package/dist/datatypes/index.d.ts +3 -2
  17. package/dist/datatypes/types.d.ts +7 -7
  18. package/dist/index.js +6 -6
  19. package/dist/types.d.ts +4 -2
  20. package/dist/utils/array.d.ts +217 -0
  21. package/dist/utils/binary.d.ts +3 -0
  22. package/dist/utils/date.d.ts +21 -35
  23. package/dist/utils/guards.d.ts +11 -10
  24. package/dist/utils/index.d.ts +3 -2
  25. package/dist/utils/list.d.ts +23 -1
  26. package/dist/utils/number.d.ts +14 -29
  27. package/dist/utils/object.d.ts +26 -0
  28. package/dist/utils/string.d.ts +3 -5
  29. package/package.json +2 -2
  30. package/dist/api.js +0 -26
  31. package/dist/bundle.min.js +0 -1
  32. package/dist/columnExpressions/ColumnExpr.js +0 -219
  33. package/dist/columnExpressions/ExprBase.js +0 -92
  34. package/dist/columnExpressions/constants.js +0 -7
  35. package/dist/columnExpressions/functions/all.js +0 -11
  36. package/dist/columnExpressions/functions/coalesce.js +0 -44
  37. package/dist/columnExpressions/functions/element.js +0 -11
  38. package/dist/columnExpressions/functions/exclude.js +0 -13
  39. package/dist/columnExpressions/functions/implode.js +0 -7
  40. package/dist/columnExpressions/functions/lit.js +0 -17
  41. package/dist/columnExpressions/functions/repeat.d.ts +0 -47
  42. package/dist/columnExpressions/functions/repeat.js +0 -131
  43. package/dist/columnExpressions/functions/seq_range.js +0 -91
  44. package/dist/columnExpressions/functions/when.js +0 -85
  45. package/dist/columnExpressions/index.js +0 -38
  46. package/dist/columnExpressions/mixins/AggregationExpr.js +0 -76
  47. package/dist/columnExpressions/mixins/ArithmeticExpr.js +0 -131
  48. package/dist/columnExpressions/mixins/BooleanExpr.d.ts +0 -40
  49. package/dist/columnExpressions/mixins/BooleanExpr.js +0 -67
  50. package/dist/columnExpressions/mixins/ComparisonExpr.js +0 -250
  51. package/dist/columnExpressions/mixins/ListExpr.js +0 -224
  52. package/dist/columnExpressions/mixins/LogicalExpr.js +0 -53
  53. package/dist/columnExpressions/mixins/ManipulationExpr.js +0 -71
  54. package/dist/columnExpressions/mixins/NumericExpr.d.ts +0 -92
  55. package/dist/columnExpressions/mixins/NumericExpr.js +0 -259
  56. package/dist/columnExpressions/mixins/StringExpr.js +0 -237
  57. package/dist/columnExpressions/mixins/StructExpr.js +0 -139
  58. package/dist/columnExpressions/mixins/TemporalExpr.js +0 -126
  59. package/dist/columnExpressions/mixins/WindowExpr.js +0 -151
  60. package/dist/columnExpressions/types.js +0 -2
  61. package/dist/columnExpressions/utils.js +0 -45
  62. package/dist/dataframe/constants.js +0 -7
  63. package/dist/dataframe/dataframe.js +0 -990
  64. package/dist/dataframe/grouped/grouped.js +0 -114
  65. package/dist/dataframe/index.js +0 -20
  66. package/dist/dataframe/types.js +0 -2
  67. package/dist/dataframe/utils.js +0 -307
  68. package/dist/datatypes/DataType.js +0 -76
  69. package/dist/datatypes/index.js +0 -46
  70. package/dist/datatypes/types/Binary.d.ts +0 -9
  71. package/dist/datatypes/types/Binary.js +0 -18
  72. package/dist/datatypes/types/Boolean.d.ts +0 -9
  73. package/dist/datatypes/types/Boolean.js +0 -19
  74. package/dist/datatypes/types/Date.d.ts +0 -8
  75. package/dist/datatypes/types/Date.js +0 -21
  76. package/dist/datatypes/types/Datetime.d.ts +0 -8
  77. package/dist/datatypes/types/Datetime.js +0 -17
  78. package/dist/datatypes/types/Decimal.d.ts +0 -10
  79. package/dist/datatypes/types/Decimal.js +0 -28
  80. package/dist/datatypes/types/Duration.d.ts +0 -8
  81. package/dist/datatypes/types/Duration.js +0 -17
  82. package/dist/datatypes/types/Float32.d.ts +0 -8
  83. package/dist/datatypes/types/Float32.js +0 -17
  84. package/dist/datatypes/types/Float64.d.ts +0 -8
  85. package/dist/datatypes/types/Float64.js +0 -17
  86. package/dist/datatypes/types/Int16.d.ts +0 -8
  87. package/dist/datatypes/types/Int16.js +0 -17
  88. package/dist/datatypes/types/Int32.d.ts +0 -8
  89. package/dist/datatypes/types/Int32.js +0 -17
  90. package/dist/datatypes/types/Int64.d.ts +0 -8
  91. package/dist/datatypes/types/Int64.js +0 -17
  92. package/dist/datatypes/types/Int8.d.ts +0 -8
  93. package/dist/datatypes/types/Int8.js +0 -17
  94. package/dist/datatypes/types/List.d.ts +0 -10
  95. package/dist/datatypes/types/List.js +0 -31
  96. package/dist/datatypes/types/Null.d.ts +0 -9
  97. package/dist/datatypes/types/Null.js +0 -17
  98. package/dist/datatypes/types/Object.d.ts +0 -9
  99. package/dist/datatypes/types/Object.js +0 -17
  100. package/dist/datatypes/types/Struct.d.ts +0 -14
  101. package/dist/datatypes/types/Struct.js +0 -39
  102. package/dist/datatypes/types/Time.d.ts +0 -8
  103. package/dist/datatypes/types/Time.js +0 -29
  104. package/dist/datatypes/types/UInt16.d.ts +0 -8
  105. package/dist/datatypes/types/UInt16.js +0 -17
  106. package/dist/datatypes/types/UInt32.d.ts +0 -8
  107. package/dist/datatypes/types/UInt32.js +0 -17
  108. package/dist/datatypes/types/UInt64.d.ts +0 -8
  109. package/dist/datatypes/types/UInt64.js +0 -17
  110. package/dist/datatypes/types/UInt8.d.ts +0 -8
  111. package/dist/datatypes/types/UInt8.js +0 -17
  112. package/dist/datatypes/types/Utf8.d.ts +0 -10
  113. package/dist/datatypes/types/Utf8.js +0 -20
  114. package/dist/datatypes/types.js +0 -290
  115. package/dist/exceptions/index.js +0 -46
  116. package/dist/exceptions/utils.js +0 -28
  117. package/dist/functions/concat.js +0 -260
  118. package/dist/functions/index.js +0 -9
  119. package/dist/functions/read_csv.js +0 -53
  120. package/dist/functions/read_json.js +0 -21
  121. package/dist/functions/transpose.d.ts +0 -7
  122. package/dist/functions/transpose.js +0 -84
  123. package/dist/types.js +0 -2
  124. package/dist/utils/boolean.d.ts +0 -1
  125. package/dist/utils/boolean.js +0 -18
  126. package/dist/utils/csv.js +0 -313
  127. package/dist/utils/date.js +0 -348
  128. package/dist/utils/guards.js +0 -112
  129. package/dist/utils/index.js +0 -23
  130. package/dist/utils/json.js +0 -217
  131. package/dist/utils/list.js +0 -361
  132. package/dist/utils/number.js +0 -401
  133. package/dist/utils/string.js +0 -209
@@ -1,131 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.repeat = repeat;
4
- exports.seq_range = seq_range;
5
- const ColumnExpr_1 = require("../ColumnExpr");
6
- const constants_1 = require("../constants");
7
- const exceptions_1 = require("../../exceptions");
8
- const utils_1 = require("../../utils");
9
- /**
10
- * Creates a literal column expression that repeats the given value.
11
- * If n is specified, it repeats the value n times.
12
- * If strict is true (default), a height mismatch with the DataFrame will throw a ShapeError.
13
- */
14
- function repeat(value, options = { strict: true }) {
15
- const expr = new ColumnExpr_1.ColumnExpr(constants_1.LITERAL_MARKER);
16
- expr.isLiteral = true;
17
- expr.literalValue = value;
18
- const opts = options;
19
- if (opts.name) {
20
- expr.outputName = opts.name;
21
- }
22
- expr.ops.push((vArray) => {
23
- const targetHeight = vArray.length;
24
- let start = opts.startIndex !== undefined ? opts.startIndex : 0;
25
- if (start < 0) {
26
- start = targetHeight + start;
27
- }
28
- const safeStart = (0, utils_1.clamp)(start, 0, targetHeight);
29
- let end = opts.endIndex !== undefined ? opts.endIndex : targetHeight;
30
- if (end < 0) {
31
- end = targetHeight + end;
32
- }
33
- const safeEnd = (0, utils_1.clamp)(end, 0, targetHeight);
34
- const sliceWidth = Math.max(0, safeEnd - safeStart);
35
- const specifiedHeight = opts.n !== undefined ? opts.n : sliceWidth;
36
- const strict = opts.strict !== false;
37
- if (strict) {
38
- if (specifiedHeight !== targetHeight) {
39
- throw new exceptions_1.ShapeError(`Column height mismatch: repeat length ${specifiedHeight} does not match DataFrame height ${targetHeight}`);
40
- }
41
- }
42
- else {
43
- const pad = opts.pad ?? false;
44
- const truncate = opts.truncate ?? false;
45
- if (pad && !truncate) {
46
- if (specifiedHeight > sliceWidth) {
47
- throw new exceptions_1.ShapeError(`Cannot pad repeat output: specified length ${specifiedHeight} starting at index ${safeStart} exceeds slice width ${sliceWidth} (requires truncation).`);
48
- }
49
- }
50
- else if (truncate && !pad) {
51
- if (specifiedHeight < sliceWidth) {
52
- throw new exceptions_1.ShapeError(`Cannot truncate repeat output: specified length ${specifiedHeight} starting at index ${safeStart} is less than slice width ${sliceWidth} (requires padding).`);
53
- }
54
- }
55
- }
56
- const finalHeight = targetHeight;
57
- const result = new Array(finalHeight);
58
- const repeatEnd = Math.min(safeStart + specifiedHeight, safeEnd);
59
- const rawFill = opts.padValue !== undefined ? opts.padValue : null;
60
- const coercedFill = opts.dtype ? opts.dtype.coerce(rawFill) : rawFill;
61
- const hasDtype = !!opts.dtype;
62
- const mode = opts.mode || "constant";
63
- const step = opts.step !== undefined ? opts.step : 1;
64
- // Fast-path optimization for simple constant lit/repeat operations
65
- if (mode === "constant" && safeStart === 0 && repeatEnd === finalHeight && !opts.dtype) {
66
- for (let i = 0; i < finalHeight; i++) {
67
- result[i] = value;
68
- }
69
- return result;
70
- }
71
- const seqVals = new Array(specifiedHeight);
72
- if (specifiedHeight > 0) {
73
- if (mode === "constant") {
74
- const finalVal = opts.dtype ? opts.dtype.coerce(value) : value;
75
- for (let idx = 0; idx < specifiedHeight; idx++) {
76
- seqVals[idx] = finalVal;
77
- }
78
- }
79
- else if (mode === "independent") {
80
- if (typeof step === "function") {
81
- for (let idx = 0; idx < specifiedHeight; idx++) {
82
- const val = step(idx, value);
83
- seqVals[idx] = hasDtype ? opts.dtype.coerce(val) : val;
84
- }
85
- }
86
- else {
87
- for (let idx = 0; idx < specifiedHeight; idx++) {
88
- const val = value + idx * step;
89
- seqVals[idx] = hasDtype ? opts.dtype.coerce(val) : val;
90
- }
91
- }
92
- }
93
- else {
94
- // cumulative mode
95
- let current = value;
96
- seqVals[0] = hasDtype ? opts.dtype.coerce(current) : current;
97
- if (typeof step === "function") {
98
- for (let idx = 1; idx < specifiedHeight; idx++) {
99
- current = step(current, idx);
100
- seqVals[idx] = hasDtype ? opts.dtype.coerce(current) : current;
101
- }
102
- }
103
- else {
104
- for (let idx = 1; idx < specifiedHeight; idx++) {
105
- current = current + step;
106
- seqVals[idx] = hasDtype ? opts.dtype.coerce(current) : current;
107
- }
108
- }
109
- }
110
- }
111
- for (let i = 0; i < finalHeight; i++) {
112
- if (i >= safeStart && i < repeatEnd) {
113
- result[i] = seqVals[i - safeStart];
114
- }
115
- else {
116
- result[i] = coercedFill;
117
- }
118
- }
119
- return result;
120
- });
121
- return expr;
122
- }
123
- /**
124
- * Creates a column expression that generates a sequence of values starting from the given start value.
125
- */
126
- function seq_range(start, options = { strict: true }) {
127
- return repeat(start, {
128
- ...options,
129
- mode: options.mode || "cumulative"
130
- });
131
- }
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.seq_range = seq_range;
4
- const ColumnExpr_1 = require("../ColumnExpr");
5
- const constants_1 = require("../constants");
6
- const exceptions_1 = require("../../exceptions");
7
- const utils_1 = require("../../utils");
8
- /**
9
- * Creates a column expression that generates a range of values.
10
- * If mode is "cumulative" (default) or "independent", it generates a sequence.
11
- * If mode is "constant", it repeats the given value.
12
- */
13
- function seq_range(value, options = { strict: true }) {
14
- const opts = options;
15
- const expr = new ColumnExpr_1.ColumnExpr(constants_1.LITERAL_MARKER);
16
- expr.literalValue = value;
17
- if (opts.name) {
18
- expr.outputName = opts.name;
19
- }
20
- expr.ops.push((vArray) => {
21
- const targetHeight = vArray.length;
22
- const getIdx = (val, def) => {
23
- if (val === undefined)
24
- return def;
25
- return (0, utils_1.clamp)(val < 0 ? targetHeight + val : val, { min: 0, max: targetHeight });
26
- };
27
- const safeStart = getIdx(opts.startIndex, 0);
28
- const safeEnd = getIdx(opts.endIndex, targetHeight);
29
- const sliceWidth = Math.max(0, safeEnd - safeStart);
30
- const specifiedHeight = opts.n !== undefined ? opts.n : sliceWidth;
31
- const strict = opts.strict !== false;
32
- if (strict) {
33
- if (specifiedHeight !== targetHeight) {
34
- throw new exceptions_1.ShapeError(`Column height mismatch: seq_range length ${specifiedHeight} does not match DataFrame height ${targetHeight}`);
35
- }
36
- }
37
- else {
38
- const pad = opts.pad ?? false;
39
- const truncate = opts.truncate ?? false;
40
- if (pad && !truncate && specifiedHeight > sliceWidth) {
41
- throw new exceptions_1.ShapeError(`Cannot pad seq_range output: specified length ${specifiedHeight} starting at index ${safeStart} exceeds slice width ${sliceWidth} (requires truncation).`);
42
- }
43
- if (truncate && !pad && specifiedHeight < sliceWidth) {
44
- throw new exceptions_1.ShapeError(`Cannot truncate seq_range output: specified length ${specifiedHeight} starting at index ${safeStart} is less than slice width ${sliceWidth} (requires padding).`);
45
- }
46
- }
47
- const finalHeight = targetHeight;
48
- const hasDtype = !!opts.dtype;
49
- const mode = opts.mode || "cumulative";
50
- const step = opts.step !== undefined ? opts.step : 1;
51
- const coerceVal = hasDtype
52
- ? (val) => opts.dtype.coerce(val)
53
- : (val) => val;
54
- if (strict) {
55
- const result = opts.dtype?.allocate
56
- ? opts.dtype.allocate(finalHeight)
57
- : new Array(finalHeight);
58
- (0, utils_1.fillSequence)(result, value, {
59
- mode,
60
- step,
61
- coerce: coerceVal,
62
- startIndex: 0,
63
- endIndex: finalHeight
64
- });
65
- return result;
66
- }
67
- // Non-strict mode path:
68
- const repeatEnd = Math.min(safeStart + specifiedHeight, safeEnd);
69
- const rawFill = opts.padValue !== undefined ? opts.padValue : null;
70
- const coercedFill = coerceVal(rawFill);
71
- // Fast-path optimization for simple constant lit/repeat operations
72
- if (mode === "constant" && safeStart === 0 && repeatEnd === finalHeight && !opts.dtype) {
73
- const result = new Array(finalHeight);
74
- for (let i = 0; i < finalHeight; i++) {
75
- result[i] = value;
76
- }
77
- return result;
78
- }
79
- const result = new Array(finalHeight);
80
- result.fill(coercedFill);
81
- (0, utils_1.fillSequence)(result, value, {
82
- mode,
83
- step,
84
- coerce: coerceVal,
85
- startIndex: safeStart,
86
- endIndex: repeatEnd
87
- });
88
- return result;
89
- });
90
- return expr;
91
- }
@@ -1,85 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WhenThen = exports.When = exports.WhenThenChain = void 0;
4
- exports.when = when;
5
- const ColumnExpr_1 = require("../ColumnExpr");
6
- const utils_1 = require("../../utils");
7
- class WhenThenChain {
8
- predicates;
9
- values;
10
- constructor(predicates, values) {
11
- this.predicates = predicates;
12
- this.values = values;
13
- }
14
- then(value) {
15
- return new WhenThen(this.predicates, this.values.concat(value));
16
- }
17
- }
18
- exports.WhenThenChain = WhenThenChain;
19
- class When {
20
- predicates;
21
- constructor(predicate) {
22
- this.predicates = [predicate];
23
- }
24
- then(value) {
25
- return new WhenThen(this.predicates, [value]);
26
- }
27
- }
28
- exports.When = When;
29
- class WhenThen extends ColumnExpr_1.ColumnExpr {
30
- predicates;
31
- values;
32
- otherwiseValue;
33
- constructor(predicates, values, otherwiseValue = null) {
34
- super(typeof predicates === "string" ? predicates : "*when*");
35
- this.predicates = Array.isArray(predicates) ? predicates : [];
36
- this.values = values || [];
37
- this.otherwiseValue = otherwiseValue;
38
- this.ops.push((_, columns) => {
39
- const height = _.length;
40
- const evaluateArg = (arg) => {
41
- if (ColumnExpr_1.ColumnExpr.isColExpr(arg)) {
42
- return arg.evaluate(columns, height);
43
- }
44
- if (typeof arg === "string" && (arg in columns)) {
45
- return columns[arg];
46
- }
47
- return arg;
48
- };
49
- const numConditions = this.predicates.length;
50
- const evaluatedPreds = new Array(numConditions);
51
- const evaluatedVals = new Array(numConditions);
52
- for (let j = 0; j < numConditions; j++) {
53
- evaluatedPreds[j] = evaluateArg(this.predicates[j]);
54
- evaluatedVals[j] = evaluateArg(this.values[j]);
55
- }
56
- const evaluatedOtherwise = evaluateArg(this.otherwiseValue);
57
- const result = new Array(height);
58
- for (let i = 0; i < height; i++) {
59
- let matched = false;
60
- for (let j = 0; j < numConditions; j++) {
61
- const predVal = (0, utils_1.isArrayOrTypedArray)(evaluatedPreds[j]) ? evaluatedPreds[j][i] : evaluatedPreds[j];
62
- if (predVal === true) {
63
- result[i] = (0, utils_1.isArrayOrTypedArray)(evaluatedVals[j]) ? evaluatedVals[j][i] : evaluatedVals[j];
64
- matched = true;
65
- break;
66
- }
67
- }
68
- if (!matched) {
69
- result[i] = (0, utils_1.isArrayOrTypedArray)(evaluatedOtherwise) ? evaluatedOtherwise[i] : evaluatedOtherwise;
70
- }
71
- }
72
- return result;
73
- });
74
- }
75
- when(predicate) {
76
- return new WhenThenChain(this.predicates.concat(predicate), this.values);
77
- }
78
- otherwise(value) {
79
- return new WhenThen(this.predicates, this.values, value);
80
- }
81
- }
82
- exports.WhenThen = WhenThen;
83
- function when(predicate) {
84
- return new When(predicate);
85
- }
@@ -1,38 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./constants"), exports);
18
- __exportStar(require("./types"), exports);
19
- __exportStar(require("./ExprBase"), exports);
20
- __exportStar(require("./mixins/ArithmeticExpr"), exports);
21
- __exportStar(require("./mixins/LogicalExpr"), exports);
22
- __exportStar(require("./mixins/ComparisonExpr"), exports);
23
- __exportStar(require("./mixins/StringExpr"), exports);
24
- __exportStar(require("./mixins/AggregationExpr"), exports);
25
- __exportStar(require("./mixins/WindowExpr"), exports);
26
- __exportStar(require("./mixins/TemporalExpr"), exports);
27
- __exportStar(require("./mixins/ListExpr"), exports);
28
- __exportStar(require("./mixins/StructExpr"), exports);
29
- __exportStar(require("./ColumnExpr"), exports);
30
- __exportStar(require("./functions/lit"), exports);
31
- __exportStar(require("./functions/all"), exports);
32
- __exportStar(require("./functions/exclude"), exports);
33
- __exportStar(require("./functions/coalesce"), exports);
34
- __exportStar(require("./functions/when"), exports);
35
- __exportStar(require("./functions/implode"), exports);
36
- __exportStar(require("./functions/seq_range"), exports);
37
- __exportStar(require("./functions/element"), exports);
38
- __exportStar(require("./utils"), exports);
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AggregationExpr = void 0;
4
- const ExprBase_1 = require("../ExprBase");
5
- const exceptions_1 = require("../../exceptions");
6
- const utils_1 = require("../../utils");
7
- class AggregationExpr extends ExprBase_1.ExprBase {
8
- _deriveAgg(fn) {
9
- const newInst = (0, ExprBase_1.derive)(this);
10
- newInst.aggFn = fn;
11
- newInst.groupingOpsIndex = this.ops.length;
12
- newInst.partitionOpsIndex = this.ops.length;
13
- return newInst;
14
- }
15
- all() {
16
- return this._deriveAgg(v => (0, utils_1.isArrayOfType)(v, (x) => !!x, { mode: "every" }));
17
- }
18
- all_null() {
19
- return this._deriveAgg(v => (0, utils_1.isArrayOfType)(v, "nullish", { mode: "every" }));
20
- }
21
- any() {
22
- return this._deriveAgg(v => (0, utils_1.isArrayOfType)(v, (x) => !!x, { mode: "some" }));
23
- }
24
- any_null() {
25
- return this._deriveAgg(v => (0, utils_1.isArrayOfType)(v, "nullish", { mode: "some" }));
26
- }
27
- avg() {
28
- return this._deriveAgg(v => (0, utils_1.getListStats)(v).mean);
29
- }
30
- count(options = {}) {
31
- if (options.includeNulls)
32
- return this._deriveAgg(v => v.length);
33
- return this._deriveAgg(v => (0, utils_1.getListStats)(v).count);
34
- }
35
- first() {
36
- return this._deriveAgg(v => v[0] ?? null);
37
- }
38
- implode() {
39
- return this._deriveAgg(v => v);
40
- }
41
- last() {
42
- return this._deriveAgg(v => v[v.length - 1] ?? null);
43
- }
44
- max() {
45
- return this._deriveAgg(v => (0, utils_1.getListStats)(v).max);
46
- }
47
- mean() {
48
- return this.avg();
49
- }
50
- median() {
51
- return this._deriveAgg(v => (0, utils_1.computeMedian)(v));
52
- }
53
- min() {
54
- return this._deriveAgg(v => (0, utils_1.getListStats)(v).min);
55
- }
56
- mode() {
57
- return this._deriveAgg(v => (0, utils_1.computeMode)(v));
58
- }
59
- n_unique(options = {}) {
60
- return this._deriveAgg(v => {
61
- return (0, utils_1.getUniqueListStats)(v, options).count;
62
- });
63
- }
64
- quantile(q) {
65
- if (q < 0 || q > 1)
66
- throw new exceptions_1.ComputeError("Quantile q must be between 0 and 1");
67
- return this._deriveAgg(v => (0, utils_1.computeQuantile)(v, q));
68
- }
69
- std() {
70
- return this._deriveAgg(v => (0, utils_1.getListStats)(v).std);
71
- }
72
- sum() {
73
- return this._deriveAgg(v => (0, utils_1.getListStats)(v).sum);
74
- }
75
- }
76
- exports.AggregationExpr = AggregationExpr;
@@ -1,131 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArithmeticExpr = void 0;
4
- const ExprBase_1 = require("../ExprBase");
5
- const utils_1 = require("../utils");
6
- const utils_2 = require("../../utils");
7
- class ArithmeticExpr extends ExprBase_1.ExprBase {
8
- abs() {
9
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)((v) => Math.abs(v)));
10
- }
11
- acos() {
12
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)((v) => (v < -1 || v > 1) ? null : Math.acos(v)));
13
- }
14
- acosh() {
15
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)((v) => v < 1 ? null : Math.acosh(v)));
16
- }
17
- add(val) {
18
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneBinary)(this, val, (v, r) => v + r));
19
- }
20
- asin() {
21
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)((v) => (v < -1 || v > 1) ? null : Math.asin(v)));
22
- }
23
- asinh() {
24
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.asinh));
25
- }
26
- atan() {
27
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.atan));
28
- }
29
- atanh() {
30
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)((v) => (v <= -1 || v >= 1) ? null : Math.atanh(v)));
31
- }
32
- cbrt() {
33
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.cbrt));
34
- }
35
- ceil() {
36
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.ceil));
37
- }
38
- clip(lower = null, upper = null) {
39
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)((v) => (0, utils_2.clamp)(v, { min: lower, max: upper })));
40
- }
41
- cos() {
42
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.cos));
43
- }
44
- cosh() {
45
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.cosh));
46
- }
47
- degrees() {
48
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)((v) => v * (180 / Math.PI)));
49
- }
50
- div(val) {
51
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneBinary)(this, val, (v, r) => r === 0 ? null : v / r));
52
- }
53
- exp() {
54
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.exp));
55
- }
56
- expm1() {
57
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.expm1));
58
- }
59
- floor() {
60
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.floor));
61
- }
62
- floordiv(val) {
63
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneBinary)(this, val, (v, r) => r === 0 ? null : Math.floor(v / r)));
64
- }
65
- hypot(val) {
66
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneBinary)(this, val, (v, r) => Math.hypot(v, r)));
67
- }
68
- log(base = Math.E) {
69
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)((v) => v <= 0 ? null : (base === Math.E ? Math.log(v) : Math.log(v) / Math.log(base))));
70
- }
71
- log1p() {
72
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)((v) => v <= -1 ? null : Math.log1p(v)));
73
- }
74
- mod(val) {
75
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneBinary)(this, val, (v, r) => r === 0 ? null : v % r));
76
- }
77
- mul(val) {
78
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneBinary)(this, val, (v, r) => v * r));
79
- }
80
- negate() {
81
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)((v) => -v));
82
- }
83
- pow(val) {
84
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneBinary)(this, val, (v, r) => Math.pow(v, r)));
85
- }
86
- radians() {
87
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)((v) => v * (Math.PI / 180)));
88
- }
89
- rand(seed, { min = 0, max = 1, integer = false } = {}) {
90
- return (0, ExprBase_1.derive)(this, (vArray) => {
91
- const len = vArray.length;
92
- const out = new Float64Array(len);
93
- const rnd = seed !== undefined ? (0, utils_2.mulberry32)(seed) : Math.random;
94
- const range = max - min;
95
- for (let i = 0; i < len; i++) {
96
- const raw = rnd();
97
- out[i] = integer ? Math.floor(raw * (range + 1)) + min : raw * range + min;
98
- }
99
- return out;
100
- });
101
- }
102
- round(decimals = 0) {
103
- const factor = Math.pow(10, decimals);
104
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)((v) => Math.round(v * factor) / factor));
105
- }
106
- sign() {
107
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.sign));
108
- }
109
- sin() {
110
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.sin));
111
- }
112
- sinh() {
113
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.sinh));
114
- }
115
- sqrt() {
116
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)((v) => v < 0 ? null : Math.sqrt(v)));
117
- }
118
- sub(val) {
119
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneBinary)(this, val, (v, r) => v - r));
120
- }
121
- tan() {
122
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.tan));
123
- }
124
- tanh() {
125
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.tanh));
126
- }
127
- trunc() {
128
- return (0, ExprBase_1.derive)(this, (0, utils_1.kleeneUnary)(Math.trunc));
129
- }
130
- }
131
- exports.ArithmeticExpr = ArithmeticExpr;
@@ -1,40 +0,0 @@
1
- import type { ExprConstructor } from "../types";
2
- export declare const BooleanExpr: <TBase extends ExprConstructor>(Base: TBase) => {
3
- new (...args: any[]): {
4
- and(other: any): /*elided*/ any;
5
- not(): /*elided*/ any;
6
- or(other: any): /*elided*/ any;
7
- xor(other: any): /*elided*/ any;
8
- all(): /*elided*/ any;
9
- all_null(): /*elided*/ any;
10
- any(): /*elided*/ any;
11
- any_null(): /*elided*/ any;
12
- ops: import("../..").OpFn[];
13
- colName?: string;
14
- outputName?: string;
15
- isLiteral?: boolean;
16
- literalValue?: any;
17
- aggFn?: import("../..").AggFn<any> | null;
18
- groupingOpsIndex?: number;
19
- partitionOpsIndex?: number;
20
- partitionBy?: (string | import("../..").IExpr)[] | null;
21
- windowOp?: {
22
- type: string;
23
- [key: string]: any;
24
- } | null;
25
- isWindow?: boolean;
26
- alias(name: string): /*elided*/ any;
27
- cast(dataType: import("../..").RegisteredDataType): /*elided*/ any;
28
- _resolve(val: any, columns: import("../..").ColumnDict, height: number): import("../..").ColumnData | any;
29
- evaluate(columns: import("../..").ColumnDict, height: number): import("../..").ColumnData;
30
- evaluatePreGrouping(columns: import("../..").ColumnDict, height: number): import("../..").ColumnData;
31
- evaluatePostGrouping(aggregatedArray: any[], columns: import("../..").ColumnDict): import("../..").ColumnData;
32
- evaluatePrePartition(columns: import("../..").ColumnDict, height: number): import("../..").ColumnData;
33
- evaluatePostPartition(aggregatedArray: any[], columns: import("../..").ColumnDict): import("../..").ColumnData;
34
- evaluateWindow?(groupPreValues: any[], partitionIndices: number[], currentIndex: number): any;
35
- debug(label?: string): /*elided*/ any;
36
- _window(evaluateWindow: (this: import("../..").IExpr, groupPreValues: any[], partitionIndices: number[], currentIndex: number) => any): /*elided*/ any;
37
- _rolling(windowSize: number, aggFn: (vals: any[]) => any): /*elided*/ any;
38
- _deriveAgg(fn: import("../..").AggFn<any>): /*elided*/ any;
39
- };
40
- } & TBase;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BooleanExpr = void 0;
4
- const ExprBase_1 = require("../ExprBase");
5
- const utils_1 = require("../../utils");
6
- const BooleanExpr = (Base) => {
7
- return class extends Base {
8
- and(other) {
9
- return (0, ExprBase_1.derive)(this, (vArray, columns) => {
10
- const height = vArray.length;
11
- const otherVal = this._resolve(other, columns, height);
12
- const isOtherArray = (0, utils_1.isArrayOrTypedArray)(otherVal);
13
- const result = new Array(height);
14
- for (let i = 0; i < height; i++) {
15
- const v = vArray[i];
16
- const w = isOtherArray ? otherVal[i] : otherVal;
17
- if (v === false || w === false)
18
- result[i] = false;
19
- else if (v == null || w == null)
20
- result[i] = null;
21
- else
22
- result[i] = true;
23
- }
24
- return result;
25
- });
26
- }
27
- not() {
28
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => !v));
29
- }
30
- or(other) {
31
- return (0, ExprBase_1.derive)(this, (vArray, columns) => {
32
- const height = vArray.length;
33
- const otherVal = this._resolve(other, columns, height);
34
- const isOtherArray = (0, utils_1.isArrayOrTypedArray)(otherVal);
35
- const result = new Array(height);
36
- for (let i = 0; i < height; i++) {
37
- const v = vArray[i];
38
- const w = isOtherArray ? otherVal[i] : otherVal;
39
- if (v === true || w === true)
40
- result[i] = true;
41
- else if (v == null || w == null)
42
- result[i] = null;
43
- else
44
- result[i] = false;
45
- }
46
- return result;
47
- });
48
- }
49
- xor(other) {
50
- return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, other, (v, w) => !!v !== !!w));
51
- }
52
- // Boolean Aggregations
53
- all() {
54
- return this._deriveAgg((v) => (0, utils_1.isArrayOfType)(v, (x) => !!x, { mode: "every" }));
55
- }
56
- all_null() {
57
- return this._deriveAgg((v) => (0, utils_1.isArrayOfType)(v, "nullish", { mode: "every" }));
58
- }
59
- any() {
60
- return this._deriveAgg((v) => (0, utils_1.isArrayOfType)(v, (x) => !!x, { mode: "some" }));
61
- }
62
- any_null() {
63
- return this._deriveAgg((v) => (0, utils_1.isArrayOfType)(v, "nullish", { mode: "some" }));
64
- }
65
- };
66
- };
67
- exports.BooleanExpr = BooleanExpr;