df-script 1.4.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 (134) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +269 -0
  3. package/dist/api.d.ts +39 -0
  4. package/dist/api.js +18 -0
  5. package/dist/bundle.min.js +1 -0
  6. package/dist/columnExpressions/ColumnExpr.d.ts +368 -0
  7. package/dist/columnExpressions/ColumnExpr.js +23 -0
  8. package/dist/columnExpressions/ExprBase.d.ts +24 -0
  9. package/dist/columnExpressions/ExprBase.js +133 -0
  10. package/dist/columnExpressions/constants.d.ts +2 -0
  11. package/dist/columnExpressions/constants.js +5 -0
  12. package/dist/columnExpressions/functions/all.d.ts +5 -0
  13. package/dist/columnExpressions/functions/all.js +11 -0
  14. package/dist/columnExpressions/functions/coalesce.d.ts +3 -0
  15. package/dist/columnExpressions/functions/coalesce.js +40 -0
  16. package/dist/columnExpressions/functions/exclude.d.ts +5 -0
  17. package/dist/columnExpressions/functions/exclude.js +13 -0
  18. package/dist/columnExpressions/functions/lit.d.ts +5 -0
  19. package/dist/columnExpressions/functions/lit.js +22 -0
  20. package/dist/columnExpressions/functions/when.d.ts +24 -0
  21. package/dist/columnExpressions/functions/when.js +81 -0
  22. package/dist/columnExpressions/index.d.ts +19 -0
  23. package/dist/columnExpressions/index.js +81 -0
  24. package/dist/columnExpressions/mixins/AggregationExpr.d.ts +50 -0
  25. package/dist/columnExpressions/mixins/AggregationExpr.js +172 -0
  26. package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +67 -0
  27. package/dist/columnExpressions/mixins/ArithmeticExpr.js +143 -0
  28. package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +60 -0
  29. package/dist/columnExpressions/mixins/ComparisonExpr.js +389 -0
  30. package/dist/columnExpressions/mixins/ListExpr.d.ts +63 -0
  31. package/dist/columnExpressions/mixins/ListExpr.js +248 -0
  32. package/dist/columnExpressions/mixins/LogicalExpr.d.ts +33 -0
  33. package/dist/columnExpressions/mixins/LogicalExpr.js +54 -0
  34. package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +31 -0
  35. package/dist/columnExpressions/mixins/ManipulationExpr.js +35 -0
  36. package/dist/columnExpressions/mixins/StringExpr.d.ts +79 -0
  37. package/dist/columnExpressions/mixins/StringExpr.js +249 -0
  38. package/dist/columnExpressions/mixins/TemporalExpr.d.ts +69 -0
  39. package/dist/columnExpressions/mixins/TemporalExpr.js +127 -0
  40. package/dist/columnExpressions/mixins/WindowExpr.d.ts +50 -0
  41. package/dist/columnExpressions/mixins/WindowExpr.js +281 -0
  42. package/dist/columnExpressions/types.d.ts +7 -0
  43. package/dist/columnExpressions/types.js +2 -0
  44. package/dist/dataframe/constants.d.ts +1 -0
  45. package/dist/dataframe/constants.js +4 -0
  46. package/dist/dataframe/dataframe.d.ts +42 -0
  47. package/dist/dataframe/dataframe.js +749 -0
  48. package/dist/dataframe/grouped/grouped.d.ts +15 -0
  49. package/dist/dataframe/grouped/grouped.js +113 -0
  50. package/dist/dataframe/index.d.ts +4 -0
  51. package/dist/dataframe/index.js +20 -0
  52. package/dist/dataframe/types.d.ts +33 -0
  53. package/dist/dataframe/types.js +2 -0
  54. package/dist/dataframe/utils.d.ts +11 -0
  55. package/dist/dataframe/utils.js +215 -0
  56. package/dist/datatypes/DataType.d.ts +40 -0
  57. package/dist/datatypes/DataType.js +47 -0
  58. package/dist/datatypes/index.d.ts +29 -0
  59. package/dist/datatypes/index.js +46 -0
  60. package/dist/datatypes/types/Binary.d.ts +9 -0
  61. package/dist/datatypes/types/Binary.js +18 -0
  62. package/dist/datatypes/types/Boolean.d.ts +9 -0
  63. package/dist/datatypes/types/Boolean.js +19 -0
  64. package/dist/datatypes/types/Date.d.ts +8 -0
  65. package/dist/datatypes/types/Date.js +21 -0
  66. package/dist/datatypes/types/Datetime.d.ts +8 -0
  67. package/dist/datatypes/types/Datetime.js +17 -0
  68. package/dist/datatypes/types/Decimal.d.ts +10 -0
  69. package/dist/datatypes/types/Decimal.js +28 -0
  70. package/dist/datatypes/types/Duration.d.ts +8 -0
  71. package/dist/datatypes/types/Duration.js +17 -0
  72. package/dist/datatypes/types/Float32.d.ts +8 -0
  73. package/dist/datatypes/types/Float32.js +17 -0
  74. package/dist/datatypes/types/Float64.d.ts +8 -0
  75. package/dist/datatypes/types/Float64.js +17 -0
  76. package/dist/datatypes/types/Int16.d.ts +8 -0
  77. package/dist/datatypes/types/Int16.js +17 -0
  78. package/dist/datatypes/types/Int32.d.ts +8 -0
  79. package/dist/datatypes/types/Int32.js +17 -0
  80. package/dist/datatypes/types/Int64.d.ts +8 -0
  81. package/dist/datatypes/types/Int64.js +17 -0
  82. package/dist/datatypes/types/Int8.d.ts +8 -0
  83. package/dist/datatypes/types/Int8.js +17 -0
  84. package/dist/datatypes/types/List.d.ts +10 -0
  85. package/dist/datatypes/types/List.js +31 -0
  86. package/dist/datatypes/types/Null.d.ts +9 -0
  87. package/dist/datatypes/types/Null.js +17 -0
  88. package/dist/datatypes/types/Object.d.ts +9 -0
  89. package/dist/datatypes/types/Object.js +17 -0
  90. package/dist/datatypes/types/Struct.d.ts +14 -0
  91. package/dist/datatypes/types/Struct.js +39 -0
  92. package/dist/datatypes/types/Time.d.ts +8 -0
  93. package/dist/datatypes/types/Time.js +29 -0
  94. package/dist/datatypes/types/UInt16.d.ts +8 -0
  95. package/dist/datatypes/types/UInt16.js +17 -0
  96. package/dist/datatypes/types/UInt32.d.ts +8 -0
  97. package/dist/datatypes/types/UInt32.js +17 -0
  98. package/dist/datatypes/types/UInt64.d.ts +8 -0
  99. package/dist/datatypes/types/UInt64.js +17 -0
  100. package/dist/datatypes/types/UInt8.d.ts +8 -0
  101. package/dist/datatypes/types/UInt8.js +17 -0
  102. package/dist/datatypes/types/Utf8.d.ts +10 -0
  103. package/dist/datatypes/types/Utf8.js +20 -0
  104. package/dist/datatypes/types.d.ts +172 -0
  105. package/dist/datatypes/types.js +286 -0
  106. package/dist/exceptions/index.d.ts +13 -0
  107. package/dist/exceptions/index.js +43 -0
  108. package/dist/exceptions/utils.d.ts +2 -0
  109. package/dist/exceptions/utils.js +9 -0
  110. package/dist/functions/concat.d.ts +4 -0
  111. package/dist/functions/concat.js +248 -0
  112. package/dist/functions/index.d.ts +1 -0
  113. package/dist/functions/index.js +17 -0
  114. package/dist/index.d.ts +7 -0
  115. package/dist/index.js +1 -0
  116. package/dist/types.d.ts +47 -0
  117. package/dist/types.js +2 -0
  118. package/dist/utils/boolean.d.ts +1 -0
  119. package/dist/utils/boolean.js +18 -0
  120. package/dist/utils/date.d.ts +57 -0
  121. package/dist/utils/date.js +349 -0
  122. package/dist/utils/guards.d.ts +14 -0
  123. package/dist/utils/guards.js +143 -0
  124. package/dist/utils/index.d.ts +5 -0
  125. package/dist/utils/index.js +21 -0
  126. package/dist/utils/json.d.ts +2 -0
  127. package/dist/utils/json.js +33 -0
  128. package/dist/utils/list.d.ts +23 -0
  129. package/dist/utils/list.js +128 -0
  130. package/dist/utils/number.d.ts +86 -0
  131. package/dist/utils/number.js +223 -0
  132. package/dist/utils/string.d.ts +52 -0
  133. package/dist/utils/string.js +120 -0
  134. package/package.json +34 -0
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lit = lit;
4
+ const ColumnExpr_1 = require("../ColumnExpr");
5
+ const constants_1 = require("../constants");
6
+ /**
7
+ * Creates a literal column expression that repeats the given value for all rows.
8
+ */
9
+ function lit(value) {
10
+ const expr = new ColumnExpr_1.ColumnExpr(constants_1.LITERAL_MARKER);
11
+ expr.isLiteral = true;
12
+ expr.literalValue = value;
13
+ expr.ops.push((vArray) => {
14
+ const height = vArray.length;
15
+ const result = new Array(height);
16
+ for (let i = 0; i < height; i++) {
17
+ result[i] = value;
18
+ }
19
+ return result;
20
+ });
21
+ return expr;
22
+ }
@@ -0,0 +1,24 @@
1
+ import { ColumnExpr } from "../ColumnExpr";
2
+ import type { IExpr, Scalar } from "../../types";
3
+ type WhenArg = IExpr | Scalar;
4
+ export declare class WhenThenChain {
5
+ private predicates;
6
+ private values;
7
+ constructor(predicates: WhenArg[], values: WhenArg[]);
8
+ then(value: WhenArg): WhenThen;
9
+ }
10
+ export declare class When {
11
+ private predicates;
12
+ constructor(predicate: WhenArg);
13
+ then(value: WhenArg): WhenThen;
14
+ }
15
+ export declare class WhenThen extends ColumnExpr<any> {
16
+ private predicates;
17
+ private values;
18
+ private otherwiseValue;
19
+ constructor(predicates: WhenArg[] | string, values?: WhenArg[], otherwiseValue?: WhenArg);
20
+ when(predicate: WhenArg): WhenThenChain;
21
+ otherwise(value: WhenArg): ColumnExpr<any>;
22
+ }
23
+ export declare function when(predicate: WhenArg): When;
24
+ export {};
@@ -0,0 +1,81 @@
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 (arg && typeof arg === "object" && "evaluate" in 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 evaluatedPreds = this.predicates.map(evaluateArg);
50
+ const evaluatedVals = this.values.map(evaluateArg);
51
+ const evaluatedOtherwise = evaluateArg(this.otherwiseValue);
52
+ const result = new Array(height);
53
+ const numConditions = evaluatedPreds.length;
54
+ for (let i = 0; i < height; i++) {
55
+ let matched = false;
56
+ for (let j = 0; j < numConditions; j++) {
57
+ const predVal = (0, utils_1.isArrayOrTypedArray)(evaluatedPreds[j]) ? evaluatedPreds[j][i] : evaluatedPreds[j];
58
+ if (predVal === true) {
59
+ result[i] = (0, utils_1.isArrayOrTypedArray)(evaluatedVals[j]) ? evaluatedVals[j][i] : evaluatedVals[j];
60
+ matched = true;
61
+ break;
62
+ }
63
+ }
64
+ if (!matched) {
65
+ result[i] = (0, utils_1.isArrayOrTypedArray)(evaluatedOtherwise) ? evaluatedOtherwise[i] : evaluatedOtherwise;
66
+ }
67
+ }
68
+ return result;
69
+ });
70
+ }
71
+ when(predicate) {
72
+ return new WhenThenChain(this.predicates.concat(predicate), this.values);
73
+ }
74
+ otherwise(value) {
75
+ return new WhenThen(this.predicates, this.values, value);
76
+ }
77
+ }
78
+ exports.WhenThen = WhenThen;
79
+ function when(predicate) {
80
+ return new When(predicate);
81
+ }
@@ -0,0 +1,19 @@
1
+ import type { IExpr } from "../types";
2
+ export * from "./constants";
3
+ export * from "./types";
4
+ export * from "./ExprBase";
5
+ export * from "./mixins/ArithmeticExpr";
6
+ export * from "./mixins/LogicalExpr";
7
+ export * from "./mixins/ComparisonExpr";
8
+ export * from "./mixins/StringExpr";
9
+ export * from "./mixins/AggregationExpr";
10
+ export * from "./mixins/WindowExpr";
11
+ export * from "./mixins/TemporalExpr";
12
+ export * from "./mixins/ListExpr";
13
+ export * from "./ColumnExpr";
14
+ export * from "./functions/lit";
15
+ export * from "./functions/all";
16
+ export * from "./functions/exclude";
17
+ export * from "./functions/coalesce";
18
+ export * from "./functions/when";
19
+ export declare function resolveColumnSelectors(exprs: any[], allKeys: string[], keysToExcludeFromAll?: string[]): IExpr[];
@@ -0,0 +1,81 @@
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
+ exports.resolveColumnSelectors = resolveColumnSelectors;
18
+ const ColumnExpr_1 = require("./ColumnExpr");
19
+ const constants_1 = require("./constants");
20
+ __exportStar(require("./constants"), exports);
21
+ __exportStar(require("./types"), exports);
22
+ __exportStar(require("./ExprBase"), exports);
23
+ __exportStar(require("./mixins/ArithmeticExpr"), exports);
24
+ __exportStar(require("./mixins/LogicalExpr"), exports);
25
+ __exportStar(require("./mixins/ComparisonExpr"), exports);
26
+ __exportStar(require("./mixins/StringExpr"), exports);
27
+ __exportStar(require("./mixins/AggregationExpr"), exports);
28
+ __exportStar(require("./mixins/WindowExpr"), exports);
29
+ __exportStar(require("./mixins/TemporalExpr"), exports);
30
+ __exportStar(require("./mixins/ListExpr"), exports);
31
+ __exportStar(require("./ColumnExpr"), exports);
32
+ __exportStar(require("./functions/lit"), exports);
33
+ __exportStar(require("./functions/all"), exports);
34
+ __exportStar(require("./functions/exclude"), exports);
35
+ __exportStar(require("./functions/coalesce"), exports);
36
+ __exportStar(require("./functions/when"), exports);
37
+ function resolveColumnSelectors(exprs, allKeys, keysToExcludeFromAll) {
38
+ const expanded = [];
39
+ const excludeSet = keysToExcludeFromAll ? new Set(keysToExcludeFromAll) : new Set();
40
+ for (const expr of exprs) {
41
+ if (typeof expr === "string") {
42
+ expanded.push(new ColumnExpr_1.ColumnExpr(expr));
43
+ }
44
+ else if (expr instanceof ColumnExpr_1.ColumnExpr && expr.colName === constants_1.ALL_COLUMNS_MARKER) {
45
+ const excluded = new Set(expr.excludedCols);
46
+ for (const key of allKeys) {
47
+ if (!excludeSet.has(key) && !excluded.has(key)) {
48
+ const concrete = new ColumnExpr_1.ColumnExpr(key);
49
+ concrete.ops = [...expr.ops];
50
+ concrete.aggFn = expr.aggFn;
51
+ concrete.partitionOpsIndex = expr.partitionOpsIndex;
52
+ concrete.groupingOpsIndex = expr.groupingOpsIndex;
53
+ concrete.partitionBy = expr.partitionBy;
54
+ if (expr.evaluateWindow) {
55
+ concrete.evaluateWindow = expr.evaluateWindow;
56
+ }
57
+ if (expr.outputName && expr.outputName !== constants_1.ALL_COLUMNS_MARKER) {
58
+ concrete.outputName = expr.outputName;
59
+ }
60
+ expanded.push(concrete);
61
+ }
62
+ }
63
+ }
64
+ else if (expr && typeof expr === 'object' && 'evaluate' in expr && !expr.colName) {
65
+ for (const key of allKeys) {
66
+ if (!excludeSet.has(key)) {
67
+ const concrete = new ColumnExpr_1.ColumnExpr(key);
68
+ concrete.ops = [...expr.ops];
69
+ concrete.aggFn = expr.aggFn;
70
+ concrete.groupingOpsIndex = expr.groupingOpsIndex;
71
+ concrete.partitionOpsIndex = expr.partitionOpsIndex;
72
+ expanded.push(concrete);
73
+ }
74
+ }
75
+ }
76
+ else {
77
+ expanded.push(expr);
78
+ }
79
+ }
80
+ return expanded;
81
+ }
@@ -0,0 +1,50 @@
1
+ import type { AggFn } from "../../types";
2
+ import type { ExprConstructor } from "../types";
3
+ export declare const AggregationExpr: <TBase extends ExprConstructor>(Base: TBase) => {
4
+ new (...args: any[]): {
5
+ aggFn: AggFn<any> | null;
6
+ _deriveAgg(fn: AggFn<any>): /*elided*/ any;
7
+ all(): /*elided*/ any;
8
+ all_null(): /*elided*/ any;
9
+ any(): /*elided*/ any;
10
+ any_null(): /*elided*/ any;
11
+ avg(): /*elided*/ any;
12
+ count(options?: {
13
+ includeNulls?: boolean;
14
+ }): /*elided*/ any;
15
+ first(): /*elided*/ any;
16
+ last(): /*elided*/ any;
17
+ max(): /*elided*/ any;
18
+ mean(): /*elided*/ any;
19
+ median(): /*elided*/ any;
20
+ min(): /*elided*/ any;
21
+ mode(): /*elided*/ any;
22
+ n_unique(): /*elided*/ any;
23
+ quantile(q: number): /*elided*/ any;
24
+ std(): /*elided*/ any;
25
+ sum(): /*elided*/ any;
26
+ ops: import("../../types").OpFn[];
27
+ colName?: string;
28
+ outputName?: string;
29
+ isLiteral?: boolean;
30
+ literalValue?: any;
31
+ groupingOpsIndex?: number;
32
+ partitionOpsIndex?: number;
33
+ partitionBy?: (string | import("../../types").IExpr)[] | null;
34
+ windowOp?: {
35
+ type: string;
36
+ [key: string]: any;
37
+ } | null;
38
+ isWindow?: boolean;
39
+ alias(name: string): /*elided*/ any;
40
+ cast(dataType: any): /*elided*/ any;
41
+ _resolve(val: any, columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData | any;
42
+ evaluate(columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData;
43
+ evaluatePreGrouping(columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData;
44
+ evaluatePostGrouping(aggregatedArray: any[], columns: import("../../types").ColumnDict): import("../../types").ColumnData;
45
+ evaluatePrePartition(columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData;
46
+ evaluatePostPartition(aggregatedArray: any[], columns: import("../../types").ColumnDict): import("../../types").ColumnData;
47
+ evaluateWindow?(groupPreValues: any[], partitionIndices: number[], currentIndex: number): any;
48
+ debug(label?: string): /*elided*/ any;
49
+ };
50
+ } & TBase;
@@ -0,0 +1,172 @@
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
+ const AggregationExpr = (Base) => {
8
+ return class extends Base {
9
+ aggFn = this.aggFn || null;
10
+ _deriveAgg(fn) {
11
+ const newInst = (0, ExprBase_1.derive)(this);
12
+ newInst.aggFn = fn;
13
+ newInst.groupingOpsIndex = this.ops.length;
14
+ newInst.partitionOpsIndex = this.ops.length;
15
+ return newInst;
16
+ }
17
+ all() {
18
+ return this._deriveAgg(v => {
19
+ for (let i = 0; i < v.length; i++) {
20
+ if (!v[i])
21
+ return false;
22
+ }
23
+ return true;
24
+ });
25
+ }
26
+ all_null() {
27
+ return this._deriveAgg(v => {
28
+ for (let i = 0; i < v.length; i++) {
29
+ if (v[i] != null)
30
+ return false;
31
+ }
32
+ return true;
33
+ });
34
+ }
35
+ any() {
36
+ return this._deriveAgg(v => {
37
+ for (let i = 0; i < v.length; i++) {
38
+ if (v[i])
39
+ return true;
40
+ }
41
+ return false;
42
+ });
43
+ }
44
+ any_null() {
45
+ return this._deriveAgg(v => {
46
+ for (let i = 0; i < v.length; i++) {
47
+ if (v[i] == null)
48
+ return true;
49
+ }
50
+ return false;
51
+ });
52
+ }
53
+ avg() {
54
+ return this._deriveAgg(v => (0, utils_1.getListStats)(v).mean);
55
+ }
56
+ count(options = {}) {
57
+ if (options.includeNulls)
58
+ return this._deriveAgg(v => v.length);
59
+ return this._deriveAgg(v => (0, utils_1.getListStats)(v).count);
60
+ }
61
+ first() {
62
+ return this._deriveAgg(v => v[0] ?? null);
63
+ }
64
+ last() {
65
+ return this._deriveAgg(v => v[v.length - 1] ?? null);
66
+ }
67
+ max() {
68
+ return this._deriveAgg(v => (0, utils_1.getListStats)(v).max);
69
+ }
70
+ mean() {
71
+ return this.avg();
72
+ }
73
+ median() {
74
+ return this._deriveAgg(v => {
75
+ if (!(0, utils_1.isArrayOfType)(v, "number", { allowNulls: true }))
76
+ return null;
77
+ const len = v.length;
78
+ const nums = [];
79
+ for (let i = 0; i < len; i++) {
80
+ const val = v[i];
81
+ if (val != null) {
82
+ nums.push(val);
83
+ }
84
+ }
85
+ const numsLen = nums.length;
86
+ if (numsLen === 0)
87
+ return null;
88
+ nums.sort((a, b) => a - b);
89
+ const mid = Math.floor(numsLen / 2);
90
+ return numsLen % 2 !== 0
91
+ ? nums[mid]
92
+ : (nums[mid - 1] + nums[mid]) / 2;
93
+ });
94
+ }
95
+ min() {
96
+ return this._deriveAgg(v => (0, utils_1.getListStats)(v).min);
97
+ }
98
+ mode() {
99
+ return this._deriveAgg(v => {
100
+ if (!(0, utils_1.isArrayOrTypedArray)(v))
101
+ return null;
102
+ const len = v.length;
103
+ const counts = new Map();
104
+ let maxCount = 0;
105
+ for (let i = 0; i < len; i++) {
106
+ const val = v[i];
107
+ if (val == null)
108
+ continue;
109
+ const c = (counts.get(val) ?? 0) + 1;
110
+ counts.set(val, c);
111
+ if (c > maxCount)
112
+ maxCount = c;
113
+ }
114
+ if (maxCount === 0)
115
+ return null;
116
+ const modes = [];
117
+ for (const [val, c] of counts.entries()) {
118
+ if (c === maxCount) {
119
+ modes.push(val);
120
+ }
121
+ }
122
+ if (modes.length === 0)
123
+ return null;
124
+ modes.sort((a, b) => {
125
+ if (a == null && b == null)
126
+ return 0;
127
+ if (a == null)
128
+ return 1;
129
+ if (b == null)
130
+ return -1;
131
+ if (a < b)
132
+ return -1;
133
+ if (a > b)
134
+ return 1;
135
+ return 0;
136
+ });
137
+ return modes[0];
138
+ });
139
+ }
140
+ n_unique() {
141
+ return this._deriveAgg(v => new Set(v).size);
142
+ }
143
+ quantile(q) {
144
+ if (q < 0 || q > 1)
145
+ throw new exceptions_1.ComputeError("Quantile q must be between 0 and 1");
146
+ return this._deriveAgg(v => {
147
+ const f = [];
148
+ for (let i = 0; i < v.length; i++) {
149
+ if (v[i] != null)
150
+ f.push(v[i]);
151
+ }
152
+ const fLen = f.length;
153
+ if (!fLen)
154
+ return null;
155
+ f.sort((a, b) => a - b);
156
+ const idx = (fLen - 1) * q;
157
+ const low = Math.floor(idx);
158
+ const high = Math.ceil(idx);
159
+ if (low === high)
160
+ return f[low];
161
+ return f[low] + (idx - low) * (f[high] - f[low]);
162
+ });
163
+ }
164
+ std() {
165
+ return this._deriveAgg(v => (0, utils_1.getListStats)(v).std);
166
+ }
167
+ sum() {
168
+ return this._deriveAgg(v => (0, utils_1.getListStats)(v).sum);
169
+ }
170
+ };
171
+ };
172
+ exports.AggregationExpr = AggregationExpr;
@@ -0,0 +1,67 @@
1
+ import type { IExpr } from "../../types";
2
+ import type { ExprConstructor, RandomOptions } from "../types";
3
+ export declare const ArithmeticExpr: <TBase extends ExprConstructor>(Base: TBase) => {
4
+ new (...args: any[]): {
5
+ abs(): /*elided*/ any;
6
+ acos(): /*elided*/ any;
7
+ acosh(): /*elided*/ any;
8
+ add(val: number | IExpr | null): /*elided*/ any;
9
+ asin(): /*elided*/ any;
10
+ asinh(): /*elided*/ any;
11
+ atan(): /*elided*/ any;
12
+ atanh(): /*elided*/ any;
13
+ cbrt(): /*elided*/ any;
14
+ ceil(): /*elided*/ any;
15
+ clip(lower?: number | null, upper?: number | null): /*elided*/ any;
16
+ cos(): /*elided*/ any;
17
+ cosh(): /*elided*/ any;
18
+ degrees(): /*elided*/ any;
19
+ div(val: number | IExpr | null): /*elided*/ any;
20
+ exp(): /*elided*/ any;
21
+ expm1(): /*elided*/ any;
22
+ floor(): /*elided*/ any;
23
+ floordiv(val: number | IExpr | null): /*elided*/ any;
24
+ hypot(val: number | IExpr | null): /*elided*/ any;
25
+ log(base?: number): /*elided*/ any;
26
+ log1p(): /*elided*/ any;
27
+ mod(val: number | IExpr | null): /*elided*/ any;
28
+ mul(val: number | IExpr | null): /*elided*/ any;
29
+ negate(): /*elided*/ any;
30
+ pow(val: number | IExpr | null): /*elided*/ any;
31
+ radians(): /*elided*/ any;
32
+ rand(seed?: number, { min, max, integer }?: RandomOptions): /*elided*/ any;
33
+ round(decimals?: number): /*elided*/ any;
34
+ sign(): /*elided*/ any;
35
+ sin(): /*elided*/ any;
36
+ sinh(): /*elided*/ any;
37
+ sqrt(): /*elided*/ any;
38
+ sub(val: number | IExpr | null): /*elided*/ any;
39
+ tan(): /*elided*/ any;
40
+ tanh(): /*elided*/ any;
41
+ trunc(): /*elided*/ any;
42
+ ops: import("../../types").OpFn[];
43
+ colName?: string;
44
+ outputName?: string;
45
+ isLiteral?: boolean;
46
+ literalValue?: any;
47
+ aggFn?: import("../../types").AggFn<any> | null;
48
+ groupingOpsIndex?: number;
49
+ partitionOpsIndex?: number;
50
+ partitionBy?: (string | IExpr)[] | null;
51
+ windowOp?: {
52
+ type: string;
53
+ [key: string]: any;
54
+ } | null;
55
+ isWindow?: boolean;
56
+ alias(name: string): /*elided*/ any;
57
+ cast(dataType: any): /*elided*/ any;
58
+ _resolve(val: any, columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData | any;
59
+ evaluate(columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData;
60
+ evaluatePreGrouping(columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData;
61
+ evaluatePostGrouping(aggregatedArray: any[], columns: import("../../types").ColumnDict): import("../../types").ColumnData;
62
+ evaluatePrePartition(columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData;
63
+ evaluatePostPartition(aggregatedArray: any[], columns: import("../../types").ColumnDict): import("../../types").ColumnData;
64
+ evaluateWindow?(groupPreValues: any[], partitionIndices: number[], currentIndex: number): any;
65
+ debug(label?: string): /*elided*/ any;
66
+ };
67
+ } & TBase;
@@ -0,0 +1,143 @@
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 ArithmeticExpr = (Base) => {
7
+ return class extends Base {
8
+ abs() {
9
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => Math.abs(v)));
10
+ }
11
+ acos() {
12
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => (v < -1 || v > 1) ? null : Math.acos(v)));
13
+ }
14
+ acosh() {
15
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v < 1 ? null : Math.acosh(v)));
16
+ }
17
+ add(val) {
18
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v + r));
19
+ }
20
+ asin() {
21
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => (v < -1 || v > 1) ? null : Math.asin(v)));
22
+ }
23
+ asinh() {
24
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.asinh));
25
+ }
26
+ atan() {
27
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.atan));
28
+ }
29
+ atanh() {
30
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => (v <= -1 || v >= 1) ? null : Math.atanh(v)));
31
+ }
32
+ cbrt() {
33
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.cbrt));
34
+ }
35
+ ceil() {
36
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.ceil));
37
+ }
38
+ clip(lower = null, upper = null) {
39
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => {
40
+ if (lower !== null && upper !== null) {
41
+ return (0, utils_1.clamp)({ val: v, min: lower, max: upper });
42
+ }
43
+ else if (lower !== null) {
44
+ return Math.max(v, lower);
45
+ }
46
+ else if (upper !== null) {
47
+ return Math.min(v, upper);
48
+ }
49
+ return v;
50
+ }));
51
+ }
52
+ cos() {
53
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.cos));
54
+ }
55
+ cosh() {
56
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.cosh));
57
+ }
58
+ degrees() {
59
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v * (180 / Math.PI)));
60
+ }
61
+ div(val) {
62
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => r === 0 ? null : v / r));
63
+ }
64
+ exp() {
65
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.exp));
66
+ }
67
+ expm1() {
68
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.expm1));
69
+ }
70
+ floor() {
71
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.floor));
72
+ }
73
+ floordiv(val) {
74
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => r === 0 ? null : Math.floor(v / r)));
75
+ }
76
+ hypot(val) {
77
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => Math.hypot(v, r)));
78
+ }
79
+ log(base = Math.E) {
80
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v <= 0 ? null : (base === Math.E ? Math.log(v) : Math.log(v) / Math.log(base))));
81
+ }
82
+ log1p() {
83
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v <= -1 ? null : Math.log1p(v)));
84
+ }
85
+ mod(val) {
86
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => r === 0 ? null : v % r));
87
+ }
88
+ mul(val) {
89
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v * r));
90
+ }
91
+ negate() {
92
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => -v));
93
+ }
94
+ pow(val) {
95
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => Math.pow(v, r)));
96
+ }
97
+ radians() {
98
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v * (Math.PI / 180)));
99
+ }
100
+ rand(seed, { min = 0, max = 1, integer = false } = {}) {
101
+ return (0, ExprBase_1.derive)(this, (vArray) => {
102
+ const len = vArray.length;
103
+ const out = new Float64Array(len);
104
+ const rnd = seed !== undefined ? (0, utils_1.mulberry32)(seed) : Math.random;
105
+ const range = max - min;
106
+ for (let i = 0; i < len; i++) {
107
+ const raw = rnd();
108
+ out[i] = integer ? Math.floor(raw * (range + 1)) + min : raw * range + min;
109
+ }
110
+ return out;
111
+ });
112
+ }
113
+ round(decimals = 0) {
114
+ const factor = Math.pow(10, decimals);
115
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => Math.round(v * factor) / factor));
116
+ }
117
+ sign() {
118
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.sign));
119
+ }
120
+ sin() {
121
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.sin));
122
+ }
123
+ sinh() {
124
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.sinh));
125
+ }
126
+ sqrt() {
127
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v < 0 ? null : Math.sqrt(v)));
128
+ }
129
+ sub(val) {
130
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v - r));
131
+ }
132
+ tan() {
133
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.tan));
134
+ }
135
+ tanh() {
136
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.tanh));
137
+ }
138
+ trunc() {
139
+ return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.trunc));
140
+ }
141
+ };
142
+ };
143
+ exports.ArithmeticExpr = ArithmeticExpr;