df-script 1.4.0 → 1.5.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/README.md +83 -34
- package/dist/api.d.ts +16 -8
- package/dist/api.js +11 -3
- package/dist/columnExpressions/ColumnExpr.d.ts +26 -364
- package/dist/columnExpressions/ColumnExpr.js +199 -3
- package/dist/columnExpressions/ExprBase.d.ts +8 -11
- package/dist/columnExpressions/ExprBase.js +20 -61
- package/dist/columnExpressions/constants.d.ts +2 -0
- package/dist/columnExpressions/constants.js +3 -1
- package/dist/columnExpressions/functions/coalesce.js +8 -4
- package/dist/columnExpressions/functions/element.d.ts +5 -0
- package/dist/columnExpressions/functions/element.js +11 -0
- package/dist/columnExpressions/functions/implode.d.ts +3 -0
- package/dist/columnExpressions/functions/implode.js +7 -0
- package/dist/columnExpressions/functions/lit.d.ts +3 -1
- package/dist/columnExpressions/functions/lit.js +8 -13
- package/dist/columnExpressions/functions/repeat.d.ts +47 -0
- package/dist/columnExpressions/functions/repeat.js +131 -0
- package/dist/columnExpressions/functions/seq_range.d.ts +31 -0
- package/dist/columnExpressions/functions/seq_range.js +91 -0
- package/dist/columnExpressions/functions/when.js +8 -4
- package/dist/columnExpressions/index.d.ts +5 -2
- package/dist/columnExpressions/index.js +5 -48
- package/dist/columnExpressions/mixins/AggregationExpr.d.ts +25 -50
- package/dist/columnExpressions/mixins/AggregationExpr.js +69 -165
- package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +41 -66
- package/dist/columnExpressions/mixins/ArithmeticExpr.js +126 -138
- package/dist/columnExpressions/mixins/BooleanExpr.d.ts +40 -0
- package/dist/columnExpressions/mixins/BooleanExpr.js +67 -0
- package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +31 -60
- package/dist/columnExpressions/mixins/ComparisonExpr.js +231 -370
- package/dist/columnExpressions/mixins/ListExpr.d.ts +15 -39
- package/dist/columnExpressions/mixins/ListExpr.js +124 -148
- package/dist/columnExpressions/mixins/LogicalExpr.d.ts +7 -33
- package/dist/columnExpressions/mixins/LogicalExpr.js +48 -49
- package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +6 -31
- package/dist/columnExpressions/mixins/ManipulationExpr.js +61 -25
- package/dist/columnExpressions/mixins/NumericExpr.d.ts +92 -0
- package/dist/columnExpressions/mixins/NumericExpr.js +259 -0
- package/dist/columnExpressions/mixins/StringExpr.d.ts +5 -30
- package/dist/columnExpressions/mixins/StringExpr.js +37 -49
- package/dist/columnExpressions/mixins/StructExpr.d.ts +16 -0
- package/dist/columnExpressions/mixins/StructExpr.js +139 -0
- package/dist/columnExpressions/mixins/TemporalExpr.d.ts +4 -30
- package/dist/columnExpressions/mixins/TemporalExpr.js +28 -29
- package/dist/columnExpressions/mixins/WindowExpr.d.ts +27 -49
- package/dist/columnExpressions/mixins/WindowExpr.js +144 -274
- package/dist/columnExpressions/utils.d.ts +4 -0
- package/dist/columnExpressions/utils.js +45 -0
- package/dist/dataframe/constants.d.ts +3 -0
- package/dist/dataframe/constants.js +4 -1
- package/dist/dataframe/dataframe.d.ts +27 -10
- package/dist/dataframe/dataframe.js +461 -220
- package/dist/dataframe/grouped/grouped.d.ts +2 -3
- package/dist/dataframe/grouped/grouped.js +17 -16
- package/dist/dataframe/types.d.ts +65 -1
- package/dist/dataframe/utils.d.ts +11 -3
- package/dist/dataframe/utils.js +101 -9
- package/dist/datatypes/DataType.d.ts +2 -1
- package/dist/datatypes/DataType.js +29 -0
- package/dist/datatypes/index.d.ts +2 -2
- package/dist/datatypes/types.d.ts +37 -36
- package/dist/datatypes/types.js +15 -11
- package/dist/exceptions/index.d.ts +2 -0
- package/dist/exceptions/index.js +4 -1
- package/dist/exceptions/utils.d.ts +1 -0
- package/dist/exceptions/utils.js +19 -0
- package/dist/functions/concat.d.ts +1 -2
- package/dist/functions/concat.js +24 -12
- package/dist/functions/index.d.ts +3 -1
- package/dist/functions/index.js +7 -15
- package/dist/functions/read_csv.d.ts +8 -0
- package/dist/functions/read_csv.js +53 -0
- package/dist/functions/read_json.d.ts +10 -0
- package/dist/functions/read_json.js +21 -0
- package/dist/functions/transpose.d.ts +7 -0
- package/dist/functions/transpose.js +84 -0
- package/dist/index.js +6 -1
- package/dist/types.d.ts +31 -5
- package/dist/utils/csv.d.ts +77 -0
- package/dist/utils/csv.js +313 -0
- package/dist/utils/date.js +5 -6
- package/dist/utils/guards.d.ts +0 -2
- package/dist/utils/guards.js +0 -31
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/json.d.ts +120 -2
- package/dist/utils/json.js +204 -20
- package/dist/utils/list.d.ts +173 -1
- package/dist/utils/list.js +255 -22
- package/dist/utils/number.d.ts +61 -28
- package/dist/utils/number.js +248 -70
- package/dist/utils/string.d.ts +5 -0
- package/dist/utils/string.js +89 -0
- package/package.json +5 -1
|
@@ -3,33 +3,69 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ManipulationExpr = void 0;
|
|
4
4
|
const ExprBase_1 = require("../ExprBase");
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
class ManipulationExpr extends ExprBase_1.ExprBase {
|
|
7
|
+
fill_null({ value = undefined, strategy = undefined, limit = undefined } = {}) {
|
|
8
|
+
return (0, ExprBase_1.derive)(this, (vArray, columns) => {
|
|
9
|
+
const height = vArray.length;
|
|
10
|
+
const result = Array.from(vArray);
|
|
11
|
+
if (strategy !== undefined) {
|
|
12
|
+
if (strategy === "zero" || strategy === "one" || strategy === "min" || strategy === "max" || strategy === "mean") {
|
|
13
|
+
let fillVal;
|
|
14
|
+
if (strategy === "zero") {
|
|
15
|
+
fillVal = 0;
|
|
16
|
+
}
|
|
17
|
+
else if (strategy === "one") {
|
|
18
|
+
fillVal = 1;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const stats = (0, utils_1.getListStats)(vArray);
|
|
22
|
+
fillVal = stats[strategy];
|
|
17
23
|
}
|
|
24
|
+
(0, utils_1.fillSequence)(result, fillVal, {
|
|
25
|
+
mode: "constant",
|
|
26
|
+
condition: (v) => v == null
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else if (strategy === "forward" || strategy === "backward") {
|
|
30
|
+
const isForward = strategy === "forward";
|
|
31
|
+
let lastVal = null;
|
|
32
|
+
let consecCount = 0;
|
|
33
|
+
(0, utils_1.fillSequence)(result, null, {
|
|
34
|
+
mode: "independent",
|
|
35
|
+
reverse: !isForward,
|
|
36
|
+
step: ({ originalValue }) => {
|
|
37
|
+
if (originalValue != null) {
|
|
38
|
+
lastVal = originalValue;
|
|
39
|
+
consecCount = 0;
|
|
40
|
+
return originalValue;
|
|
41
|
+
}
|
|
42
|
+
if (lastVal !== null && (limit === undefined || consecCount < limit)) {
|
|
43
|
+
consecCount++;
|
|
44
|
+
return lastVal;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
18
49
|
}
|
|
19
50
|
else {
|
|
20
|
-
|
|
21
|
-
const v = vArray[i];
|
|
22
|
-
result[i] = v == null ? resolved : v;
|
|
23
|
-
}
|
|
51
|
+
throw new Error(`Unsupported fill_null strategy: "${strategy}"`);
|
|
24
52
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const resolved = this._resolve(value, columns, height);
|
|
56
|
+
const isArr = (0, utils_1.isArrayOrTypedArray)(resolved);
|
|
57
|
+
(0, utils_1.fillSequence)(result, null, {
|
|
58
|
+
mode: "independent",
|
|
59
|
+
step: ({ index, originalValue }) => originalValue == null ? (isArr ? resolved[index] : resolved) : originalValue
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
reverse() {
|
|
66
|
+
return (0, ExprBase_1.derive)(this, (vArray) => {
|
|
67
|
+
return vArray.slice().reverse();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
35
71
|
exports.ManipulationExpr = ManipulationExpr;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { IExpr } from "../../types";
|
|
2
|
+
import type { ExprConstructor, RandomOptions } from "../types";
|
|
3
|
+
export declare const NumericExpr: <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
|
+
avg(): /*elided*/ any;
|
|
43
|
+
mean(): /*elided*/ any;
|
|
44
|
+
sum(): /*elided*/ any;
|
|
45
|
+
std(): /*elided*/ any;
|
|
46
|
+
min(): /*elided*/ any;
|
|
47
|
+
max(): /*elided*/ any;
|
|
48
|
+
median(): /*elided*/ any;
|
|
49
|
+
quantile(q: number): /*elided*/ any;
|
|
50
|
+
count(options?: {
|
|
51
|
+
includeNulls?: boolean;
|
|
52
|
+
}): /*elided*/ any;
|
|
53
|
+
cum_max(reverse?: boolean): /*elided*/ any;
|
|
54
|
+
cum_min(reverse?: boolean): /*elided*/ any;
|
|
55
|
+
cum_prod(reverse?: boolean): /*elided*/ any;
|
|
56
|
+
cum_sum(reverse?: boolean): /*elided*/ any;
|
|
57
|
+
rolling_max(windowSize: number): /*elided*/ any;
|
|
58
|
+
rolling_mean(windowSize: number): /*elided*/ any;
|
|
59
|
+
rolling_median(windowSize: number): /*elided*/ any;
|
|
60
|
+
rolling_min(windowSize: number): /*elided*/ any;
|
|
61
|
+
rolling_quantile(quantile: number, windowSize: number): /*elided*/ any;
|
|
62
|
+
rolling_std(windowSize: number): /*elided*/ any;
|
|
63
|
+
rolling_sum(windowSize: number): /*elided*/ any;
|
|
64
|
+
ops: import("../../types").OpFn[];
|
|
65
|
+
colName?: string;
|
|
66
|
+
outputName?: string;
|
|
67
|
+
isLiteral?: boolean;
|
|
68
|
+
literalValue?: any;
|
|
69
|
+
aggFn?: import("../../types").AggFn<any> | null;
|
|
70
|
+
groupingOpsIndex?: number;
|
|
71
|
+
partitionOpsIndex?: number;
|
|
72
|
+
partitionBy?: (string | IExpr)[] | null;
|
|
73
|
+
windowOp?: {
|
|
74
|
+
type: string;
|
|
75
|
+
[key: string]: any;
|
|
76
|
+
} | null;
|
|
77
|
+
isWindow?: boolean;
|
|
78
|
+
alias(name: string): /*elided*/ any;
|
|
79
|
+
cast(dataType: import("../../types").RegisteredDataType): /*elided*/ any;
|
|
80
|
+
_resolve(val: any, columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData | any;
|
|
81
|
+
evaluate(columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData;
|
|
82
|
+
evaluatePreGrouping(columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData;
|
|
83
|
+
evaluatePostGrouping(aggregatedArray: any[], columns: import("../../types").ColumnDict): import("../../types").ColumnData;
|
|
84
|
+
evaluatePrePartition(columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData;
|
|
85
|
+
evaluatePostPartition(aggregatedArray: any[], columns: import("../../types").ColumnDict): import("../../types").ColumnData;
|
|
86
|
+
evaluateWindow?(groupPreValues: any[], partitionIndices: number[], currentIndex: number): any;
|
|
87
|
+
debug(label?: string): /*elided*/ any;
|
|
88
|
+
_window(evaluateWindow: (this: IExpr, groupPreValues: any[], partitionIndices: number[], currentIndex: number) => any): /*elided*/ any;
|
|
89
|
+
_rolling(windowSize: number, aggFn: (vals: any[]) => any): /*elided*/ any;
|
|
90
|
+
_deriveAgg(fn: import("../../types").AggFn<any>): /*elided*/ any;
|
|
91
|
+
};
|
|
92
|
+
} & TBase;
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumericExpr = void 0;
|
|
4
|
+
const ExprBase_1 = require("../ExprBase");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const exceptions_1 = require("../../exceptions");
|
|
7
|
+
const NumericExpr = (Base) => {
|
|
8
|
+
return class extends Base {
|
|
9
|
+
abs() {
|
|
10
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => Math.abs(v)));
|
|
11
|
+
}
|
|
12
|
+
acos() {
|
|
13
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => (v < -1 || v > 1) ? null : Math.acos(v)));
|
|
14
|
+
}
|
|
15
|
+
acosh() {
|
|
16
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v < 1 ? null : Math.acosh(v)));
|
|
17
|
+
}
|
|
18
|
+
add(val) {
|
|
19
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v + r));
|
|
20
|
+
}
|
|
21
|
+
asin() {
|
|
22
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => (v < -1 || v > 1) ? null : Math.asin(v)));
|
|
23
|
+
}
|
|
24
|
+
asinh() {
|
|
25
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.asinh));
|
|
26
|
+
}
|
|
27
|
+
atan() {
|
|
28
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.atan));
|
|
29
|
+
}
|
|
30
|
+
atanh() {
|
|
31
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => (v <= -1 || v >= 1) ? null : Math.atanh(v)));
|
|
32
|
+
}
|
|
33
|
+
cbrt() {
|
|
34
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.cbrt));
|
|
35
|
+
}
|
|
36
|
+
ceil() {
|
|
37
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.ceil));
|
|
38
|
+
}
|
|
39
|
+
clip(lower = null, upper = null) {
|
|
40
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => {
|
|
41
|
+
if (lower !== null && upper !== null) {
|
|
42
|
+
return (0, utils_1.clamp)(v, lower, upper);
|
|
43
|
+
}
|
|
44
|
+
else if (lower !== null) {
|
|
45
|
+
return Math.max(v, lower);
|
|
46
|
+
}
|
|
47
|
+
else if (upper !== null) {
|
|
48
|
+
return Math.min(v, upper);
|
|
49
|
+
}
|
|
50
|
+
return v;
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
cos() {
|
|
54
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.cos));
|
|
55
|
+
}
|
|
56
|
+
cosh() {
|
|
57
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.cosh));
|
|
58
|
+
}
|
|
59
|
+
degrees() {
|
|
60
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v * (180 / Math.PI)));
|
|
61
|
+
}
|
|
62
|
+
div(val) {
|
|
63
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => r === 0 ? null : v / r));
|
|
64
|
+
}
|
|
65
|
+
exp() {
|
|
66
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.exp));
|
|
67
|
+
}
|
|
68
|
+
expm1() {
|
|
69
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.expm1));
|
|
70
|
+
}
|
|
71
|
+
floor() {
|
|
72
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.floor));
|
|
73
|
+
}
|
|
74
|
+
floordiv(val) {
|
|
75
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => r === 0 ? null : Math.floor(v / r)));
|
|
76
|
+
}
|
|
77
|
+
hypot(val) {
|
|
78
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => Math.hypot(v, r)));
|
|
79
|
+
}
|
|
80
|
+
log(base = Math.E) {
|
|
81
|
+
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))));
|
|
82
|
+
}
|
|
83
|
+
log1p() {
|
|
84
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v <= -1 ? null : Math.log1p(v)));
|
|
85
|
+
}
|
|
86
|
+
mod(val) {
|
|
87
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => r === 0 ? null : v % r));
|
|
88
|
+
}
|
|
89
|
+
mul(val) {
|
|
90
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v * r));
|
|
91
|
+
}
|
|
92
|
+
negate() {
|
|
93
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => -v));
|
|
94
|
+
}
|
|
95
|
+
pow(val) {
|
|
96
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => Math.pow(v, r)));
|
|
97
|
+
}
|
|
98
|
+
radians() {
|
|
99
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v * (Math.PI / 180)));
|
|
100
|
+
}
|
|
101
|
+
rand(seed, { min = 0, max = 1, integer = false } = {}) {
|
|
102
|
+
return (0, ExprBase_1.derive)(this, (vArray) => {
|
|
103
|
+
const len = vArray.length;
|
|
104
|
+
const out = new Float64Array(len);
|
|
105
|
+
const rnd = seed !== undefined ? (0, utils_1.mulberry32)(seed) : Math.random;
|
|
106
|
+
const range = max - min;
|
|
107
|
+
for (let i = 0; i < len; i++) {
|
|
108
|
+
const raw = rnd();
|
|
109
|
+
out[i] = integer ? Math.floor(raw * (range + 1)) + min : raw * range + min;
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
round(decimals = 0) {
|
|
115
|
+
const factor = Math.pow(10, decimals);
|
|
116
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => Math.round(v * factor) / factor));
|
|
117
|
+
}
|
|
118
|
+
sign() {
|
|
119
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.sign));
|
|
120
|
+
}
|
|
121
|
+
sin() {
|
|
122
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.sin));
|
|
123
|
+
}
|
|
124
|
+
sinh() {
|
|
125
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.sinh));
|
|
126
|
+
}
|
|
127
|
+
sqrt() {
|
|
128
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)((v) => v < 0 ? null : Math.sqrt(v)));
|
|
129
|
+
}
|
|
130
|
+
sub(val) {
|
|
131
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneBinary)(this, val, (v, r) => v - r));
|
|
132
|
+
}
|
|
133
|
+
tan() {
|
|
134
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.tan));
|
|
135
|
+
}
|
|
136
|
+
tanh() {
|
|
137
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.tanh));
|
|
138
|
+
}
|
|
139
|
+
trunc() {
|
|
140
|
+
return (0, ExprBase_1.derive)(this, (0, ExprBase_1.kleeneUnary)(Math.trunc));
|
|
141
|
+
}
|
|
142
|
+
// Numeric Aggregations
|
|
143
|
+
avg() {
|
|
144
|
+
return this._deriveAgg((v) => (0, utils_1.getListStats)(v).mean);
|
|
145
|
+
}
|
|
146
|
+
mean() {
|
|
147
|
+
return this.avg();
|
|
148
|
+
}
|
|
149
|
+
sum() {
|
|
150
|
+
return this._deriveAgg((v) => (0, utils_1.getListStats)(v).sum);
|
|
151
|
+
}
|
|
152
|
+
std() {
|
|
153
|
+
return this._deriveAgg((v) => (0, utils_1.getListStats)(v).std);
|
|
154
|
+
}
|
|
155
|
+
min() {
|
|
156
|
+
return this._deriveAgg((v) => (0, utils_1.getListStats)(v).min);
|
|
157
|
+
}
|
|
158
|
+
max() {
|
|
159
|
+
return this._deriveAgg((v) => (0, utils_1.getListStats)(v).max);
|
|
160
|
+
}
|
|
161
|
+
median() {
|
|
162
|
+
return this._deriveAgg((v) => (0, utils_1.computeMedian)(v));
|
|
163
|
+
}
|
|
164
|
+
quantile(q) {
|
|
165
|
+
if (q < 0 || q > 1)
|
|
166
|
+
throw new exceptions_1.ComputeError("Quantile q must be between 0 and 1");
|
|
167
|
+
return this._deriveAgg((v) => (0, utils_1.computeQuantile)(v, q));
|
|
168
|
+
}
|
|
169
|
+
count(options = {}) {
|
|
170
|
+
if (options.includeNulls)
|
|
171
|
+
return this._deriveAgg((v) => v.length);
|
|
172
|
+
return this._deriveAgg((v) => (0, utils_1.getListStats)(v).count);
|
|
173
|
+
}
|
|
174
|
+
// Numeric Cumulative/Rolling Windows
|
|
175
|
+
cum_max(reverse = false) {
|
|
176
|
+
return this._window(function (groupPreValues, _partitionIndices, currentIndex) {
|
|
177
|
+
let maxVal = null;
|
|
178
|
+
const start = reverse ? currentIndex : 0;
|
|
179
|
+
const end = reverse ? groupPreValues.length - 1 : currentIndex;
|
|
180
|
+
for (let i = start; i <= end; i++) {
|
|
181
|
+
const val = groupPreValues[i];
|
|
182
|
+
if (val != null) {
|
|
183
|
+
if (maxVal === null || val > maxVal) {
|
|
184
|
+
maxVal = val;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return maxVal;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
cum_min(reverse = false) {
|
|
192
|
+
return this._window(function (groupPreValues, _partitionIndices, currentIndex) {
|
|
193
|
+
let minVal = null;
|
|
194
|
+
const start = reverse ? currentIndex : 0;
|
|
195
|
+
const end = reverse ? groupPreValues.length - 1 : currentIndex;
|
|
196
|
+
for (let i = start; i <= end; i++) {
|
|
197
|
+
const val = groupPreValues[i];
|
|
198
|
+
if (val != null) {
|
|
199
|
+
if (minVal === null || val < minVal) {
|
|
200
|
+
minVal = val;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return minVal;
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
cum_prod(reverse = false) {
|
|
208
|
+
return this._window(function (groupPreValues, _partitionIndices, currentIndex) {
|
|
209
|
+
let prod = 1;
|
|
210
|
+
let hasValid = false;
|
|
211
|
+
const start = reverse ? currentIndex : 0;
|
|
212
|
+
const end = reverse ? groupPreValues.length - 1 : currentIndex;
|
|
213
|
+
for (let i = start; i <= end; i++) {
|
|
214
|
+
const val = groupPreValues[i];
|
|
215
|
+
if (val != null) {
|
|
216
|
+
prod *= val;
|
|
217
|
+
hasValid = true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return hasValid ? prod : null;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
cum_sum(reverse = false) {
|
|
224
|
+
return this._window(function (groupPreValues, _partitionIndices, currentIndex) {
|
|
225
|
+
let sum = 0;
|
|
226
|
+
const start = reverse ? currentIndex : 0;
|
|
227
|
+
const end = reverse ? groupPreValues.length - 1 : currentIndex;
|
|
228
|
+
for (let i = start; i <= end; i++) {
|
|
229
|
+
const val = groupPreValues[i];
|
|
230
|
+
if (val != null)
|
|
231
|
+
sum += val;
|
|
232
|
+
}
|
|
233
|
+
return sum;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
rolling_max(windowSize) {
|
|
237
|
+
return this._rolling(windowSize, (v) => (0, utils_1.getListStats)(v).max);
|
|
238
|
+
}
|
|
239
|
+
rolling_mean(windowSize) {
|
|
240
|
+
return this._rolling(windowSize, (v) => (0, utils_1.getListStats)(v).mean);
|
|
241
|
+
}
|
|
242
|
+
rolling_median(windowSize) {
|
|
243
|
+
return this._rolling(windowSize, (v) => (0, utils_1.computeMedian)(v));
|
|
244
|
+
}
|
|
245
|
+
rolling_min(windowSize) {
|
|
246
|
+
return this._rolling(windowSize, (v) => (0, utils_1.getListStats)(v).min);
|
|
247
|
+
}
|
|
248
|
+
rolling_quantile(quantile, windowSize) {
|
|
249
|
+
return this._rolling(windowSize, (v) => (0, utils_1.computeQuantile)(v, quantile));
|
|
250
|
+
}
|
|
251
|
+
rolling_std(windowSize) {
|
|
252
|
+
return this._rolling(windowSize, (v) => (0, utils_1.getListStats)(v).std);
|
|
253
|
+
}
|
|
254
|
+
rolling_sum(windowSize) {
|
|
255
|
+
return this._rolling(windowSize, (v) => (0, utils_1.getListStats)(v).sum);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
exports.NumericExpr = NumericExpr;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { IExpr } from "../../types";
|
|
2
|
-
import
|
|
2
|
+
import { ExprBase } from "../ExprBase";
|
|
3
3
|
import { StripCharsOptions } from "../../utils";
|
|
4
4
|
export declare class StringExprNamespace {
|
|
5
5
|
expr: any;
|
|
6
6
|
constructor(expr: any);
|
|
7
7
|
_deriveString(fn: (v: string) => any): any;
|
|
8
|
+
_patternGuard(pattern: any, fn: () => any): any;
|
|
8
9
|
concat(other: string | IExpr): any;
|
|
9
10
|
contains(pattern: string | RegExp): any;
|
|
10
11
|
count_matches(pattern: string | RegExp): any;
|
|
@@ -48,32 +49,6 @@ export declare class StringExprNamespace {
|
|
|
48
49
|
upper(): any;
|
|
49
50
|
zfill(width: number): any;
|
|
50
51
|
}
|
|
51
|
-
export declare
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
ops: import("../../types").OpFn[];
|
|
55
|
-
colName?: string;
|
|
56
|
-
outputName?: string;
|
|
57
|
-
isLiteral?: boolean;
|
|
58
|
-
literalValue?: any;
|
|
59
|
-
aggFn?: import("../../types").AggFn<any> | null;
|
|
60
|
-
groupingOpsIndex?: number;
|
|
61
|
-
partitionOpsIndex?: number;
|
|
62
|
-
partitionBy?: (string | IExpr)[] | null;
|
|
63
|
-
windowOp?: {
|
|
64
|
-
type: string;
|
|
65
|
-
[key: string]: any;
|
|
66
|
-
} | null;
|
|
67
|
-
isWindow?: boolean;
|
|
68
|
-
alias(name: string): /*elided*/ any;
|
|
69
|
-
cast(dataType: any): /*elided*/ any;
|
|
70
|
-
_resolve(val: any, columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData | any;
|
|
71
|
-
evaluate(columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData;
|
|
72
|
-
evaluatePreGrouping(columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData;
|
|
73
|
-
evaluatePostGrouping(aggregatedArray: any[], columns: import("../../types").ColumnDict): import("../../types").ColumnData;
|
|
74
|
-
evaluatePrePartition(columns: import("../../types").ColumnDict, height: number): import("../../types").ColumnData;
|
|
75
|
-
evaluatePostPartition(aggregatedArray: any[], columns: import("../../types").ColumnDict): import("../../types").ColumnData;
|
|
76
|
-
evaluateWindow?(groupPreValues: any[], partitionIndices: number[], currentIndex: number): any;
|
|
77
|
-
debug(label?: string): /*elided*/ any;
|
|
78
|
-
};
|
|
79
|
-
} & TBase;
|
|
52
|
+
export declare class StringExpr extends ExprBase {
|
|
53
|
+
get str(): StringExprNamespace;
|
|
54
|
+
}
|